The Important guide to git




Version control, a key tool for developers and the one which we end up using - git. Although git happens to be failry simple and intuitive in basic things such as pull , push and clone , it however poses a challenge when you want to work with actual version control commands, such as reverting a commit, or updating your repository with the remote one - The main reason why there exits multiple applications which use visual version control, but if you are like me who enjoys working on the command line this post os for you!

Reverting a commit

Although reverting a commit, can be equivalent to undoing your changes on projects which are small, when it comes to bigger projects and packages, it becomes a tedious task. Thus reverting it important.

The command for reverting a commit is

git revert <commit id>

we can also use the reset command

git reset --soft HEAD~n
git reset --hard HEAD~n

where n is the number of commits you want to revert back to

The –soft keeps your present work while reverting, while –hard does not.

Creating a new branch

in order to do this, simply type the following

git checkout -b <new branch> <branch that the new branch will look like>

changing to a branch can be done simply by

git checkout <branch>


Updating the remote or upstream

While contributing and opening pull request after pull requests, it becomes important to update your clone to the upstream - the original project repo. So in order to do so

git remote add upstream github.com/ORIGINAL-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream

and finally updating it

git pull upstream master


Force Push

Force push can occur when remote is ahead in commits and you want push your repository. In this case git usually doesn’t give you the permission to use, because it will ask you to pull first. I really don’t happen to remember when I would actually want this to happen, but in case you do

git push -f


Hope the following extra pointers have helped in making, using git far simpler

cheers!

- Jayakrishna Sahit