Git: handy branching commands

Here's a little cheatsheet to help deal with branches.

Listing branches

List branches:

$ git brach

List remote branches:

$ git branch --remote # Or -r for short

List remote branches that are not tracked:

$ git ls-remote --heads <remote-name>

Making and editing branches

Make a new branch based on the active branch:

$ git branch <branch-name>

Rename a branch:

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

Rename the active branch:

$ git branch -m <new-name>

Deleting branches

Delete a branch:

$ git branch -d <branch-name>

Git docs on the -d flag:

Delete a branch. The branch must be fully merged in its upstream branch, or in HEAD if no upstream was set with

If a branch that is not merged is wanted to be deleted, use the -D flag:

$ git branch -D <branch-name>

Delete remote branch:

$ git branch -d -r origin/<branch-name>

As always, see the docs on the branch command for more complete set of information.

Club-Mate, the beverage →