Difference Between Git Pull and Git Pull Origin Master

John Wachira Feb 15, 2024
Difference Between Git Pull and Git Pull Origin Master

We will discuss the difference between the git pull and git pull origin master. We use these commands to integrate changes from the remote repository to a local branch.

However, as we will discuss shortly, each command works differently and has different use cases.

Difference Between git pull and git pull origin master

You probably know that the git pull command combines two commands.

  1. The git fetch command
  2. The git merge Fetch_Head command

Hence the git pull command will fetch changes from the remote repository and merge them to the tip of the checked-out branch. For the command to work, your local branch must have a remote tracking branch.

A remote-tracking branch is a branch your local branch pulls from and pushes changes to. The command will fail if your branch does not have a remote-tracking branch.

On the other hand, the git pull origin master will fetch changes from the remote master branch and merge the changes to the branch you are currently standing at.

Let’s look at an example for both cases.

Assuming we are checked out in our feature branch, but the branch does not have a remote-tracking branch. What happens when we run the git pull command?

Git will display a message shown below.

git pull message

If you do not have a remote feature branch, you can pull changes directly from the remote master branch. This is where the git pull origin master command comes into play.

On running the command, we get:

git pull origin master

Note that this will only update our feature branch and not the master branch. If we were checked out in the master branch, the command would have updated our master branch.

If you want to update your master branch, switch to the master and run the git merge command, as illustrated below.

$ git merge Fetch_Head

Fetch_Head is a reference that keeps track of what has been fetched from the remote repository.

In a nutshell, the git pull and git pull origin master commands integrate changes from the remote repository to the current local branch. The git pull command requires your branch to have a remote tracking branch.

Invoking the git pull origin master command will fetch changes from the remote master branch and merge them to your currently checked-out branch.

Author: John Wachira
John Wachira avatar John Wachira avatar

John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.

LinkedIn

Related Article - Git Pull