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.
Aliases the pros type
Memorize the git branch concept, then let one of these shortcuts make it instant. Aliases are real git config keys — add one with:
git config --global alias.st # → git branchg bgit branchThe universal shorthand for listing branches.
g bavgit branch -avvList everything with tracking info.
g bagit branch -aInclude remote-tracking branches in the list.
g bdgit branch -dDelete a merged branch.
g bnmgit branch --no-mergedWhat's not merged yet — pre-merge check.
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.
Pro tip
Create AND check out in one move: `git switch -c feature` (or the older `git checkout -b feature`). Two separate actions — create pointer, then move HEAD — are compressed into one command.