3 ms·
The intuition is that a branch consists of a line of commits off of a trunk. Like, you know, what the word "branch" means in real life. But in git, a branch d
by zestyping 3y ago
The intuition is that a branch consists of a line of commits off of a trunk. Like, you know, what the word "branch" means in real life.
But in git, a branch doesn't "contain" anything. It is just a pointer to a single commit. This is completely counterintuitive and makes no sense to most people at first, for a very good reason: the analogy is misleading.
These things shouldn't be called branches. They are pointers: they can be repointed anywhere, dereferenced, and copied by reference.
HEAD is also a stupid term, because it doesn't refer to the head of anything. HEAD is the current pointer, and it can point to any commit, not just the head of a branch. It should be called something like "here". The "detached HEAD" warning is scary and useless.
Just look at these two commands, which do very similar things but look totally different:
git checkout -b staging
git branch -f staging 3d1b582
They are just pointer assignments. Wouldn't it make a lot more sense if they were written like this?
git point staging here
git repoint staging 3d1b582