Oscar the owl and Vershd logo
Git rebase instead of merge

Git Rebase Instead of Merge

2nd March 2020

This is part of a Git Tips series. For the complete set for beginner and intermediate Git users, see our white paper.

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

The Quickest & Easiest Solution

Do you need a Git GUI that's totally free for personal use? Vershd boosts your software development productivity by making Git simple with a unique UI/UX. It's a Git GUI that prevents errors and creates clarity. This Git client soars over your repository and then swoops down to quickly tackle branches, commits and files. It deals with Git, so you can concentrate on coding.

Get screenshots and a 60 second video of what Vershd, the effortless Git GUI can do for you.
Vershd is the effortless Git GUI for Windows, Mac, & Linux
Oscar the owl and Vershd logo
 © 2021 Blightysoft
Made in England
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