Sharma
Sharma

Reputation: 17

What is the difference between git pull and git pull origin <branchName>

I have a parent branch origin/develop , from this branch I have created a child branch feature/NewFeatureBranch

I am now on feature/NewFeatureBranch using git checkout feature/NewFeatureBranch

Now I have done git pull and can see several new branches downloading to my local machine which all have parent as develop

In another scenario I have done git pull origin develop and in this case newly checked in files from other branches towards develop are getting downloaded.

so is it that git pull is behaving like git fetch and git pull origin develop is behaving like git fetch + git merge .

Upvotes: 0

Views: 1145

Answers (1)

matt
matt

Reputation: 534893

The very first words of the documentation:

In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD.

So git pull is just a shorthand. Git makes some assumptions about what you mean and supplies the missing pieces. And so, by default what it's a shorthand for is:

git fetch
git merge <remote-tracking-branch-that-current-branch-tracks> [into the current branch]

Similarly, if you actually give a remote and a branch, you are still saying:

git fetch remote
git merge remote/branch [into the current branch]

You can change the meaning of the shorthand (as part of your config setup), for example to rebase instead of merge, but most people don't. In general, some people regard it as better not to say git pull at all, but to say the fetch and then, if desired, the merge or the rebase or whatever, explicitly. This gives you a chance to "look around" and decide how to proceed.

Upvotes: 1

Related Questions