git branch

List, create, rename or delete branches

What it does

A branch is a movable label on a commit: you work on a separate task in it without touching the main branch. With no arguments git branch lists local branches and marks the current one with an asterisk. With a name it creates a new branch at the current commit but does not switch to it.

-m renames a branch, -d deletes one. -d refuses to delete a branch that has not been merged, which protects your work. -D deletes without checking.

Careful. git branch -D deletes a branch even if its commits exist nowhere else. After that, only git reflog can bring them back.

Syntax

git branch
git branch <name>
git branch -m <old-name> <new-name>
git branch -d <name>

Examples

Related commands

Practise · All commands