Differences between git pull origin master & git pull origin/master

GitVersion Control

Git Problem Overview


What is the difference between git pull origin master and git pull origin/master ?

Git Solutions


Solution 1 - Git

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

git pull origin/master will pull changes from the locally stored branch origin/master and merge that to the local checked-out branch. The origin/master branch is essentially a "cached copy" of what was last pulled from origin, which is why it's called a remote branch in git parlance. This might be somewhat confusing.

You can see what branches are available with git branch and git branch -r to see the "remote branches".

Solution 2 - Git

git pull origin master will fetch all the changes from the remote's master branch and will merge it into your local. We generally do not use git pull origin/master. We can do the same thing by git merge origin/master. It will merge all the changes from "cached copy" of origin's master branch into your local branch. In my case, git pull origin/master is throwing the error:

fatal: 'origin/master' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Solution 3 - Git

git pull = git fetch + git merge origin/branch

git pull and git pull origin branch only differ in that the latter will only "update" origin/branch and not all origin/* as git pull does.

git pull origin/branch will just not work because it's trying to do a git fetch origin/branch which is invalid.

Question related: https://stackoverflow.com/questions/61211167/git-fetch-git-merge-origin-master-vs-git-pull-origin-master/61216900#61216900

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
QuestionRachelView Question on Stackoverflow
Solution 1 - GitJakob BorgView Answer on Stackoverflow
Solution 2 - GitDhruvil ShahView Answer on Stackoverflow
Solution 3 - Gituser33276346View Answer on Stackoverflow