Do you know The Golden Rule of Rebasing?

Last updated by AdamStephensen about 8 years ago.See history

Rebasing is great for ensuring a clean project history... but it can be dangerous in inexperienced hands.

The golden rule of git rebase is to never use it on public branches. (ie. never rebase master).

You should never rebase master onto a feature branch. This would move all of the commits in master onto the tip of the feature branch (not the other way around).

Since rebasing results in brand new commits, Git will think that your master branch’s history has diverged from everybody else’s. If you were to Push this to the server... expect lots of pain to fix it up!

rebase3
Figure: Bad Example: Rebasing master onto a feature branch can cause project history to become confused.

rebase4
Figure: To get it wrong in Visual Studio you would need to change the current branch to master and then choose rebase. While this is possible, the VS team have done a good job making it hard to do the wrong thing

rebase5
Figure: Good Example - Rebase your Feature branch onto Master

We open source. Powered by GitHub