Do you know The Golden Rule of Rebasing?

Updated by AdamStephensen 9 years ago. See history

123

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!

Image

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

Image

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

Image

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

acknowledgements
related rules