Home·Terminal commands

git branch

git

Usage

git branch [-a|-vv] [-d <name>]

Lists, creates and deletes branches locally; deleting one leaves the remote copy alone, so the server still needs git push origin --delete.

Common flags

FlagMeaning
-alocal and remote-tracking branches
-rremote-tracking branches only
-vvlast commit and upstream of each branch
-d <name>delete a branch that is already merged
-D <name>delete it even if unmerged; those commits are left behind
-m <old> <new>rename
--mergedbranches already contained in the current one
--show-currentprint the branch you are on

Examples

git branch -vv

every local branch with its upstream and last commit

git branch -d old-feature

removes a merged branch locally only

git push origin --delete old-feature

the separate step that removes it on the server

The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does git branch do?

Lists, creates and deletes branches locally; deleting one leaves the remote copy alone, so the server still needs git push origin --delete.

Q. How do I type it?

git branch [-a|-vv] [-d <name>] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

8 are listed here; the full set is in man git. This command sits under git.

Related commands

man page: man git-branch