branching

git branch

Lists, creates, renames, or deletes branches — pointers to commits. Does not switch branches on its own; use switch or checkout for that.

git branch [<options>] [<name> [<start-point>]]

Common flags

Flag Purpose
-a List local and remote-tracking branches
-r List only remote-tracking branches
-d <name> Delete a fully merged branch
-D <name> Force delete a branch even if unmerged
-m <old> <new> Rename a branch
--set-upstream-to=<upstream> Configure tracking for the current branch
-vv Verbose list showing upstream tracking info

Examples

git branch

List local branches; asterisk marks the current one

git branch -d feature/login

Delete a merged feature branch

git branch -m main master-old

Rename a branch locally

Gotcha

Deleting the local branch does not delete it on the remote; use 'git push origin --delete ' for that.

Related commands

← All Git commands · Git cheat sheet · Git rebase vs merge