Git Concepts

Quick Start Guides

Git Rebase

What is Git rebase? Rebase is an action in Git that allows you to rewrite commits from one branch onto another branch. Essentially, Git is deleting commits from one branch and adding them onto another.

When comparing Git rebase vs merge, both actions can be used to combine file changes from one branch to another, but there are associated benefits and drawbacks to both. But we’re here to focus on Git rebase, so let’s get started.

We’re going to go over how to rebase using the GitKraken Git client, a visualization tool that helps simplify what’s going on under the hood of Git, followed by a step-by-step example of how to use the Git rebase command in the terminal.

Have more control over your rebase with the GitKraken Git GUI

Git Rebase in GitKraken

One of the largest benefits associated with GitKraken’s graphical user interface is the way your repo information is displayed. As you can see here, GitKraken visualizes your commit history clearly in the central commit graph. This gives you an immediate snapshot so you can quickly understand what’s going on with the branches you want to rebase.

In this example, let’s say you have a feature branch with changes that you need to combine onto the dev branch. To perform a rebase in GitKraken, simply drag-and-drop feature onto dev and then click the Rebase feature onto dev option from the context menu.

Git rebase in just 2 clicks using GitKraken

Git Rebase in the Command Line

To begin your Git rebase in the terminal, you will likely start by running the git branch command to see a list of your local branches. In the example below, you can see the currently checked out branch is feature, along with two other branches: dev and production

GitTip: If you want to target commits on a branch that is not currently checked out, you will have to switch to another branch with the git checkout command. Learn how to checkout a remote Git branch and a local Git branch.

In this example, let’s say you want to rewrite the two most recent commits from the feature branch onto the dev branch. Because the terminal lacks the immediate visual context of which commits exist on which branch, you will start by running the git log command followed by -2.

The commit named Additional sentence structure changes is where the feature branch originally branched off from the dev branch. This will change after the Git rebase is completed, so take note.

From here, you can hit q to exit the log.

To proceed with the rebase, you will use the git rebase command followed by the name of your target branch—in this case, the dev branch—to move your changes from one branch to another.

With that, the rebase is complete! Git has re-written the commits from your feature branch onto the most recent commit on the dev branch.

Because you’re unable to immediately verify the success of the rebase in the CLI, as you can with GitKraken, you should double-check by running git log -2 again. And voila! We now have a new base commit on the feature branch: Finalize release date.

GitTip: feeling like you’ve got the hang of rebase? Graduate onto Git interactive rebase.

Stop wasting time on commands and get more time back in your day to….do whatever you want. Download the cross-platform GitKraken Git client free today.

Additional Resources

Make Git Easier, Safer &
More Powerful

with GitKraken