Rebase using SourceTree

Interactive rebase is a variation that lets you tidy up your commit history before merging or pushing to origin. Changing the commit history lets you apply 20/20 hindsight to describing the steps you took to get to this change. Git has a special file called git-rebase-todo which is simply a text file containing a list of the commits you’re working with. Interactive rebase offers a chance to edit this file and gives you some control over exactly what happens when you replay those commits.

Warning: Even though it looks like you’re just shifting your commits to a different point in your repo’s history, under the covers, Git actually creates new commits – each with a new sha. So don’t rebase commits you’ve already pushed to origin unless you coordinate closely with your teammates. They’ll need to bring their local copy of the repo up to date afterwards.

Interactive rebase using Sourcetree

If you’re doing an interactive rebase from the command line, Git will open an editor where you an issue the commands that result in edits to git-rebase-todo – which is sort of like a runbook Git will use when executing the rebase. Similarly, Sourcetree taps into git-rebase-todo and edits it. The difference is the user experience: you get to interact with the rebase through a point-n-click UI instead of having to memorize commands and their syntax.

Learn more about the internal mechanisms of interactive rebase on our free Git tutorials site.

There are two ways to start an interactive rebase in Sourcetree. The first is to right-click (or context-click) on a commit and choose Rebase children of <sha> interactively… The second is to pull down the Repository menu and select Interactive rebase.

From there, you’ll have the chance to rewrite your repository’s history with the help of a few operations

Since rebase is an action that rewrites git history if you have already pushed your branch to origin, you will need to Force Push to rewrite history once you have rebased your branch

Sometimes, you might can a trailing HEAD in Sourecetree when resolving conflicts during rebase. You will need to go to Actions → Continue Rebase