Change base of the current branch using git rebase

Git rebase is a very neat way to merge changes if you haven’t yet pushed to mas­ter. Git rebase works in a very sim­ple way. Lets say that you have a ‘mas­ter’ branch off which you forked of a ‘fea­ture’ branch. The cur­rent com­mit of the mas­ter becomes the com­mon ances­tor of both the — ‘fea­ture’ and the ‘mas­ter’ branch. Lets say that after a while, your mas­ter branch added 3 more com­mits and that your fea­ture branch added 10 com­mits. Now, instead of doing a sim­ple 3 way merge, you can choose to update the com­mon ances­tor of the fea­ture branch to the lat­est com­mit of the mas­ter branch and then replay the 10 com­mits on top of this lat­est commit.

This will help you later when you merge into mas­ter by cre­at­ing a very lin­ear history.

Here’s how you’d go about it

git checkout feature-branch
git rebase master
git checkout master
git merge feature-branch

Ryan Sukale

Ryan is a UX engineer living in San Francisco, California.

You may also like...

Leave a Reply

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