Linux "git-branch" Command Line Options and Examples
List, create, or delete branches

If --list is given, or if there are no non-option arguments, existing branches are listed; the current branch will be highlighted with an asterisk. Option -r causes the remote-tracking branches to be listed, and option -a shows both local and remote branches. If a <pattern> is given, it is used as a shell wildcard to restrict the output to matching branches.


Usage:

git branch [--color[=] | --no-color] [-r | -a]
[--list] [-v [--abbrev= | --no-abbrev]]
[--column[=] | --no-column] [--sort=]
[(--merged | --no-merged) []]
[--contains [<commit]] [--no-contains []]
[--points-at ] [--format=] [...]
git branch [--track | --no-track] [-l] [-f] []
git branch (--set-upstream-to= | -u ) []
git branch --unset-upstream []
git branch (-m | -M) []
git branch (-c | -C) []
git branch (-d | -D) [-r] ...
git branch --edit-description []






Command Line Options:

-d
Delete a branch. The branch must be fully merged in its upstream branch, or in HEAD if no upstream was set with --track or
git-branch -d ...
-D
Shortcut for --delete --force.
git-branch -D ...
-l
Create the branch’s reflog. This activates recording of all changes made to the branch ref, enabling use of date based sha1expressions such as "<branchname>@{yesterday}". Note that in non-bare repositories, reflogs are usually enabled by default by thecore.logAllRefUpdates config option. The negated form --no-create-reflog only overrides an earlier --create-reflog, but currentlydoes not negate the setting of core.logAllRefUpdates.
git-branch -l ...
-f
Reset <branchname> to <startpoint>, even if <branchname> exists already. Without -f, git branch refuses to change an existingbranch. In combination with -d (or --delete), allow deleting the branch irrespective of its merged status. In combination with -m(or --move), allow renaming the branch even if the new branch name already exists, the same applies for -c (or --copy).
git-branch -f ...
-m
Move/rename a branch and the corresponding reflog.
git-branch -m ...
-M
Shortcut for --move --force.
git-branch -M ...
-c
Copy a branch and the corresponding reflog.
git-branch -c ...
-C
Shortcut for --copy --force.
git-branch -C ...
--color[
Color branches to highlight current, local, and remote-tracking branches. The value must be always (the default), never, or auto.
git-branch --color[ ...
--no-color
Turn off branch colors, even when the configuration file gives the default to color output. Same as --color=never.
git-branch --no-color ...
-i
Sorting and filtering branches are case insensitive.
git-branch -i ...
--column[
Display branch listing in columns. See configuration variable column.branch for option syntax.--column and --no-column withoutoptions are equivalent to always and never respectively.This option is only applicable in non-verbose mode.
git-branch --column[ ...
-r
List or delete (if used with -d) the remote-tracking branches.
git-branch -r ...
-a
List both remote-tracking branches and local branches.
git-branch -a ...
--list
List branches. With optional <pattern>..., e.g. git branch --list 'maint-*', list only the branches that match the pattern(s).This should not be confused with git branch -l <branchname>, which creates a branch named <branchname> with a reflog. See
git-branch --list ...
--create-reflog
above for details.
git-branch --create-reflog ...
-v
When in list mode, show sha1 and commit subject line for each head, along with relationship to upstream branch (if any). If giventwice, print the name of the upstream branch, as well (see also git remote show <remote>).
git-branch -v ...
-q
Be more quiet when creating or deleting a branch, suppressing non-error messages.
git-branch -q ...
--abbrev
Alter the sha1’s minimum display length in the output listing. The default value is 7 and can be overridden by the core.abbrevconfig option.
git-branch --abbrev ...
--no-abbrev
Display the full sha1s in the output listing rather than abbreviating them.
git-branch --no-abbrev ...
-t
When creating a new branch, set up branch.<name>.remote and branch.<name>.merge configuration entries to mark the start-pointbranch as "upstream" from the new branch. This configuration will tell git to show the relationship between the two branches ingit status and git branch -v. Furthermore, it directs git pull without arguments to pull from the upstream when the new branch ischecked out.This behavior is the default when the start point is a remote-tracking branch. Set the branch.autoSetupMerge configurationvariable to false if you want git checkout and git branch to always behave as if --no-track were given. Set it to always if youwant this behavior when the start-point is either a local or remote-tracking branch.
git-branch -t ...
--no-track
Do not set up "upstream" configuration, even if the branch.autoSetupMerge configuration variable is true.
git-branch --no-track ...
--set-upstream
As this option had confusing syntax, it is no longer supported. Please use --track or --set-upstream-to instead.
git-branch --set-upstream ...
-u
Set up <branchname>'s tracking information so <upstream> is considered <branchname>'s upstream branch. If no <branchname> isspecified, then it defaults to the current branch.
git-branch -u ...
--unset-upstream
Remove the upstream information for <branchname>. If no branch is specified it defaults to the current branch.
git-branch --unset-upstream ...
--edit-description
Open an editor and edit the text to explain what the branch is for, to be used by various other commands (e.g. format-patch,request-pull, and merge (if enabled)). Multi-line explanations may be used.
git-branch --edit-description ...
--contains
Only list branches which contain the specified commit (HEAD if not specified). Implies --list.
git-branch --contains ...
--no-contains
Only list branches which don’t contain the specified commit (HEAD if not specified). Implies --list.
git-branch --no-contains ...
--merged
Only list branches whose tips are reachable from the specified commit (HEAD if not specified). Implies --list, incompatible with
git-branch --merged ...
--no-merged
Only list branches whose tips are not reachable from the specified commit (HEAD if not specified). Implies --list, incompatiblewith --merged.<branchname>The name of the branch to create or delete. The new branch name must pass all checks defined by git-check-ref-format(1). Some ofthese checks may restrict the characters allowed in a branch name.<start-point>The new branch head will point to this commit. It may be given as a branch name, a commit-id, or a tag. If this option isomitted, the current HEAD will be used instead.<oldbranch>The name of an existing branch to rename.<newbranch>The new name for an existing branch. The same restrictions as for <branchname> apply.
git-branch --no-merged ...
--sort
Sort based on the key given. Prefix - to sort in descending order of the value. You may use the --sort=<key> option multipletimes, in which case the last key becomes the primary key. The keys supported are the same as those in git for-each-ref. Sortorder defaults to sorting based on the full refname (including refs/... prefix). This lists detached HEAD (if present) first,then local branches and finally remote-tracking branches.
git-branch --sort ...
--points-at
Only list branches of the given object.
git-branch --points-at ...
--format
A string that interpolates %(fieldname) from a branch ref being shown and the object it points at. The format is the same as thatof git-for-each-ref(1).CONFIGURATIONpager.branch is only respected when listing branches, i.e., when --list is used or implied. The default is to use a pager. See git-config(1).EXAMPLESStart development from a known tag$ git clone git://git.kernel.org/pub/scm/.../linux-2.6 my2.6$ cd my2.6$ git branch my2.6.14 v2.6.14 (1)$ git checkout my2.6.141. This step and the next one could be combined into a single step with "checkout -b my2.6.14 v2.6.14".Delete an unneeded branch$ git clone git://git.kernel.org/.../git.git my.git$ cd my.git$ git branch -d -r origin/todo origin/html origin/man (1)$ git branch -D test (2)1. Delete the remote-tracking branches "todo", "html" and "man". The next fetch or pull will create them again unless youconfigure them not to. See git-fetch(1).2. Delete the "test" branch even if the "master" branch (or whichever branch is currently checked out) does not have all commitsfrom the test branch.NOTESIf you are creating a branch that you want to checkout immediately, it is easier to use the git checkout command with its -b optionto create a branch and check it out with a single command.The options --contains, --no-contains, --merged and --no-merged serve four related but different purposes:
git-branch --format ...