1GIT-BRANCH(1) Git Manual GIT-BRANCH(1)
2
3
4
6 git-branch - List, create, or delete branches
7
9 git branch [--color[=<when>] | --no-color] [-r | -a]
10 [--list] [-v [--abbrev=<length> | --no-abbrev]]
11 [--column[=<options>] | --no-column]
12 [(--merged | --no-merged | --contains) [<commit>]] [<pattern>...]
13 git branch [--set-upstream | --track | --no-track] [-l] [-f] <branchname> [<start-point>]
14 git branch (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>]
15 git branch --unset-upstream [<branchname>]
16 git branch (-m | -M) [<oldbranch>] <newbranch>
17 git branch (-d | -D) [-r] <branchname>...
18 git branch --edit-description [<branchname>]
19
20
22 If --list is given, or if there are no non-option arguments, existing
23 branches are listed; the current branch will be highlighted with an
24 asterisk. Option -r causes the remote-tracking branches to be listed,
25 and option -a shows both local and remote branches. If a <pattern> is
26 given, it is used as a shell wildcard to restrict the output to
27 matching branches. If multiple patterns are given, a branch is shown if
28 it matches any of the patterns. Note that when providing a <pattern>,
29 you must use --list; otherwise the command is interpreted as branch
30 creation.
31
32 With --contains, shows only the branches that contain the named commit
33 (in other words, the branches whose tip commits are descendants of the
34 named commit). With --merged, only branches merged into the named
35 commit (i.e. the branches whose tip commits are reachable from the
36 named commit) will be listed. With --no-merged only branches not merged
37 into the named commit will be listed. If the <commit> argument is
38 missing it defaults to HEAD (i.e. the tip of the current branch).
39
40 The command’s second form creates a new branch head named <branchname>
41 which points to the current HEAD, or <start-point> if given.
42
43 Note that this will create the new branch, but it will not switch the
44 working tree to it; use "git checkout <newbranch>" to switch to the new
45 branch.
46
47 When a local branch is started off a remote-tracking branch, Git sets
48 up the branch so that git pull will appropriately merge from the
49 remote-tracking branch. This behavior may be changed via the global
50 branch.autosetupmerge configuration flag. That setting can be
51 overridden by using the --track and --no-track options, and changed
52 later using git branch --set-upstream-to.
53
54 With a -m or -M option, <oldbranch> will be renamed to <newbranch>. If
55 <oldbranch> had a corresponding reflog, it is renamed to match
56 <newbranch>, and a reflog entry is created to remember the branch
57 renaming. If <newbranch> exists, -M must be used to force the rename to
58 happen.
59
60 With a -d or -D option, <branchname> will be deleted. You may specify
61 more than one branch for deletion. If the branch currently has a reflog
62 then the reflog will also be deleted.
63
64 Use -r together with -d to delete remote-tracking branches. Note, that
65 it only makes sense to delete remote-tracking branches if they no
66 longer exist in the remote repository or if git fetch was configured
67 not to fetch them again. See also the prune subcommand of git-remote(1)
68 for a way to clean up all obsolete remote-tracking branches.
69
71 -d, --delete
72 Delete a branch. The branch must be fully merged in its upstream
73 branch, or in HEAD if no upstream was set with --track or
74 --set-upstream.
75
76 -D
77 Delete a branch irrespective of its merged status.
78
79 -l, --create-reflog
80 Create the branch’s reflog. This activates recording of all changes
81 made to the branch ref, enabling use of date based sha1 expressions
82 such as "<branchname>@{yesterday}". Note that in non-bare
83 repositories, reflogs are usually enabled by default by the
84 core.logallrefupdates config option.
85
86 -f, --force
87 Reset <branchname> to <startpoint> if <branchname> exists already.
88 Without -fgit branch refuses to change an existing branch.
89
90 -m, --move
91 Move/rename a branch and the corresponding reflog.
92
93 -M
94 Move/rename a branch even if the new branch name already exists.
95
96 --color[=<when>]
97 Color branches to highlight current, local, and remote-tracking
98 branches. The value must be always (the default), never, or auto.
99
100 --no-color
101 Turn off branch colors, even when the configuration file gives the
102 default to color output. Same as --color=never.
103
104 --column[=<options>], --no-column
105 Display branch listing in columns. See configuration variable
106 column.branch for option syntax.--column and --no-column without
107 options are equivalent to always and never respectively.
108
109 This option is only applicable in non-verbose mode.
110
111 -r, --remotes
112 List or delete (if used with -d) the remote-tracking branches.
113
114 -a, --all
115 List both remote-tracking branches and local branches.
116
117 --list
118 Activate the list mode. git branch <pattern> would try to create a
119 branch, use git branch --list <pattern> to list matching branches.
120
121 -v, -vv, --verbose
122 When in list mode, show sha1 and commit subject line for each head,
123 along with relationship to upstream branch (if any). If given
124 twice, print the name of the upstream branch, as well (see also git
125 remote show <remote>).
126
127 -q, --quiet
128 Be more quiet when creating or deleting a branch, suppressing
129 non-error messages.
130
131 --abbrev=<length>
132 Alter the sha1’s minimum display length in the output listing. The
133 default value is 7 and can be overridden by the core.abbrev config
134 option.
135
136 --no-abbrev
137 Display the full sha1s in the output listing rather than
138 abbreviating them.
139
140 -t, --track
141 When creating a new branch, set up configuration to mark the
142 start-point branch as "upstream" from the new branch. This
143 configuration will tell git to show the relationship between the
144 two branches in git status and git branch -v. Furthermore, it
145 directs git pull without arguments to pull from the upstream when
146 the new branch is checked out.
147
148 This behavior is the default when the start point is a
149 remote-tracking branch. Set the branch.autosetupmerge configuration
150 variable to false if you want git checkout and git branch to always
151 behave as if --no-track were given. Set it to always if you want
152 this behavior when the start-point is either a local or
153 remote-tracking branch.
154
155 --no-track
156 Do not set up "upstream" configuration, even if the
157 branch.autosetupmerge configuration variable is true.
158
159 --set-upstream
160 If specified branch does not exist yet or if --force has been
161 given, acts exactly like --track. Otherwise sets up configuration
162 like --track would when creating the branch, except that where
163 branch points to is not changed.
164
165 -u <upstream>, --set-upstream-to=<upstream>
166 Set up <branchname>'s tracking information so <upstream> is
167 considered <branchname>'s upstream branch. If no <branchname> is
168 specified, then it defaults to the current branch.
169
170 --unset-upstream
171 Remove the upstream information for <branchname>. If no branch is
172 specified it defaults to the current branch.
173
174 --edit-description
175 Open an editor and edit the text to explain what the branch is for,
176 to be used by various other commands (e.g. request-pull).
177
178 --contains [<commit>]
179 Only list branches which contain the specified commit (HEAD if not
180 specified). Implies --list.
181
182 --merged [<commit>]
183 Only list branches whose tips are reachable from the specified
184 commit (HEAD if not specified). Implies --list.
185
186 --no-merged [<commit>]
187 Only list branches whose tips are not reachable from the specified
188 commit (HEAD if not specified). Implies --list.
189
190 <branchname>
191 The name of the branch to create or delete. The new branch name
192 must pass all checks defined by git-check-ref-format(1). Some of
193 these checks may restrict the characters allowed in a branch name.
194
195 <start-point>
196 The new branch head will point to this commit. It may be given as a
197 branch name, a commit-id, or a tag. If this option is omitted, the
198 current HEAD will be used instead.
199
200 <oldbranch>
201 The name of an existing branch to rename.
202
203 <newbranch>
204 The new name for an existing branch. The same restrictions as for
205 <branchname> apply.
206
208 Start development from a known tag
209
210 $ git clone git://git.kernel.org/pub/scm/.../linux-2.6 my2.6
211 $ cd my2.6
212 $ git branch my2.6.14 v2.6.14 [1m(1)
213 $ git checkout my2.6.14
214
215 1. This step and the next one could be combined into a single step
216 with "checkout -b my2.6.14 v2.6.14".
217
218 Delete an unneeded branch
219
220 $ git clone git://git.kernel.org/.../git.git my.git
221 $ cd my.git
222 $ git branch -d -r origin/todo origin/html origin/man [1m(1)
223 $ git branch -D test [1m(2)
224
225 1. Delete the remote-tracking branches "todo", "html" and "man".
226 The next fetch or pull will create them again unless you configure
227 them not to. See git-fetch(1).
228 2. Delete the "test" branch even if the "master" branch (or
229 whichever branch is currently checked out) does not have all
230 commits from the test branch.
231
233 If you are creating a branch that you want to checkout immediately, it
234 is easier to use the git checkout command with its -b option to create
235 a branch and check it out with a single command.
236
237 The options --contains, --merged and --no-merged serve three related
238 but different purposes:
239
240 · --contains <commit> is used to find all branches which will need
241 special attention if <commit> were to be rebased or amended, since
242 those branches contain the specified <commit>.
243
244 · --merged is used to find all branches which can be safely deleted,
245 since those branches are fully contained by HEAD.
246
247 · --no-merged is used to find branches which are candidates for
248 merging into HEAD, since those branches are not fully contained by
249 HEAD.
250
252 git-check-ref-format(1), git-fetch(1), git-remote(1), “Understanding
253 history: What is a branch?”[1] in the Git User’s Manual.
254
256 Part of the git(1) suite
257
259 1. “Understanding history: What is a branch?”
260 file:///usr/share/doc/git-1.8.3.1/user-manual.html#what-is-a-branch
261
262
263
264Git 1.8.3.1 11/19/2018 GIT-BRANCH(1)