Branches and HEAD
Until now we worked on a single line of history. But what if you want to try a new idea without touching the code that works? That's where branches come in. The big secret: a branch is not a heavy copy of the project — it's just a lightweight label pointing at a certain commit, so creating one is in
A branch is like a sticky-note label you slide along the chain of photos of your project — it just marks a certain photo. HEAD is the arrow that says which label you're standing on right now.
- Branch
- A lightweight, movable label that points at a commit. Creating a branch is just making a tiny file holding the commit's hash, so it's instant and takes almost no space.
- HEAD
- A special pointer that says 'you are here' — which branch (and through it, which commit) you are standing on right now.
- git switch
- Move between branches. git switch -c <name> creates a new branch and moves you onto it. (The older, equivalent command is git checkout -b.)
- main
- The common name for the primary branch in new repos (formerly master). It's just an ordinary branch — there's no special magic in it for Git.
- git branch
- With no argument — lists the branches, with an asterisk (*) next to the active one. With a name — creates a new branch without moving onto it.