Lessons · Git · a branch is a name for a commit
A branch is a pointer
A branch is a movable name for a commit. Creating one costs nothing and changes nothing; committing on it moves it forward.
Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.
What it is for
Cheap branches are why teams work in parallel without stepping on each other: one branch per change, merged when it is ready, deleted after.
How to think about it
Create a branch for every piece of work. List them, see which you are on, delete them once merged. If a branch feels heavy, remember it is a pointer, not a copy of the files.
Worked example
git branchLists branches; * marks the one you are on.
git branch featureA new pointer at the current commit. Nothing else changes.
git branch --show-currentmain: creating a branch does not move you onto it.
git branch -d featureDeletes a branch that is fully merged; -D forces.
Your turn
Print the branch you are on.
git branch
Try it in a real repository
The trap
Deleting a merged branch loses nothing, because its commits are reachable from main. Deleting an unmerged one orphans its commits.