Git rebase vs merge

I have been thinking about this for quite a while now. I have been doing merge and it always keep adding the merge commit which is good to keep track of the project history. However, I am more lenient towards git rebase as it keep the history flat and clean.

A typical git rebase example:

Lets say you start working on a feature enhancement

#Start a feature branch
git checkout -b feature
git commit -a -m "Feature added"

Now there is a sudden need to do a bug fix

#create bug fix branch
git checkout -b bugfix master
git commit -a -m "bugfix"
#merge back to master
git checkout master
git merge bugfix
git branch -d bugfix

Now that bugfix is merged with master, we rebase feature branch to keep our repo history flat and clean

git checkout feature
git rebase master

This will put the feature branch changes to the tip of master so we can do a standard merge from master once we are ready to commit feature changes.

Do you prefer git merge? and why?

Leave a Reply

Your email address will not be published. Required fields are marked *