A new branch is just a new ref pointing at a commit. Today you create one, and confirm it starts life pointing at the same commit as the branch you are on, without moving HEAD.
Create a branch ref at the current commit, leaving HEAD unchanged.
Creating a branch is one of Git’s cheapest operations because a branch is one
small file. Branch("dev") resolves the current commit and writes it to
refs/heads/dev. Now two branch labels, main and dev, point at the very same
commit 9bae7f0a.... No objects are copied; both are just names for the same tip.
Crucially, creating a branch does not move HEAD onto it: you stay on main.
This separation matters, because the branch you are on (HEAD) and the branches
that merely exist are different things. To start adding commits to dev you must
first switch to it, which retargets HEAD, and that is the last piece of this
chapter.
// point a new branch ref at wherever HEAD currently resolvesfunc (r *Repo) Branch(name string) error {id, _ := r.Resolve("HEAD")return r.UpdateRef("refs/heads/"+name, id)}