kb/branching
Git branches and how to combine them: a branch is a file holding one SHA, fast-forward and three-way merge, rebase for rewriting history, cherry-pick for moving a single commit. The section compares merge against rebase and shows you when to use each one.
A branch in Git is a file inside `.git/refs/heads/` that holds the SHA of one commit. Creating, switching, and deleting branches are trivial operations because a branch contains exactly 41 bytes of data.
A state in which HEAD points directly at a commit rather than at a branch. Safe for reading and exploring, but any commits you make in this mode are lost unless you create a branch from them.
The simplest form of merge: Git moves the branch pointer to the new commit without creating a merge object. Possible only when the target branch has no commits of its own since the point of divergence.
Takes one commit from another branch and applies it to the current one, creating a duplicate with a new SHA. Used for hotfixes across multiple release branches and for moving individual commits.
Merges another branch into the current one. Either fast-forwards the pointer or creates a merge commit with two parents. Overlapping changes produce conflicts.
Rewrites the commits of a branch so they descend from a different commit. Each commit gets a new SHA; history becomes linear. Safe only on branches that no one else has seen.
`git rebase -i <base>` opens an editor with the list of commits from `<base>` to HEAD, where you can rename, combine, delete, and reorder them. It is the primary tool for cleaning up local history.