Reputation: 1465
I have read many answers about "origin/master" where they say it's a local copy of the remote origin of branch master. I'm confused when I read about set-upstream-to where it should refer to remote branch master , so can anyone explain why set-upstream-to reference to local copy instead of remote ? like git push origin master
not git push origin/master
Upvotes: 2
Views: 3896
Reputation: 522752
You seem to have some confusion about references in the basic Git commands. And you should have confusion, because it's confusing.
The local branch master
, which exists only in your local Git repo, is in what you do most of your actual development work. Similarly, there is also a branch called master
which exists on the remote. Now, for the confusion, there is a third branch called origin/master
. This is a local branch, which exists on your local repo. It exists mainly to serve as a proxy for the true remote master
branch. Whenever you sync with the remote master
branch, locally you are actually using origin/master
.
Doing git pull origin master
is actually identical to this (assuming you are using the merge strategy by default):
git fetch origin
git merge origin/master
The first step, git fetch origin
, updates the local tracking branch origin/master
with the latest changes, such that it mirrors the true master
branch on the remote. Then, it does a merge into your local master
branch using origin/master
. Here is a brief summary:
master | the master branch (either local or remote)
origin master | the master branch on the remote (as in the git pull command)
origin/master | local tracking branch for master which mirrors the remote version
So, keeping in mind that origin/master
is the actual branch which tracks the true remote master
branch, we can tell Git to use origin/master
as the tracking branch via:
# from local master branch
git --set-upstream-to origin/master
Note that if you create or checkout master
locally, Git typically would create origin/master
as the default tracking branch behind the scenes. So, in practice, you probably won't have to use --set-upstream-to
very often.
Upvotes: 4