Merging GIT branches

View differences between branches

You will see all differences with this command:

git diff nameOfBranchYouWantToCompareWith

If you only want to see the statistics you can run

git diff --stat nameOfBranchYouWantToCompareWith

Doing a general merge of two branches

First checkout the branch you want to merge to. Next do the merge thus:

git merge branchThatIAmMergingFrom

An example of merging one commit

Let's say that I noticed last night that Joe had committed something to the master branch that was very nice. The master branch is the sort-of-stable main line of development. In my opinion (and I think it was Joe's intention), this change should also be in the 0.5 release. Stuff for the 0.5 release is in the 0.5-maintenance branch.

For the most part, it is no problem to just check-in such things to the 0.5-maintenance branch and we will merge those changes into the master branch regularly. However, we do not want to merge all of the stuff from the master branch back to the 0.5-maintenance branch (because includes potentially half-baked new features and breakages). So what do you do in this case to get just a single commit from the master branch back to the 0.5-maintenance branch without merging everything?

If you've never checked out the 0.5-maintenance branch before, then do it this way the first time (remembering that what I have setup as 'github' might be 'origin' or something on yours):

git checkout --track remotes/github/0.5-maintenance

If you have already checked it out before, then you just do this:

git checkout 0.5-maintenance

The commit number of Nils cool new improvement is 222ae775fca978ae840b7b02731f46cd9cda9e88. So now I do this:

git cherry-pick 222ae775fca978ae840b7b02731f46cd9cda9e88
git status
git push github 0.5-maintenance

The git cherry-pick is a special merge that is merging just a single commit into the current branch rather than merging a whole other branch into the existing branch.