In Git, what is the difference between origin/master vs origin master?
I know, origin is a term for the remote repository and master is the branch there.
I am purposely omitting the "context" here and I am hoping that the answer should not depend upon the context. So in git command lines, what is the difference between origin/master and origin master . Is there a non-ambiguous way to understand when to use origin/master and when I should use origin master ?
There are actually three things here: origin master
is two separate things, and origin/master
is one thing. Three things total.
Two branches:
master
is a local branch origin/master
is a remote branch (which is a local copy of the branch named "master" on the remote named "origin") One remote:
origin
is a remote Example: pull in two steps
Since origin/master
is a branch, you can merge it. Here's a pull in two steps:
Step one, fetch master
from the remote origin
. The master
branch on origin
will be fetched and the local copy will be named origin/master
.
git fetch origin master
Then you merge origin/master
into master
.
git merge origin/master
Then you can push your new changes in master
back to origin
:
git push origin master
More examples
You can fetch multiple branches by name...
git fetch origin master stable oldstable
You can merge multiple branches...
git merge origin/master hotfix-2275 hotfix-2276 hotfix-2290
origin/master
is the local branch representing the state of the master
branch on the remote origin
.
origin master
is the branch master
on the remote origin
.
Example (in local branch master
):
git fetch # get current state of remote repository
git merge origin/master # merge state of remote master branch into local branch
git push origin master # push local branch master to remote branch master
origin/master
is the remote master
branch
Usually after doing a git fetch origin
to bring all the changes from the server, you would do a git rebase origin/master
, to rebase your changes and move the branch to the latest index. Here, origin/master
is referring to the remote branch, because you are basically telling GIT to rebase the origin/master
branch onto the current branch.
You would use origin master
when pushing, for example. git push origin master
is simply telling GIT to push to the remote repository the local master
branch.
上一篇: 从github远程仓库中输出git