Hone

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 branch
Lists branches; * marks the one you are on.
git branch feature
A new pointer at the current commit. Nothing else changes.
git branch --show-current
main: creating a branch does not move you onto it.
git branch -d feature
Deletes a branch that is fully merged; -D forces.

Your turn

Print the branch you are on.

git branch 

The trap

Deleting a merged branch loses nothing, because its commits are reachable from main. Deleting an unmerged one orphans its commits.

Practise a branch is a name for a commit on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.