updated git doc
[TortoiseGit.git] / doc / source / en / TortoiseGit / git_doc / git-branch.xml
blobd097d69894db2f65f922270f4dc1a96cc5bf7c76
1 <?xml version="1.0" encoding="UTF-8"?>\r
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">\r
3 \r
4 <article lang="en" id="git-branch(1)">\r
5 <articleinfo>\r
6     <title>git-branch(1)</title>\r
7 <indexterm>\r
8 <primary>git-branch(1)</primary>\r
9 </indexterm>\r
10 </articleinfo>\r
11 <simplesect id="_name">\r
12 <title>NAME</title>\r
13 <simpara>git-branch - List, create, or delete branches</simpara>\r
14 </simplesect>\r
15 <simplesect id="_synopsis">\r
16 <title>SYNOPSIS</title>\r
17 <blockquote>\r
18 <literallayout><emphasis>git branch</emphasis> [--color[=&lt;when&gt;] | --no-color] [-r | -a]\r
19         [--list] [-v [--abbrev=&lt;length&gt; | --no-abbrev]]\r
20         [(--merged | --no-merged | --contains) [&lt;commit&gt;]] [&lt;pattern&gt;&#8230;]\r
21 <emphasis>git branch</emphasis> [--set-upstream | --track | --no-track] [-l] [-f] &lt;branchname&gt; [&lt;start-point&gt;]\r
22 <emphasis>git branch</emphasis> (-m | -M) [&lt;oldbranch&gt;] &lt;newbranch&gt;\r
23 <emphasis>git branch</emphasis> (-d | -D) [-r] &lt;branchname&gt;&#8230;\r
24 <emphasis>git branch</emphasis> --edit-description [&lt;branchname&gt;]</literallayout>\r
25 </blockquote>\r
26 </simplesect>\r
27 <simplesect id="_description">\r
28 <title>DESCRIPTION</title>\r
29 <simpara>With no arguments, existing branches are listed and the current branch will\r
30 be highlighted with an asterisk.  Option <emphasis>-r</emphasis> causes the remote-tracking\r
31 branches to be listed, and option <emphasis>-a</emphasis> shows both. This list mode is also\r
32 activated by the <emphasis>--list</emphasis> option (see below).\r
33 &lt;pattern&gt; restricts the output to matching branches, the pattern is a shell\r
34 wildcard (i.e., matched using fnmatch(3)).\r
35 Multiple patterns may be given; if any of them matches, the branch is shown.</simpara>\r
36 <simpara>With <emphasis>--contains</emphasis>, shows only the branches that contain the named commit\r
37 (in other words, the branches whose tip commits are descendants of the\r
38 named commit).  With <emphasis>--merged</emphasis>, only branches merged into the named\r
39 commit (i.e. the branches whose tip commits are reachable from the named\r
40 commit) will be listed.  With <emphasis>--no-merged</emphasis> only branches not merged into\r
41 the named commit will be listed.  If the &lt;commit&gt; argument is missing it\r
42 defaults to <emphasis>HEAD</emphasis> (i.e. the tip of the current branch).</simpara>\r
43 <simpara>The command's second form creates a new branch head named &lt;branchname&gt;\r
44 which points to the current <emphasis>HEAD</emphasis>, or &lt;start-point&gt; if given.</simpara>\r
45 <simpara>Note that this will create the new branch, but it will not switch the\r
46 working tree to it; use "git checkout &lt;newbranch&gt;" to switch to the\r
47 new branch.</simpara>\r
48 <simpara>When a local branch is started off a remote-tracking branch, git sets up the\r
49 branch so that <emphasis>git pull</emphasis> will appropriately merge from\r
50 the remote-tracking branch. This behavior may be changed via the global\r
51 <emphasis>branch.autosetupmerge</emphasis> configuration flag. That setting can be\r
52 overridden by using the <emphasis>--track</emphasis> and <emphasis>--no-track</emphasis> options, and\r
53 changed later using <emphasis>git branch --set-upstream</emphasis>.</simpara>\r
54 <simpara>With a <emphasis>-m</emphasis> or <emphasis>-M</emphasis> option, &lt;oldbranch&gt; will be renamed to &lt;newbranch&gt;.\r
55 If &lt;oldbranch&gt; had a corresponding reflog, it is renamed to match\r
56 &lt;newbranch&gt;, and a reflog entry is created to remember the branch\r
57 renaming. If &lt;newbranch&gt; exists, -M must be used to force the rename\r
58 to happen.</simpara>\r
59 <simpara>With a <emphasis>-d</emphasis> or <emphasis>-D</emphasis> option, <emphasis>&lt;branchname&gt;</emphasis> will be deleted.  You may\r
60 specify more than one branch for deletion.  If the branch currently\r
61 has a reflog then the reflog will also be deleted.</simpara>\r
62 <simpara>Use <emphasis>-r</emphasis> together with <emphasis>-d</emphasis> to delete remote-tracking branches. Note, that it\r
63 only makes sense to delete remote-tracking branches if they no longer exist\r
64 in the remote repository or if <emphasis>git fetch</emphasis> was configured not to fetch\r
65 them again. See also the <emphasis>prune</emphasis> subcommand of <xref linkend="git-remote(1)" /> for a\r
66 way to clean up all obsolete remote-tracking branches.</simpara>\r
67 </simplesect>\r
68 <simplesect id="_options">\r
69 <title>OPTIONS</title>\r
70 <variablelist>\r
71 <varlistentry>\r
72 <term>\r
73 -d\r
74 </term>\r
75 <term>\r
76 --delete\r
77 </term>\r
78 <listitem>\r
79 <simpara>\r
80         Delete a branch. The branch must be fully merged in its\r
81         upstream branch, or in <emphasis>HEAD</emphasis> if no upstream was set with\r
82         <emphasis>--track</emphasis> or <emphasis>--set-upstream</emphasis>.\r
83 </simpara>\r
84 </listitem>\r
85 </varlistentry>\r
86 <varlistentry>\r
87 <term>\r
88 -D\r
89 </term>\r
90 <listitem>\r
91 <simpara>\r
92         Delete a branch irrespective of its merged status.\r
93 </simpara>\r
94 </listitem>\r
95 </varlistentry>\r
96 <varlistentry>\r
97 <term>\r
98 -l\r
99 </term>\r
100 <term>\r
101 --create-reflog\r
102 </term>\r
103 <listitem>\r
104 <simpara>\r
105         Create the branch's reflog.  This activates recording of\r
106         all changes made to the branch ref, enabling use of date\r
107         based sha1 expressions such as "&lt;branchname&gt;@{yesterday}".\r
108         Note that in non-bare repositories, reflogs are usually\r
109         enabled by default by the <emphasis>core.logallrefupdates</emphasis> config option.\r
110 </simpara>\r
111 </listitem>\r
112 </varlistentry>\r
113 <varlistentry>\r
114 <term>\r
115 -f\r
116 </term>\r
117 <term>\r
118 --force\r
119 </term>\r
120 <listitem>\r
121 <simpara>\r
122         Reset &lt;branchname&gt; to &lt;startpoint&gt; if &lt;branchname&gt; exists\r
123         already. Without <emphasis>-f</emphasis> <emphasis>git branch</emphasis> refuses to change an existing branch.\r
124 </simpara>\r
125 </listitem>\r
126 </varlistentry>\r
127 <varlistentry>\r
128 <term>\r
129 -m\r
130 </term>\r
131 <term>\r
132 --move\r
133 </term>\r
134 <listitem>\r
135 <simpara>\r
136         Move/rename a branch and the corresponding reflog.\r
137 </simpara>\r
138 </listitem>\r
139 </varlistentry>\r
140 <varlistentry>\r
141 <term>\r
142 -M\r
143 </term>\r
144 <listitem>\r
145 <simpara>\r
146         Move/rename a branch even if the new branch name already exists.\r
147 </simpara>\r
148 </listitem>\r
149 </varlistentry>\r
150 <varlistentry>\r
151 <term>\r
152 --color[=&lt;when&gt;]\r
153 </term>\r
154 <listitem>\r
155 <simpara>\r
156         Color branches to highlight current, local, and\r
157         remote-tracking branches.\r
158         The value must be always (the default), never, or auto.\r
159 </simpara>\r
160 </listitem>\r
161 </varlistentry>\r
162 <varlistentry>\r
163 <term>\r
164 --no-color\r
165 </term>\r
166 <listitem>\r
167 <simpara>\r
168         Turn off branch colors, even when the configuration file gives the\r
169         default to color output.\r
170         Same as <emphasis>--color=never</emphasis>.\r
171 </simpara>\r
172 </listitem>\r
173 </varlistentry>\r
174 <varlistentry>\r
175 <term>\r
176 -r\r
177 </term>\r
178 <term>\r
179 --remotes\r
180 </term>\r
181 <listitem>\r
182 <simpara>\r
183         List or delete (if used with -d) the remote-tracking branches.\r
184 </simpara>\r
185 </listitem>\r
186 </varlistentry>\r
187 <varlistentry>\r
188 <term>\r
189 -a\r
190 </term>\r
191 <term>\r
192 --all\r
193 </term>\r
194 <listitem>\r
195 <simpara>\r
196         List both remote-tracking branches and local branches.\r
197 </simpara>\r
198 </listitem>\r
199 </varlistentry>\r
200 <varlistentry>\r
201 <term>\r
202 --list\r
203 </term>\r
204 <listitem>\r
205 <simpara>\r
206         Activate the list mode. <emphasis>git branch &lt;pattern&gt;</emphasis> would try to create a branch,\r
207         use <emphasis>git branch --list &lt;pattern&gt;</emphasis> to list matching branches.\r
208 </simpara>\r
209 </listitem>\r
210 </varlistentry>\r
211 <varlistentry>\r
212 <term>\r
213 -v\r
214 </term>\r
215 <term>\r
216 --verbose\r
217 </term>\r
218 <listitem>\r
219 <simpara>\r
220         When in list mode,\r
221         show sha1 and commit subject line for each head, along with\r
222         relationship to upstream branch (if any). If given twice, print\r
223         the name of the upstream branch, as well.\r
224 </simpara>\r
225 </listitem>\r
226 </varlistentry>\r
227 <varlistentry>\r
228 <term>\r
229 --abbrev=&lt;length&gt;\r
230 </term>\r
231 <listitem>\r
232 <simpara>\r
233         Alter the sha1's minimum display length in the output listing.\r
234         The default value is 7 and can be overridden by the <emphasis>core.abbrev</emphasis>\r
235         config option.\r
236 </simpara>\r
237 </listitem>\r
238 </varlistentry>\r
239 <varlistentry>\r
240 <term>\r
241 --no-abbrev\r
242 </term>\r
243 <listitem>\r
244 <simpara>\r
245         Display the full sha1s in the output listing rather than abbreviating them.\r
246 </simpara>\r
247 </listitem>\r
248 </varlistentry>\r
249 <varlistentry>\r
250 <term>\r
251 -t\r
252 </term>\r
253 <term>\r
254 --track\r
255 </term>\r
256 <listitem>\r
257 <simpara>\r
258         When creating a new branch, set up configuration to mark the\r
259         start-point branch as "upstream" from the new branch. This\r
260         configuration will tell git to show the relationship between the\r
261         two branches in <emphasis>git status</emphasis> and <emphasis>git branch -v</emphasis>. Furthermore,\r
262         it directs <emphasis>git pull</emphasis> without arguments to pull from the\r
263         upstream when the new branch is checked out.\r
264 </simpara>\r
265 <simpara>This behavior is the default when the start point is a remote-tracking branch.\r
266 Set the branch.autosetupmerge configuration variable to <emphasis>false</emphasis> if you\r
267 want <emphasis>git checkout</emphasis> and <emphasis>git branch</emphasis> to always behave as if <emphasis>--no-track</emphasis>\r
268 were given. Set it to <emphasis>always</emphasis> if you want this behavior when the\r
269 start-point is either a local or remote-tracking branch.</simpara>\r
270 </listitem>\r
271 </varlistentry>\r
272 <varlistentry>\r
273 <term>\r
274 --no-track\r
275 </term>\r
276 <listitem>\r
277 <simpara>\r
278         Do not set up "upstream" configuration, even if the\r
279         branch.autosetupmerge configuration variable is true.\r
280 </simpara>\r
281 </listitem>\r
282 </varlistentry>\r
283 <varlistentry>\r
284 <term>\r
285 --set-upstream\r
286 </term>\r
287 <listitem>\r
288 <simpara>\r
289         If specified branch does not exist yet or if <emphasis>--force</emphasis> has been\r
290         given, acts exactly like <emphasis>--track</emphasis>. Otherwise sets up configuration\r
291         like <emphasis>--track</emphasis> would when creating the branch, except that where\r
292         branch points to is not changed.\r
293 </simpara>\r
294 </listitem>\r
295 </varlistentry>\r
296 <varlistentry>\r
297 <term>\r
298 --edit-description\r
299 </term>\r
300 <listitem>\r
301 <simpara>\r
302         Open an editor and edit the text to explain what the branch is\r
303         for, to be used by various other commands (e.g. <emphasis>request-pull</emphasis>).\r
304 </simpara>\r
305 </listitem>\r
306 </varlistentry>\r
307 <varlistentry>\r
308 <term>\r
309 --contains [&lt;commit&gt;]\r
310 </term>\r
311 <listitem>\r
312 <simpara>\r
313         Only list branches which contain the specified commit (HEAD\r
314         if not specified).\r
315 </simpara>\r
316 </listitem>\r
317 </varlistentry>\r
318 <varlistentry>\r
319 <term>\r
320 --merged [&lt;commit&gt;]\r
321 </term>\r
322 <listitem>\r
323 <simpara>\r
324         Only list branches whose tips are reachable from the\r
325         specified commit (HEAD if not specified).\r
326 </simpara>\r
327 </listitem>\r
328 </varlistentry>\r
329 <varlistentry>\r
330 <term>\r
331 --no-merged [&lt;commit&gt;]\r
332 </term>\r
333 <listitem>\r
334 <simpara>\r
335         Only list branches whose tips are not reachable from the\r
336         specified commit (HEAD if not specified).\r
337 </simpara>\r
338 </listitem>\r
339 </varlistentry>\r
340 <varlistentry>\r
341 <term>\r
342 &lt;branchname&gt;\r
343 </term>\r
344 <listitem>\r
345 <simpara>\r
346         The name of the branch to create or delete.\r
347         The new branch name must pass all checks defined by\r
348         <xref linkend="git-check-ref-format(1)" />.  Some of these checks\r
349         may restrict the characters allowed in a branch name.\r
350 </simpara>\r
351 </listitem>\r
352 </varlistentry>\r
353 <varlistentry>\r
354 <term>\r
355 &lt;start-point&gt;\r
356 </term>\r
357 <listitem>\r
358 <simpara>\r
359         The new branch head will point to this commit.  It may be\r
360         given as a branch name, a commit-id, or a tag.  If this\r
361         option is omitted, the current HEAD will be used instead.\r
362 </simpara>\r
363 </listitem>\r
364 </varlistentry>\r
365 <varlistentry>\r
366 <term>\r
367 &lt;oldbranch&gt;\r
368 </term>\r
369 <listitem>\r
370 <simpara>\r
371         The name of an existing branch to rename.\r
372 </simpara>\r
373 </listitem>\r
374 </varlistentry>\r
375 <varlistentry>\r
376 <term>\r
377 &lt;newbranch&gt;\r
378 </term>\r
379 <listitem>\r
380 <simpara>\r
381         The new name for an existing branch. The same restrictions as for\r
382         &lt;branchname&gt; apply.\r
383 </simpara>\r
384 </listitem>\r
385 </varlistentry>\r
386 </variablelist>\r
387 </simplesect>\r
388 <simplesect id="_examples">\r
389 <title>Examples</title>\r
390 <variablelist>\r
391 <varlistentry>\r
392 <term>\r
393 Start development from a known tag\r
394 </term>\r
395 <listitem>\r
396 <screen>$ git clone git://git.kernel.org/pub/scm/.../linux-2.6 my2.6\r
397 $ cd my2.6\r
398 $ git branch my2.6.14 v2.6.14   <co id="CO1-1"/>\r
399 $ git checkout my2.6.14</screen>\r
400 <calloutlist>\r
401 <callout arearefs="CO1-1">\r
402 <para>\r
403 This step and the next one could be combined into a single step with\r
404 "checkout -b my2.6.14 v2.6.14".\r
405 </para>\r
406 </callout>\r
407 </calloutlist>\r
408 </listitem>\r
409 </varlistentry>\r
410 <varlistentry>\r
411 <term>\r
412 Delete an unneeded branch\r
413 </term>\r
414 <listitem>\r
415 <screen>$ git clone git://git.kernel.org/.../git.git my.git\r
416 $ cd my.git\r
417 $ git branch -d -r origin/todo origin/html origin/man   <co id="CO2-1"/>\r
418 $ git branch -D test                                    <co id="CO2-2"/></screen>\r
419 <calloutlist>\r
420 <callout arearefs="CO2-1">\r
421 <para>\r
422 Delete the remote-tracking branches "todo", "html" and "man". The next\r
423 <emphasis>fetch</emphasis> or <emphasis>pull</emphasis> will create them again unless you configure them not to.\r
424 See <xref linkend="git-fetch(1)" />.\r
425 </para>\r
426 </callout>\r
427 <callout arearefs="CO2-2">\r
428 <para>\r
429 Delete the "test" branch even if the "master" branch (or whichever branch\r
430 is currently checked out) does not have all commits from the test branch.\r
431 </para>\r
432 </callout>\r
433 </calloutlist>\r
434 </listitem>\r
435 </varlistentry>\r
436 </variablelist>\r
437 </simplesect>\r
438 <simplesect id="_notes">\r
439 <title>Notes</title>\r
440 <simpara>If you are creating a branch that you want to checkout immediately, it is\r
441 easier to use the git checkout command with its <emphasis>-b</emphasis> option to create\r
442 a branch and check it out with a single command.</simpara>\r
443 <simpara>The options <emphasis>--contains</emphasis>, <emphasis>--merged</emphasis> and <emphasis>--no-merged</emphasis> serve three related\r
444 but different purposes:</simpara>\r
445 <itemizedlist>\r
446 <listitem>\r
447 <simpara>\r
448 <emphasis>--contains &lt;commit&gt;</emphasis> is used to find all branches which will need\r
449   special attention if &lt;commit&gt; were to be rebased or amended, since those\r
450   branches contain the specified &lt;commit&gt;.\r
451 </simpara>\r
452 </listitem>\r
453 <listitem>\r
454 <simpara>\r
455 <emphasis>--merged</emphasis> is used to find all branches which can be safely deleted,\r
456   since those branches are fully contained by HEAD.\r
457 </simpara>\r
458 </listitem>\r
459 <listitem>\r
460 <simpara>\r
461 <emphasis>--no-merged</emphasis> is used to find branches which are candidates for merging\r
462   into HEAD, since those branches are not fully contained by HEAD.\r
463 </simpara>\r
464 </listitem>\r
465 </itemizedlist>\r
466 </simplesect>\r
467 <simplesect id="_see_also">\r
468 <title>SEE ALSO</title>\r
469 <simpara><xref linkend="git-check-ref-format(1)" />,\r
470 <xref linkend="git-fetch(1)" />,\r
471 <xref linkend="git-remote(1)" />,\r
472 <link linkend="what-is-a-branch">Understanding history: What is\r
473 a branch?</link> in the Git User's Manual.</simpara>\r
474 </simplesect>\r
475 <simplesect id="_git">\r
476 <title>GIT</title>\r
477 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>\r
478 </simplesect>\r
479 </article>\r