Knowing GIT The Easy Way !!

I have seen many people(including myself !) who have just messed up with GIT. Now the fact for most of the developers working is they all know GIT but not the correct way of using it. There's a huge difference and impact in very small fundamentals of GIT. So in this article i will be explaining a very important point of Difference between GIT Merge and GIT Rebase.
So, to explain in simple words doing a git merge will merge your current branch with master from where you have created it. This will create very shabby commit logs which are very confusing for anyone to track. And git rebase will first put all commits fetched from the master below yours as yours is the latest one and then pushing the same in the master. This will create a very clean one lined commit logs which is a good way of doing it.
First of all i am assuming that you have cloned a repo from github into your system. After completing your task on your working branch(lets assume xyz_staging) other than master, follow below steps:
1. git add . (This stages all the modified files.)
2. git commit -m "my first commit"
Now, to have this commit in your master branch, rebase your working branch(i.e. xyz_staging) with master branch. For that follow the below steps:
3. git stash
4. git fetch
5. git rebase origin/master (Here you may get conflicts in files which you can solve using tools like meld, smartgit etc)
Now checkout in the master branch and do the following:
6. git rebase origin/master
7. git rebase working_branch name (for us here is xyz_staging)
8. git push origin master
Now to explain the above stuff, we have rebased a branch with master and not merged. We could have merged too which also serves to our purposes but the whole concept maintaining clean track of git commits is lost with that. To explain this difference i will just share some images :
  1. Git Merge way looks like this:                                                                          I will be explaining some more GIT concepts in my next articles till then goodbye. Any suggestions or correction in this article is warmly welcomed.

Comments