the /
between origin and branch
some time i need put / between origin and branch, somemtime not, could anyone explain me why?
for example here is no /
git push -u origin branch_name
here is with /
git diff master origin/branch_name
the /
between origin and branch
some time i need put / between origin and branch, somemtime not, could anyone explain me why?
for example here is no /
git push -u origin branch_name
here is with /
git diff master origin/branch_name
One funny thing with git
is that you cannot look at branches in a remote, only local ones.
When you do git fetch origin
you are telling git
to sync all the X
branches from that remote into local branches named remotes/origin/X
. Then when you do git log origin/X
you are actually looking the history of the local branch remotes/origin/X
(the remotes
part is assumed).
Some people call these remote branches, but they are actually local branches that mimick remote branches.
In the command line, when you name a commit (branch, tag...) and you want to use a remote branch (actually a local branch that mimicks a remote one) you must use the origin/master
format or remotes/origin/master
.
But if you use a command that uses a remote proper and a real remote branch then you use two arguments, one for the remote and another one for the branch or branches. In this case, the real remote branch name will not have the remote/
part.
For example:
git fetch origin master
: Fetch the real remote branch master
from remote origin
and clone it into local branch remotes/origin/master
(with default config).git fetch origin master:foo
: Fetch the real remote branch master
from remote origin
and clone it into local branch foo
.git log origin/master
: Show log of local branch remotes/origin/master
that will have the same content of remote master
in origin
at the time of the previous fetch.git push origin foo:bar
: Upload the local branch foo
into origin
as a remote branch named bar
. If then you do git fetch origin
you will get a new remotes/origin/bar
branch identical to foo
.git push
: If the current branch is configured with upstream, then it will be equivalent to git push <upstream-remote> <upstream-branch>
.NOTE: Note the default refspec when you do a git fetch origin
is +refs/heads/*:refs/remotes/origin/*
. See how it makes sense if you remember that the refs/
part means just the directory of branches and tags, the heads/
means local branches, and remotes/
means local clone of remote branches.
origin
conventionally refers to the remote from which you cloned your repo. Similarly master conventionally refers to the main branch in your repository.
In the first command, you are asking git to push a branch called master
in your local to a remote called origin
.
In the second command, you are asking git to show you the difference in the branch called master
in your local and a branch called master
in a remote called origin
.
Contrast it with something like
git pull upstream feature1
or
git diff origin/master upstream/master
In the first case, you are pulling from a branch called feature1
in a remote called upstream
in to your current local branch.
In the second one, you are checking the difference between the master
branch in your remote called origin
and the master
branch in a remote called upstream