It's just a movable pointer. Treat it like one.
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.
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.'
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>...| Flag | What it does |
|---|---|
-a | List all branches (local + remote-tracking). |
-r | List only remote-tracking branches. |
-v, -vv | Verbose: show tip SHA and (with -vv) upstream tracking info. |
-d, --delete | Delete a fully merged branch. |
-D | ⚠️ Force-delete, even if unmerged. ⚠️ Lost commits go to reflog only. |
-m, --move | Rename a branch. |
--track <upstream> | Set upstream tracking on creation. |
--show-current | Print just the current branch name. |
$ git branch$ git branch -vva$ git branch hotfix/1.2 v1.2$ git branch -m new-name$ git branch -d old-featuregit switch -c <name> for create-and-switch. Use git branch <name> only when you want to create without switching.branch.autoSetupMerge = always so new branches track their start point automatically.git fetch --prune (or git remote prune origin).-d won't delete an unmerged branch. -D will, silently. Look before you leap.Hit each option, then Check answers. Score is recorded; Next is always open.