A Git Branch as a Moving Reference
A local branch names a commit at the tip of a line of work. New commits on the active branch normally advance that reference.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Trace branches from one point
Start branches docs and tests at commit A. A commit B made on docs moves only docs to B, with A as B's parent. The tests branch still names A. A commit snapshot gives those tips their content and ancestry.
Keep branch identity distinct from contents
Two branches can temporarily point to the same commit and later diverge. Compare their ancestry to determine which changes each includes. Fast-forward updates depend on that ancestry relation.[1]
Write the reference before and after a commit
Suppose a feature branch points to B, whose parent is A. Committing C while that branch is active advances its pointer to C, leaving A and B in the graph. A second branch pointing to B stays there unless updated separately. See recognizing a fast-forward.
Before: main→B, feature→B
Commit C as child of B on feature
After: main→B, feature→C
A and B keep their existing IDs
Distinguish local and remote-tracking names
A locally named branch and a remote-tracking reference are different pointers. Observing one says little about the current server until related operations refresh it. Test your understanding by reading each reference name with its destination.