Difference between git pull and git pull origin master

GitGithub

Git Problem Overview


What is the difference between these two commands?

git pull

and

git pull origin master

Git Solutions


Solution 1 - Git

[Edit, May 2018: git pull is no longer a shell script and a few details are different in modern Git. Pull also now has recursion options that make it more useful with submodules. This answer ignores the submodules.]

The git pull script is meant as a convenience method for invoking git fetch followed by git merge (or, with git pull --rebase, invoking git fetch followed by git rebase).

The first extra argument to git pull tells it which remote to give to the fetch operation:

git pull origin

for example, means to fetch from origin. If you leave this out, Git uses the current branch's remote:

$ git branch
* master
$ git config --get branch.master.remote
origin

The second (and any additional) arguments to git pull tell it which branch or branches to merge in. These are the names of the branches as found on the remote. For instance, suppose you create a new branch feature2 that tracks origin/feature:

$ git checkout -b feature2 origin/feature

If you now want to fetch from origin to pick up new commits added to their feature branch, but merge them in to your local feature2 branch:

$ git pull origin feature

If you leave out the branch name(s), git uses the current branch's merge:

$ git config --get branch.feature2.merge
feature

Note that if you list multiple branch names, Git will do an "octopus merge". In my experience, this usually surprises people the first time: they think git pull remote br1 br2 will run git fetch followed by a series of separate git merge-s on each branch, but that's not what happens.

Solution 2 - Git

git pull origin master will pull changes from the origin remote, master branch and merge them to the local checked-out branch.

where as git pull will fetch new commits from all tracked branches from the default remote(origin). you can also configure default remote and branch name in gitconfig file.

git branch --set-upstream master origin/master

This will add the following info to your gitconfig file:

[branch "master"]
    remote = origin
    merge = refs/heads/master

now whenever you say git pull it will fetch from origin master.

Solution 3 - Git

git pull origin master is the verbose form which specifies both the remote (origin) and the branch to pull from (master). If you don’t specify that, Git will apply a default behavior that is explained in the documentation:

> Often people use git pull without giving any parameter. Traditionally, this has been equivalent to saying git pull origin. However, when configuration branch.<name>.remote is present while on branch <name>, that value is used instead of origin. > > […] > > In order to determine what remote branches to fetch (and optionally store in the remote-tracking branches) when the command is run without any refspec parameters on the command line, values of the configuration variable remote.<origin>.fetch are consulted, and if there aren't any, $GIT_DIR/remotes/<origin> file is consulted and its Pull: lines are used.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSachin KainthView Question on Stackoverflow
Solution 1 - GittorekView Answer on Stackoverflow
Solution 2 - Gitnitesh goelView Answer on Stackoverflow
Solution 3 - GitpokeView Answer on Stackoverflow