git branch
Create, list and rename refs that point at commits.
git branchWhat it does
A branch is nothing but a movable pointer — a text file in .git/refs/heads that stores one commit hash. git branch lists them, creates a new pointer at the current commit, or renames one. Crucially, it does NOT move you onto the branch; that's git switch or git checkout.
git branch feature just adds a second pointer to the same commit
Watch it — press play
A narrated, step-by-step walkthrough that shows how to do it — not just theory. It adapts to the learner mode you picked in the top bar.
Step 1
Pick your starting point
A branch is just a pointer to a commit. From wherever HEAD is, you can hang a new name.
git branch featureUnder the hood
A branch is a file with one hash
Creating a branch literally writes a 41-byte file. The hash is copied from wherever you were when you ran it — usually HEAD's commit.
echo 74d3b9f0… > .git/refs/heads/feature # what `git branch feature` does
Multiple branches, one commit each
Branches are cheap because they hold no data. The history they point at is shared — branch pointers just let you name different positions along it.
Listing reads refs and shows HEAD target
`git branch` reads every file in refs/heads, resolves each to its commit, and puts an asterisk on the branch that HEAD's ref: line names.
$ git branch * main feature/login feature/export
Deleting removes the pointer, never the commits
Deleting a branch deletes its ref file only. The commits remain in objects/ and stay alive until garbage collected — which is why you can often recover a 'deleted' branch.
Command anatomy
<name>Create a new branch pointing at your current commit.
-aList all branches, including remote-tracking ones.
-d / -DDelete a branch (merged / force).
-mRename the current branch.
-vvShow which refs each local branch tracks.
When to reach for it
You want to start a feature without leaving your current branch yet.
Check what branches exist and where they point before switching.
Cleaning up stale branches with -d after a merge.
Practice
A real repo, pre-seeded with history, runs right here — stage, commit, branch, stash, diff, even hit and resolve a real merge conflict. Nothing to install, nothing leaves your machine.
Open practice playground