Now Up To 80% OFF
Our Lowest Price of the Year Sale ends soon
Search
Close this search box.

Git Rebase

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

In this article, we will cover the following topics related to the Git rebase command: 

We also have additional resources for learning more about Git rebase: 

Rebasing in Git can be a destructive action. Make sure you have the visibility and control you need with the help of GitKraken Desktop.

How to 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: main and production

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.

Let’s say you want to rewrite the two most recent commits from the feature branch onto the main 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 main branch. This will change after the Git rebase is completed, so take note.

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

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

You can verify that the Git rebase was successful by referencing GitKraken Desktop’s commit graph. The commit graph should show that the commits from the feature branch have moved to the main branch.

This is even easier if you’re using the GitKraken CLI as your terminal of choice. Because GitKraken Desktop combines the power of the CLI with convenient GUI visuals, developers can see how your changes affect the repository in real time.  Download GitKraken Desktop to experience the convenience of a streamlined terminal and desktop client for yourself.

How to Git Rebase with GitKraken Desktop

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 Desktop 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 Desktop

Feeling like you’ve got the hang of Git 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.

Git Pull Rebase

Git pull rebase is a method of combining your local unpublished changes with the latest published changes on your remote.

Let’s say you have a local copy of your project’s main branch with unpublished changes, and that branch is one commit behind the origin/main branch.

Git has two methods for combining changes in this nature: Git pull rebase and Git pull merge.

Git Pull Rebase vs Git Pull Merge

So, what’s the difference between Git pull rebase and Git pull merge? While both of these options will combine the changes fetched from your remote, the outcome will look very different in your Git history.

Git pull merge is the default method for combining changes in Git, and will merge the unpublished changes with the published changes, resulting in a merge commit.

With Git pull rebase, on the other hand, the unpublished changes will be reapplied on top of the published changes and no new commit will be added to your history.

With this in mind, you can see that Git pull rebase will result in a linear and cleaner project history by removing the unneeded merge commit.

We’re going to walk you through how to perform a Git pull rebase using the CLI and the legendary cross-platform GitKraken Desktop.

How to Git Pull Rebase in the Command Line

To perform a Git pull rebase in the CLI, you will start by navigating to your local repo and performing the following command:

git pull --rebase

If Git doesn’t detect any conflicts in the rebase, you should see the message: Successfully rebased and updated refs/heads/main. If Git does detect conflicts, however, your unpublished changes won’t be applied.

How to Git Pull Rebase with GitKraken Desktop

To begin the process of Git pull rebase in GitKraken Desktop, you will start by selecting the down arrow ▼ next to Pull in the top toolbar.

the dropdown arrow next to the Pull option in GitKraken Desktop

From the dropdown menu, select Pull (rebase).

(You can click the circle next to that option to make Pull (rebase) your default operation for pulling and fetching in GitKraken Desktop.)

Git Pull (rebase) option from the Pull dropdown menu in GitKraken Desktop

And that’s it. Seriously, it’s that easy.

You can see the graph is now linear and easy to navigate without any merge commits! In just two clicks, you were able to perform a Git pull rebase in GitKraken with complete visual context.

succesful git pull rebase

Git Rebase FAQ

Q: What Does Git Rebase Do?

A: Git rebase takes commits from one Git branch and adds them to another. It can be helpful to think of this as a Git “cut-and-paste” action. When you Git rebase, you are essentially deleting commits from one branch and adding them to a different branch. 

Q: How to Rebase Git?

A: To be clear, Git is a version control software that allows you to track your files. Git rebase is an action available in Git that allows you to move files between Git branches. For step-by-step instructions regarding how to Git rebase, see the above sections, How to Git Rebase in the Command Line or How to Git Rebase in GitKraken Desktop.

Additional Resources

Table of Contents

Visual Studio Code is required to install GitLens.

Don’t have Visual Studio Code? Get it now.

Team Collaboration Services

Secure cloud-backed services that span across all products in the DevEx platform to keep your workflows connected across projects, repos, and team members
Launchpad – All your PRs, issues, & tasks in one spot to kick off a focused, unblocked day. Code Suggest – Real code suggestions anywhere in your project, as simple as in Google Docs. Cloud Patches – Speed up PR reviews by enabling early collaboration on work-in-progress. Workspaces – Group & sync repos to simplify multi-repo actions, & get new devs coding faster. DORA Insights – Data-driven code insights to track & improve development velocity. Security & Admin – Easily set up SSO, manage access, & streamline IdP integrations.
winget install gitkraken.cli