Name

branch

Synopsis

git branch [-r] [-a] [--contains commit]
git branch [-f] [--track] branchname [commit]
git branch -m oldname newname
git branch -d|-D [-r] branchname

List, create, rename, and delete branches.

git branch [-r] [-a] [--contains commit]

List the existing branches. By default, lists only local branches (.git/refs/heads/*). With -r, list remote tracking branches instead (.git/refs/remotes/*/*). With -a, list all local and remote tracking branches. With --contains, list only the branches that contain the given commit.

git branch [-f] [--track|--no-track] branchname [commit]

Create a new branch, branchname, that points at the given commit. The default for commit is HEAD. If branchname already exists, the operation will fail unless -f is specified. If you specify --track (the default in newer versions of Git) and commit is a remote tracking branch, you will be able to type simply git merge or git pull in the future to merge remote changes into your branch.

Tip

This command does not check out your new branch. If you want to create a new branch and check it out in one step, use git checkout -b.

git branch -m|-Moldnamenewname

Rename a branch from oldname to newname. If newname already exists, -m will fail while -M will overwrite it.

git branch -d|-D [-r]branchname

Delete branchname. If -r is specified, branchname is a remote tracking branch (.git/refs/remotes/*/*); otherwise it is a local branch (.git/refs/heads/*). If you use -d, the branch will only be deleted if your current HEAD ...

Get Linux in a Nutshell, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.