All commands

git branch

Create, list and rename refs that point at commits.

What 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.

9a2f1c0init project4b7c2a5add components74d3b9ffeat: dark modemainHEADfeature

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.

1 / 3

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 feature
9a2f1c0init project4b7c2a5add componentsc86d9eestyle layoutmainHEAD

Under the hood

1

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
2

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.

3

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
4

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 branch
AliasWhy people use it
g b

The universal shorthand for listing branches.

g bav

List everything with tracking info.

g ba

Include remote-tracking branches in the list.

g bd

Delete a merged branch.

g bnm

What's not merged yet — pre-merge check.

Command anatomy

git branch <name>
<name>

Create a new branch pointing at your current commit.

-a

List all branches, including remote-tracking ones.

-d / -D

Delete a branch (merged / force).

-m

Rename the current branch.

-vv

Show 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.

Go deeper with