Let’s say your local branch is out-of-date, and you need to fetch changes from your remote branch in order to bring your local branch up to speed.
In order to fetch these changes from your remote, or in other words, download the changes to your local branch, you will perform a Git pull.
Under the covers, a Git pull is actually a Git fetch followed by a Git merge. Git pull is just a shortcut to perform both of these actions in one step.
Let’s review how to Git pull a remote branch using the cross-platform GitKraken Client before showing how Git pull works in the CLI.
“I use @GitKraken Client because I can concentrate to get the job done rather than trying to remember the commands and trying to imagine how the branches connect.” – @palmiak_fp
How do you Git pull a remote branch in GitKraken Client?
Pulling changes from a remote Git branch is simple using the visual assistance of the incredibly powerful GitKraken Client.
In this example, we’re going to fetch changes from a remote branch and bring the local branch up to speed.
GitKraken Client simplifies your efforts, as GitKraken Client automatically fetches updates from your remote repositories every minute by default. If you prefer to only ever fetch manually, you can change this setting from Preferences -> General menu.
If GitKraken Client has not automatically fetched changes, simply click the Pull button in the top toolbar and select the Fetch option from the dropdown menu. This will fetch the remote for your currently checked out branch.
If you want to fetch and merge the associated changes into your local branch, then you can select one of the merge strategies for GitKraken Client to implement.
You can see there are multiple options to choose from when you want to pull a remote branch in GitKraken Client.
GitKraken Client allows you to easily choose between performing a Git pull with fast forward, Git pull fast forward only, or a Git pull rebase. No need to remember or type any commands!
GitKraken’s easy-to-read commit graph will help beginners and advanced users alike visualize branch structure so you know exactly who made what code changes when, even activity on your forks and remotes.
How do you Git pull a remote branch in the command line?
If you’re using a terminal to learn Git, such as the GitKraken CLI, you will get started with the following command:
git pull
Git Pull Origin Main
One of the most common examples of performing a Git pull uses the command:git pull origin main
Why is the Git pull origin main command so common in examples? The first remote you add for a local repository is named origin
by default in Git. For a lot of repositories, there is only ever one remote set, so origin
is the most popular remote name.
Just as origin
is the default remote name, ‘main’ is the current industry standard for what to call the main working branch. In some older docs and repositories you might see this labeled as the master
branch, making the command Git pull origin master, it has become standard to rename it to main
. You can read more about why “main” is the current default here.
There is no requirement to have either a remote called origin
or a branch called main
. Some Git workflows eliminate these naming conventions altogether, favoring terms like dev
, staging
, and production
, as you see in the repo used in examples on this page.
While important to note why this is so common, it is more important to realize all Git pulls follow the general format: git pull <remote-name> <branch-name>
, regardless of any particular naming convention.
No matter what you decide, you can set both the default remote name Git uses, as well as the default branch naming strategy, in your Git config settings.
Git Pull Fast-Forward Only
If a merge is not required, Git will fast forward your local branch. This means that your local branch will now be pointing to the most recent commit from your remote branch without merging. However, if a fast forward is not possible because a merge is required, a merge will be executed instead.
GitTip: Learn more about how to merge a Git branch, including how to merge a Git branch with main.
git pull --ff-only
You may choose to pull a branch using only fast forward if you only want non-conflicting changes brought in and never want a merge executed.
Now, if you would prefer to pull a branch only using fast forwarding, you can append the --ff-only flag to the git pull command.
Git Pull Rebase
Alternatively, if you prefer to perform a Git rebase when combining file changes, you may choose to rebase the commits from the remote Git branch you are pulling, rather than merging them.
You can accomplish this with the --rebase flag.
git pull --rebase
Have you ever attempted a Git interactive rebase? You will be blown away by how easy it is to perform complex Git actions, such as rebase and interactive rebase, with the GitKraken Client! Plus, you will streamline the process for easier, but more common, actions, like pulling a remote branch.