Before we get started on the Git pull rebase action, let’s quickly outline the two commands: Git pull and Git rebase.
Git pull allows you to integrate with and fetch from another repository or local Git branch.
Git rebase allows you to rewrite commits from one branch onto another branch.
Let’s say you have a local copy of your project’s master branch with unpublished changes, and that branch is one commit behind the origin/master branch.
Git pull rebase is a method of combining your local unpublished changes with the latest published changes on your remote.
Git Pull Rebase vs Git Pull merge
To combine the unpublished local changes with the latest published remote changes, you will need to perform a Git pull from origin/master.
Git has two methods for combining changes in this nature: Git pull rebase and Git pull merge.
GitTip: Understand the difference between Git rebase vs merge before getting started with these more advanced Git operations.
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 legendary cross-platform GitKraken Git GUI before going through the process in the CLI.
How do you Git pull rebase with GitKraken?
To begin the process of Git pull rebase in GitKraken, you will start by selecting the down arrow ▼ next to Pull in the tool toolbar.
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.)
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.
How do you 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/master. If Git does detect conflicts, however, your unpublished changes won’t be applied.
If you’re working in the CLI, resolving merge conflicts can be tricky. But with the help of the cross-platform GitKraken Git client, your workflow won’t be paralyzed by a Git merge conflict, thanks to the extremely popular in-app merge tool.