Skip to content

What it is

A branch is a lightweight, movable pointer to a commit — not a copy of the code — that lets parallel lines of work diverge and merge.

In Git, a branch is a file at .git/refs/heads/main containing a 40-character SHA (or 64 with SHA-256) pointing to the latest commit on that branch. Creating a branch writes a new file with the same SHA. Switching branches (checkout) rewrites the working tree to match the target commit. Merging two branches finds their common ancestor and combines the changes.

This is radically different from older systems. In Subversion, a branch is a directory copy — cheap but not free. In Mercurial, a branch is a named line of commits. In Git, a branch is just a label: the "branching" is the fact that different commits have different parents.