Progress:
TIER 1 · MODULE 17· Basics

git branch

It's just a movable pointer. Treat it like one.

🎯 What & why

List, create, rename, delete, or annotate branches. Branches in Git are literally one-line files in .git/refs/heads/ (or entries in packed-refs) — each containing a 40-character SHA. That cheapness is why branching workflows became practical.

🧠 Mental model

A branch is a movable pointer to a commit. git branch reads, writes, or deletes those pointers. It does not move HEAD; that's the job of switch/checkout. Knowing this lets you reason about every branch operation as 'move/create/delete a 41-byte file.'

🛠️ Synopsis

git branch [--color[=<when>] | --no-color] [--show-current] [-v [--abbrev=<n>]]
           [--list] [<pattern>...]
git branch [--track[=(direct|inherit)] | --no-track] [-f] [--recurse-submodules]
           <branchname> [<start-point>]
git branch (-c | -C) [<oldbranch>] <newbranch>
git branch (-m | -M) [<oldbranch>] <newbranch>
git branch (-d | -D) [-r] [-f] <branchname>...

🎚️ Switches & options

FlagWhat it does
-aList all branches (local + remote-tracking).
-rList only remote-tracking branches.
-v, -vvVerbose: show tip SHA and (with -vv) upstream tracking info.
-d, --deleteDelete a fully merged branch.
-D⚠️ Force-delete, even if unmerged. ⚠️ Lost commits go to reflog only.
-m, --moveRename a branch.
--track <upstream>Set upstream tracking on creation.
--show-currentPrint just the current branch name.

💡 Use cases

🧪 Examples

List local branches.
$ git branch
List all branches with tracking info.
$ git branch -vva
Create a branch from a tag without switching.
$ git branch hotfix/1.2 v1.2
Rename current branch.
$ git branch -m new-name
Delete a merged branch.
$ git branch -d old-feature

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.