Git Guide for Good

What can we do with Git?

In the term of software development, there are some steps and actions we can do with Git. But before that, we need to know ‘trees’ in Git. Trees in Git has 3 part and each of those tell us in which step is our job.

  • Working Directory: The part where we code our project
  • Index/Stage: To commit our changes
  • HEAD: Refer to the last commit.


As we mostly code in out local repository, we have to make a setup in our local repository. This step remarks the first step of working directory.

git init
git clone /path/to/repository

Add & Commit

The next step is to add files and/or changes to.

git add <file-name>
git add .
git add .
git reset <file-name>
git rm <file-name>
git commit -m “Meaningful commit message”


The next is to push to our repository. This stage will put our commits of changes in the online git repository.

git push origin <branch-name>
git remote add origin <server>


As Git is designed for a big project with several programmers, if every programmer does different tasks and commits it all in the same place, there will be a lot of conflicts in file. Thank Git, for having a branch feature and letting us commit several jobs separately. This feature allows us to do project separately from other programmers. We also can use a specific branch to do a particular feature so that it will be easier to take a look for a progress on that feature. Here’s how to use branch :

git checkout -b <branch-name>
git checkout <branch-name>
git branch -d <branch-name>
git branch

Update & Merge

Sometimes in development, we have to update our file in the local repository, with the most updated one in the ‘main’/’master’ branch or we will merge a branch with other branch. Here’s how to use merge and update in Git.

git pull
git pull <remote> <branch>
git merge <branch>


To view a list of existing commits, use this command :

git log

Stash & Revert

Sometimes when we want to switch to another branch, we have some uncommitted files in our local repository, to save those change, we can use stash by doing this command :

git stash
git revert HEAD



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Fikri Adidharma

Fikri Adidharma

Penultimate CS Student @ University of Indonesia