Oscar the owl and Vershd logo
Menu

How to Git Rebase Instead of Merge Effortlessly

The Problem

Sometimes after merging a branch, you realise that you’d like to create a nice linear history, as you would if you had rebased that branch with git rebase, instead of merging it.

Depending on your team’s outlook, this is either a sensible ‘clean repository’ step, or a significant step to obsessive compulsive disorder. The diagram shows the situation, whereby you want to move the commits of my-branch onto master in one seamless line.

It’s important to recognise that this will create new commit hashes, so you should be wary of doing this on a branch that has been published. If you do, then other people’s history will change, and that may cause havoc for them.

The Solution

This checks out the commit and allows you to work on it, and its ancestors:
git checkout d2bb4ba
This effectively moves your commits on my-branch, up to d2bb4ba, onto the tip of a new base, 8029ced:
git rebase 8029ced
This reapplies all the subsequent commits that were on master, from e7cdf7b onwards:
git cherry-pick e7cdf7b..master
Important: At this point, carefully check the history that you’ve created!
Warning: This overwrites the master branch entirely:
git branch -f master
And now see the results of your effort:
git checkout master

Free

GitBreeze is an effortless Git GUI that's free for use at work, at home, anywhere. It boosts software development. It works on Windows, macOS, and Linux.

Designed for developers who want Git to be simple, our unique UI/UX boosts your software development - learn more and reap the benefits.

Help & tools

We provide these pages to try to make your programming life easier. Our resources page gives an overview. You can see a full list of our Git tips & tools here.

We have these free tools:

Customers say...

I love any tool that makes my life easier... This is perfect, just the right amount of control. No more, no less. Easy to get started, push and rollback changes... It's a no brainer!
Hayden T.
Oscar the owl and Vershd logo
 © 2024 GitBreeze Ltd.
St. George's flag of England, the Union Jack flag of the United Kingdom, the European Union flag, and the United Nations flag.
chevron-right linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram