• 0

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 master. Git rebase works in a very simple way. Lets say that you have a 'master' branch off which you forked of a 'feature' branch. The current commit of the master becomes the common ancestor of both the - 'feature' and the 'master' branch. Lets say that after a while, your master branch added 3 more commits and that your feature branch added 10 commits. Now, instead of doing a simple 3 way merge, you can choose to update the common ancestor of the feature branch to the latest commit of the master branch and then replay the 10 commits on top of this latest commit. This will help you later when you merge into master by creating a very linear history. Here's how you'd go about it
git checkout feature-branch
git rebase master
git checkout master
git merge feature-branch