What exactly is a branch, and what does creating one cost?
IntermediateConceptGit internals: objects, refs and the index
Answer
A branch is a file containing a 40-hex commit ID, stored at .git/refs/heads/<name> (or in packed-refs). Creating one writes 41 bytes, so it is effectively free. Committing on a branch just moves that pointer forward to the new commit.
cat .git/refs/heads/main
git rev-parse main
More on Git internals: objects, refs and the index
What are the four object types in Git's object database?BeginnerIs Git a snapshot system or a diff system?BeginnerWhat is the SHA-1 (or SHA-256) hash of an object and how is it computed?BeginnerWhere does Git store objects on disk, and what are loose objects versus packfiles?IntermediateWhat is HEAD?BeginnerWhat is a detached HEAD and how do you recover work done in it?Intermediate