Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between git pull and git pull origin master [duplicate]

Tags:

git

github

What is the difference between these two commands?

git pull 

and

git pull origin master 
like image 295
Sachin Kainth Avatar asked May 30 '14 11:05

Sachin Kainth


2 Answers

[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.

like image 118
torek Avatar answered Oct 01 '22 12:10

torek


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.

like image 27
nitesh goel Avatar answered Oct 01 '22 13:10

nitesh goel