master
, HEAD
, origin/something
and maybe some tag, why not, may all point to the same commit, but they are most definitely not the same thing.
origin
is usually the name of a remote repository.
You can see your remotes and configure new ones with git remote -v
.
Try it (with -v
) and it will probably make sense.
remote/somebranch
points to the head of some branch on a remote repository.
origin/master
points to the head of master
on origin
.
Is it the same as master
?
Yes and no. If you pull your master branch, do some work and in the meantime somebody else commits on master
and pushes to origin
, they will differ.
When you do a git fetch origin
, then, origin/master
will have additional commits (will be ahead).
HEAD
is simply "the current commit".
Think of it as .
.
See this question
Again, this could be the same as master
, but if you check out another branch or commit or are in the middle of a rebase, well, it's not.
So try this on a fresh repository on which nobody else is working:
$ git checkout master
$ git log -1 --format="%H" HEAD
123abc
$ git log -1 --format="%H" origin/master
123abc
They are the same!
$ git diff origin/master
Of course their content is the same.
$ echo "foo" > foo
$ git add foo
$ git commit -m "Foo the thingy"
$ git log -1 --format="%H" HEAD
321bca
$ git log -1 --format="%H" origin/master
123abc
Ah, look, now they're different commits!
$ git push origin master
$ git log -1 --format="%H" HEAD
321bca
$ git log -1 --format="%H" origin/master
321bca
And now they aren't! we have pushed our latest commit and they both point to the same.
$ git checkout -b newbranch
$ echo "baz" > baz
$ git add baz
$ git commit -m "Baz the thingy with the stuff"
$ git branch -a
master
* new_branch
origin/master
$ git log -1 --format="%H"
789def
$ git log -1 --format="%H" master
321bca
git log -1 --format="%H" origin/master
321bca
git log -1 --format="%H" origin/new_branch
unknown revision or path not in the working tree.
Of course not. We haven't pushed new_branch
to origin
, it is only on our local machine
git checkout 123abc
We have just checked out 123abc
, the old head of master
. It is not the head of any branch, now, but we can check it out just the same.
Note: checking out 123abc. You are in 'detached HEAD' state, etc
$ git checkout -b old_master
$ git branch -a
master
* new_branch
origin/master
old_master
Now guess what their SHA1 will respectively be?