As I'm learning about git, I keep coming across the terms HEAD, master, origin, and I'm not sure what the differences are. If I understand correctly, HEAD is always equal to the latest revision? And if so, is that the latest revision of the whole repository, or of a specific branch or tag? This is so confusing. I've read so many tutorials on this and things like branching/merging, but still can't wrap my head around it.
I highly recommend the book "Pro Git" by Scott Chacon. Take time and really read it, while exploring an actual git repo as you do.
HEAD: the current commit your repo is on. Most of the time HEAD
points to the latest commit in your current branch, but that doesn't have to be the case. HEAD
really just means "what is my repo currently pointing at".
In the event that the commit HEAD
refers to is not the tip of any branch, this is called a "detached head".
master: the name of the default branch that git creates for you when first creating a repo. In most cases, "master" means "the main branch". Most shops have everyone pushing to master, and master is considered the definitive view of the repo. But it's also common for release branches to be made off of master for releasing. Your local repo has its own master branch, that almost always follows the master of a remote repo.
origin: the default name that git gives to your main remote repo. Your box has its own repo, and you most likely push out to some remote repo that you and all your coworkers push to. That remote repo is almost always called origin, but it doesn't have to be.
HEAD
is an official notion in git. HEAD
always has a well-defined meaning. master
and origin
are common names usually used in git, but they don't have to be.
HEAD
is not the latest revision, it's the current revision. Usually, it's the latest revision of the current branch, but it doesn't have to be.
master
is a name commonly given to the main branch, but it could be called anything else (or there could be no main branch).
origin
is a name commonly given to the main remote. remote is another repository that you can pull from and push to. Usually it's on some server, like github.
git checkout v1.1
) then your HEAD changes to the commit of that tag. It may not be the latest commit. –
Ojeda © 2022 - 2024 — McMap. All rights reserved.
“This is so confusing… but still can't wrap my head around it.”
I see what you did there… 😉 – Lafferty