I noticed the ability of git to checkout to a specific commit. After that, I began to understand how git really works.
But I want to be sure that this is correct:
When I create a branch, it is nothing more than a tag that points to the current commit. When I checkout this branch, I checkout the commit this “tag” points to. Now, when I commit something, a new commit is created. The current checked out branch tag is now updated, so that it points to the new commit.
So… in fact, I could do all of this manually, right?
It´s just a feature to make things easier.
Yes, that’s a good model for what a branch is. Beware, though, about the terminology – git also has a concept of tags, but tags don’t move – they forever point to the same commit.
Update: adding a little more detail, which might be of interest…
Your current branch is stored in the file
HEAD, which either points to a branch, in which case the contents look like:… or it points directly to a commit, in which case the contents will look like:
In the former case, the branch
masteris advanced when you create a new commit, but in the latter situation (known as “detached HEAD” for hopefully obvious reasons), no branch will be changed when you create a new commit.