Git Reference / Branching
06Branching
Branches are cheap — a 41-byte file. Make one for every feature, fix or experiment.
A feature branch diverging from
main.Create & switch
switch is the modern, focused alternative to checkout.
git switch -c feature/login # create + switch git switch main git switch - # previous branch git switch -c fix origin/fix # track a remote branch
List branches
Local, remote, merged or stale.
git branch -vv # with upstream + last commit git branch -a # include remotes git branch --merged main git branch --sort=-committerdate
Rename & delete
Clean up when you’re done.
git branch -m old-name new-name git branch -d feature # safe: only if merged git branch -D feature # force git push origin --delete feature
Detached HEAD
Look around an old commit without a branch.
git switch --detach v1.2.0
# made commits? keep them:
git switch -c rescue-branch