blob: 2fb2e4883c8dc4b2c544af47ee62462ed78e3393 [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
2 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Junio C Hamano7bd050f2011-09-22 06:32:226<meta name="generator" content="AsciiDoc 8.5.2" />
Junio C Hamano97bcb482010-11-25 03:16:077<title>git-checkout(1)</title>
Junio C Hamano1a4e8412005-12-27 08:17:238<style type="text/css">
9/* Debug borders */
10p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
11/*
12 border: 1px solid red;
13*/
14}
15
16body {
17 margin: 1em 5% 1em 5%;
18}
19
Junio C Hamanoba4b9282008-07-06 05:20:3120a {
21 color: blue;
22 text-decoration: underline;
23}
24a:visited {
25 color: fuchsia;
26}
Junio C Hamano1a4e8412005-12-27 08:17:2327
28em {
29 font-style: italic;
Junio C Hamano97bcb482010-11-25 03:16:0730 color: navy;
Junio C Hamano1a4e8412005-12-27 08:17:2331}
32
33strong {
34 font-weight: bold;
Junio C Hamano97bcb482010-11-25 03:16:0735 color: #083194;
Junio C Hamano1a4e8412005-12-27 08:17:2336}
37
38tt {
39 color: navy;
40}
41
42h1, h2, h3, h4, h5, h6 {
43 color: #527bbd;
44 font-family: sans-serif;
45 margin-top: 1.2em;
46 margin-bottom: 0.5em;
47 line-height: 1.3;
48}
49
Junio C Hamanoba4b9282008-07-06 05:20:3150h1, h2, h3 {
Junio C Hamano1a4e8412005-12-27 08:17:2351 border-bottom: 2px solid silver;
52}
53h2 {
Junio C Hamano1a4e8412005-12-27 08:17:2354 padding-top: 0.5em;
55}
Junio C Hamanoba4b9282008-07-06 05:20:3156h3 {
57 float: left;
58}
59h3 + * {
60 clear: left;
61}
Junio C Hamano1a4e8412005-12-27 08:17:2362
63div.sectionbody {
64 font-family: serif;
65 margin-left: 0;
66}
67
68hr {
69 border: 1px solid silver;
70}
71
72p {
73 margin-top: 0.5em;
74 margin-bottom: 0.5em;
75}
76
Junio C Hamano97bcb482010-11-25 03:16:0777ul, ol, li > p {
78 margin-top: 0;
79}
80
Junio C Hamano1a4e8412005-12-27 08:17:2381pre {
82 padding: 0;
83 margin: 0;
84}
85
86span#author {
87 color: #527bbd;
88 font-family: sans-serif;
89 font-weight: bold;
Junio C Hamanoba4b9282008-07-06 05:20:3190 font-size: 1.1em;
Junio C Hamano1a4e8412005-12-27 08:17:2391}
92span#email {
93}
Junio C Hamano97bcb482010-11-25 03:16:0794span#revnumber, span#revdate, span#revremark {
Junio C Hamano1a4e8412005-12-27 08:17:2395 font-family: sans-serif;
96}
97
98div#footer {
99 font-family: sans-serif;
100 font-size: small;
101 border-top: 2px solid silver;
102 padding-top: 0.5em;
103 margin-top: 4.0em;
104}
105div#footer-text {
106 float: left;
107 padding-bottom: 0.5em;
108}
109div#footer-badges {
110 float: right;
111 padding-bottom: 0.5em;
112}
113
Junio C Hamano97bcb482010-11-25 03:16:07114div#preamble {
115 margin-top: 1.5em;
116 margin-bottom: 1.5em;
117}
Junio C Hamano1a4e8412005-12-27 08:17:23118div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
119div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
120div.admonitionblock {
Junio C Hamano7bd050f2011-09-22 06:32:22121 margin-top: 1.0em;
Junio C Hamano1a4e8412005-12-27 08:17:23122 margin-bottom: 1.5em;
123}
124div.admonitionblock {
Junio C Hamano7bd050f2011-09-22 06:32:22125 margin-top: 2.0em;
126 margin-bottom: 2.0em;
127 margin-right: 10%;
128 color: #606060;
Junio C Hamano1a4e8412005-12-27 08:17:23129}
130
131div.content { /* Block element content. */
132 padding: 0;
133}
134
135/* Block element titles. */
136div.title, caption.title {
Junio C Hamano97bcb482010-11-25 03:16:07137 color: #527bbd;
Junio C Hamano1a4e8412005-12-27 08:17:23138 font-family: sans-serif;
139 font-weight: bold;
140 text-align: left;
141 margin-top: 1.0em;
142 margin-bottom: 0.5em;
143}
144div.title + * {
145 margin-top: 0;
146}
147
148td div.title:first-child {
149 margin-top: 0.0em;
150}
151div.content div.title:first-child {
152 margin-top: 0.0em;
153}
154div.content + div.title {
155 margin-top: 0.0em;
156}
157
158div.sidebarblock > div.content {
159 background: #ffffee;
160 border: 1px solid silver;
161 padding: 0.5em;
162}
163
164div.listingblock > div.content {
165 border: 1px solid silver;
166 background: #f4f4f4;
167 padding: 0.5em;
168}
169
Junio C Hamano7bd050f2011-09-22 06:32:22170div.quoteblock, div.verseblock {
171 padding-left: 1.0em;
172 margin-left: 1.0em;
Junio C Hamano97bcb482010-11-25 03:16:07173 margin-right: 10%;
Junio C Hamano7bd050f2011-09-22 06:32:22174 border-left: 5px solid #dddddd;
175 color: #777777;
Junio C Hamano1a4e8412005-12-27 08:17:23176}
Junio C Hamano7bd050f2011-09-22 06:32:22177
Junio C Hamano97bcb482010-11-25 03:16:07178div.quoteblock > div.attribution {
179 padding-top: 0.5em;
Junio C Hamano1a4e8412005-12-27 08:17:23180 text-align: right;
181}
Junio C Hamano97bcb482010-11-25 03:16:07182
Junio C Hamano97bcb482010-11-25 03:16:07183div.verseblock > div.content {
184 white-space: pre;
185}
186div.verseblock > div.attribution {
187 padding-top: 0.75em;
188 text-align: left;
189}
190/* DEPRECATED: Pre version 8.2.7 verse style literal block. */
Junio C Hamanoba4b9282008-07-06 05:20:31191div.verseblock + div.attribution {
192 text-align: left;
193}
Junio C Hamano1a4e8412005-12-27 08:17:23194
195div.admonitionblock .icon {
196 vertical-align: top;
197 font-size: 1.1em;
198 font-weight: bold;
199 text-decoration: underline;
200 color: #527bbd;
201 padding-right: 0.5em;
202}
203div.admonitionblock td.content {
204 padding-left: 0.5em;
Junio C Hamano7bd050f2011-09-22 06:32:22205 border-left: 3px solid #dddddd;
Junio C Hamano1a4e8412005-12-27 08:17:23206}
207
208div.exampleblock > div.content {
Junio C Hamano7bd050f2011-09-22 06:32:22209 border-left: 3px solid #dddddd;
210 padding-left: 0.5em;
Junio C Hamano1a4e8412005-12-27 08:17:23211}
212
Junio C Hamano1a4e8412005-12-27 08:17:23213div.imageblock div.content { padding-left: 0; }
Junio C Hamano1a4e8412005-12-27 08:17:23214span.image img { border-style: none; }
Junio C Hamano97bcb482010-11-25 03:16:07215a.image:visited { color: white; }
Junio C Hamano1a4e8412005-12-27 08:17:23216
217dl {
218 margin-top: 0.8em;
219 margin-bottom: 0.8em;
220}
221dt {
222 margin-top: 0.5em;
223 margin-bottom: 0;
Junio C Hamano97bcb482010-11-25 03:16:07224 font-style: normal;
225 color: navy;
Junio C Hamano1a4e8412005-12-27 08:17:23226}
227dd > *:first-child {
Junio C Hamano97bcb482010-11-25 03:16:07228 margin-top: 0.1em;
Junio C Hamano1a4e8412005-12-27 08:17:23229}
230
231ul, ol {
232 list-style-position: outside;
233}
Junio C Hamano97bcb482010-11-25 03:16:07234ol.arabic {
235 list-style-type: decimal;
236}
237ol.loweralpha {
Junio C Hamano1a4e8412005-12-27 08:17:23238 list-style-type: lower-alpha;
239}
Junio C Hamano97bcb482010-11-25 03:16:07240ol.upperalpha {
241 list-style-type: upper-alpha;
242}
243ol.lowerroman {
244 list-style-type: lower-roman;
245}
246ol.upperroman {
247 list-style-type: upper-roman;
248}
249
250div.compact ul, div.compact ol,
251div.compact p, div.compact p,
252div.compact div, div.compact div {
253 margin-top: 0.1em;
254 margin-bottom: 0.1em;
255}
Junio C Hamano1a4e8412005-12-27 08:17:23256
257div.tableblock > table {
Junio C Hamanoba4b9282008-07-06 05:20:31258 border: 3px solid #527bbd;
Junio C Hamano1a4e8412005-12-27 08:17:23259}
Junio C Hamano7bd050f2011-09-22 06:32:22260thead, p.table.header {
Junio C Hamano1a4e8412005-12-27 08:17:23261 font-family: sans-serif;
262 font-weight: bold;
263}
264tfoot {
265 font-weight: bold;
266}
Junio C Hamano97bcb482010-11-25 03:16:07267td > div.verse {
268 white-space: pre;
269}
270p.table {
271 margin-top: 0;
272}
273/* Because the table frame attribute is overriden by CSS in most browsers. */
274div.tableblock > table[frame="void"] {
275 border-style: none;
276}
277div.tableblock > table[frame="hsides"] {
278 border-left-style: none;
279 border-right-style: none;
280}
281div.tableblock > table[frame="vsides"] {
282 border-top-style: none;
283 border-bottom-style: none;
284}
Junio C Hamano1a4e8412005-12-27 08:17:23285
Junio C Hamano97bcb482010-11-25 03:16:07286
287div.hdlist {
Junio C Hamano1a4e8412005-12-27 08:17:23288 margin-top: 0.8em;
289 margin-bottom: 0.8em;
290}
Junio C Hamano97bcb482010-11-25 03:16:07291div.hdlist tr {
292 padding-bottom: 15px;
Junio C Hamanoba4b9282008-07-06 05:20:31293}
Junio C Hamano97bcb482010-11-25 03:16:07294dt.hdlist1.strong, td.hdlist1.strong {
295 font-weight: bold;
296}
297td.hdlist1 {
Junio C Hamano1a4e8412005-12-27 08:17:23298 vertical-align: top;
Junio C Hamano97bcb482010-11-25 03:16:07299 font-style: normal;
Junio C Hamano1a4e8412005-12-27 08:17:23300 padding-right: 0.8em;
Junio C Hamano97bcb482010-11-25 03:16:07301 color: navy;
Junio C Hamano1a4e8412005-12-27 08:17:23302}
Junio C Hamano97bcb482010-11-25 03:16:07303td.hdlist2 {
Junio C Hamano1a4e8412005-12-27 08:17:23304 vertical-align: top;
305}
Junio C Hamano97bcb482010-11-25 03:16:07306div.hdlist.compact tr {
307 margin: 0;
308 padding-bottom: 0;
309}
310
311.comment {
312 background: yellow;
313}
Junio C Hamano1a4e8412005-12-27 08:17:23314
Junio C Hamano7bd050f2011-09-22 06:32:22315.footnote, .footnoteref {
316 font-size: 0.8em;
317}
318
319span.footnote, span.footnoteref {
320 vertical-align: super;
321}
322
323#footnotes {
324 margin: 20px 0 20px 0;
325 padding: 7px 0 0 0;
326}
327
328#footnotes div.footnote {
329 margin: 0 0 5px 0;
330}
331
332#footnotes hr {
333 border: none;
334 border-top: 1px solid silver;
335 height: 1px;
336 text-align: left;
337 margin-left: 0;
338 width: 20%;
339 min-width: 100px;
340}
341
342
Junio C Hamano1a4e8412005-12-27 08:17:23343@media print {
344 div#footer-badges { display: none; }
345}
Junio C Hamanoba4b9282008-07-06 05:20:31346
Junio C Hamano7bd050f2011-09-22 06:32:22347div#toc {
348 margin-bottom: 2.5em;
349}
350
Junio C Hamanoba4b9282008-07-06 05:20:31351div#toctitle {
352 color: #527bbd;
353 font-family: sans-serif;
354 font-size: 1.1em;
355 font-weight: bold;
356 margin-top: 1.0em;
357 margin-bottom: 0.1em;
358}
359
360div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
361 margin-top: 0;
362 margin-bottom: 0;
363}
364div.toclevel2 {
365 margin-left: 2em;
366 font-size: 0.9em;
367}
368div.toclevel3 {
369 margin-left: 4em;
370 font-size: 0.9em;
371}
372div.toclevel4 {
373 margin-left: 6em;
374 font-size: 0.9em;
375}
Junio C Hamano97bcb482010-11-25 03:16:07376/* Overrides for manpage documents */
377h1 {
378 padding-top: 0.5em;
379 padding-bottom: 0.5em;
380 border-top: 2px solid silver;
381 border-bottom: 2px solid silver;
382}
383h2 {
384 border-style: none;
385}
386div.sectionbody {
387 margin-left: 5%;
388}
389
390@media print {
391 div#toc { display: none; }
392}
393
Junio C Hamano1a4e8412005-12-27 08:17:23394/* Workarounds for IE6's broken and incomplete CSS2. */
395
396div.sidebar-content {
397 background: #ffffee;
398 border: 1px solid silver;
399 padding: 0.5em;
400}
401div.sidebar-title, div.image-title {
Junio C Hamano97bcb482010-11-25 03:16:07402 color: #527bbd;
Junio C Hamano1a4e8412005-12-27 08:17:23403 font-family: sans-serif;
404 font-weight: bold;
405 margin-top: 0.0em;
406 margin-bottom: 0.5em;
407}
408
409div.listingblock div.content {
410 border: 1px solid silver;
411 background: #f4f4f4;
412 padding: 0.5em;
413}
414
Junio C Hamano97bcb482010-11-25 03:16:07415div.quoteblock-attribution {
416 padding-top: 0.5em;
417 text-align: right;
418}
419
420div.verseblock-content {
421 white-space: pre;
422}
423div.verseblock-attribution {
424 padding-top: 0.75em;
425 text-align: left;
Junio C Hamano1a4e8412005-12-27 08:17:23426}
427
428div.exampleblock-content {
Junio C Hamano7bd050f2011-09-22 06:32:22429 border-left: 3px solid #dddddd;
Junio C Hamano1a4e8412005-12-27 08:17:23430 padding-left: 0.5em;
431}
Junio C Hamanoba4b9282008-07-06 05:20:31432
433/* IE6 sets dynamically generated links as visited. */
434div#toc a:visited { color: blue; }
Junio C Hamano1a4e8412005-12-27 08:17:23435</style>
Junio C Hamano7bd050f2011-09-22 06:32:22436<script type="text/javascript">
437/*<![CDATA[*/
438window.onload = function(){asciidoc.footnotes();}
439var asciidoc = { // Namespace.
440
441/////////////////////////////////////////////////////////////////////
442// Table Of Contents generator
443/////////////////////////////////////////////////////////////////////
444
445/* Author: Mihai Bazon, September 2002
446 * http://students.infoiasi.ro/~mishoo
447 *
448 * Table Of Content generator
449 * Version: 0.4
450 *
451 * Feel free to use this script under the terms of the GNU General Public
452 * License, as long as you do not remove or alter this notice.
453 */
454
455 /* modified by Troy D. Hanson, September 2006. License: GPL */
456 /* modified by Stuart Rackham, 2006, 2009. License: GPL */
457
458// toclevels = 1..4.
459toc: function (toclevels) {
460
461 function getText(el) {
462 var text = "";
463 for (var i = el.firstChild; i != null; i = i.nextSibling) {
464 if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
465 text += i.data;
466 else if (i.firstChild != null)
467 text += getText(i);
468 }
469 return text;
470 }
471
472 function TocEntry(el, text, toclevel) {
473 this.element = el;
474 this.text = text;
475 this.toclevel = toclevel;
476 }
477
478 function tocEntries(el, toclevels) {
479 var result = new Array;
480 var re = new RegExp('[hH]([2-'+(toclevels+1)+'])');
481 // Function that scans the DOM tree for header elements (the DOM2
482 // nodeIterator API would be a better technique but not supported by all
483 // browsers).
484 var iterate = function (el) {
485 for (var i = el.firstChild; i != null; i = i.nextSibling) {
486 if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
487 var mo = re.exec(i.tagName);
488 if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") {
489 result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
490 }
491 iterate(i);
492 }
493 }
494 }
495 iterate(el);
496 return result;
497 }
498
499 var toc = document.getElementById("toc");
500 var entries = tocEntries(document.getElementById("content"), toclevels);
501 for (var i = 0; i < entries.length; ++i) {
502 var entry = entries[i];
503 if (entry.element.id == "")
504 entry.element.id = "_toc_" + i;
505 var a = document.createElement("a");
506 a.href = "#" + entry.element.id;
507 a.appendChild(document.createTextNode(entry.text));
508 var div = document.createElement("div");
509 div.appendChild(a);
510 div.className = "toclevel" + entry.toclevel;
511 toc.appendChild(div);
512 }
513 if (entries.length == 0)
514 toc.parentNode.removeChild(toc);
515},
516
517
518/////////////////////////////////////////////////////////////////////
519// Footnotes generator
520/////////////////////////////////////////////////////////////////////
521
522/* Based on footnote generation code from:
523 * http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
524 */
525
526footnotes: function () {
527 var cont = document.getElementById("content");
528 var noteholder = document.getElementById("footnotes");
529 var spans = cont.getElementsByTagName("span");
530 var refs = {};
531 var n = 0;
532 for (i=0; i<spans.length; i++) {
533 if (spans[i].className == "footnote") {
534 n++;
535 // Use [\s\S] in place of . so multi-line matches work.
536 // Because JavaScript has no s (dotall) regex flag.
537 note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1];
538 noteholder.innerHTML +=
539 "<div class='footnote' id='_footnote_" + n + "'>" +
540 "<a href='#_footnoteref_" + n + "' title='Return to text'>" +
541 n + "</a>. " + note + "</div>";
542 spans[i].innerHTML =
543 "[<a id='_footnoteref_" + n + "' href='#_footnote_" + n +
544 "' title='View footnote' class='footnote'>" + n + "</a>]";
545 var id =spans[i].getAttribute("id");
546 if (id != null) refs["#"+id] = n;
547 }
548 }
549 if (n == 0)
550 noteholder.parentNode.removeChild(noteholder);
551 else {
552 // Process footnoterefs.
553 for (i=0; i<spans.length; i++) {
554 if (spans[i].className == "footnoteref") {
555 var href = spans[i].getElementsByTagName("a")[0].getAttribute("href");
556 href = href.match(/#.*/)[0]; // Because IE return full URL.
557 n = refs[href];
558 spans[i].innerHTML =
559 "[<a href='#_footnote_" + n +
560 "' title='View footnote' class='footnote'>" + n + "</a>]";
561 }
562 }
563 }
564}
565
566}
567/*]]>*/
568</script>
Junio C Hamano1a4e8412005-12-27 08:17:23569</head>
570<body>
571<div id="header">
572<h1>
573git-checkout(1) Manual Page
574</h1>
575<h2>NAME</h2>
576<div class="sectionbody">
577<p>git-checkout -
Junio C Hamanoa14a4032008-03-25 09:11:02578 Checkout a branch or paths to the working tree
Junio C Hamano1a4e8412005-12-27 08:17:23579</p>
580</div>
581</div>
Junio C Hamano7bd050f2011-09-22 06:32:22582<div id="content">
Junio C Hamano97bcb482010-11-25 03:16:07583<h2 id="_synopsis">SYNOPSIS</h2>
Junio C Hamano1a4e8412005-12-27 08:17:23584<div class="sectionbody">
Junio C Hamano2b135272006-03-18 07:45:42585<div class="verseblock">
Junio C Hamano97bcb482010-11-25 03:16:07586<div class="verseblock-content"><em>git checkout</em> [-q] [-f] [-m] [&lt;branch&gt;]
Junio C Hamano63c2bc92011-02-28 06:41:28587<em>git checkout</em> [-q] [-f] [-m] [--detach] [&lt;commit&gt;]
Junio C Hamano619596a2010-08-18 22:15:35588<em>git checkout</em> [-q] [-f] [-m] [[-b|-B|--orphan] &lt;new_branch&gt;] [&lt;start_point&gt;]
Junio C Hamanoc28068f2009-09-08 00:55:23589<em>git checkout</em> [-f|--ours|--theirs|-m|--conflict=&lt;style&gt;] [&lt;tree-ish&gt;] [--] &lt;paths&gt;&#8230;
Junio C Hamano9eb58352011-05-11 20:09:24590<em>git checkout</em> [-p|--patch] [&lt;tree-ish&gt;] [--] [&lt;paths&gt;&#8230;]</div>
Junio C Hamano97bcb482010-11-25 03:16:07591<div class="verseblock-attribution">
592</div></div>
Junio C Hamano1a4e8412005-12-27 08:17:23593</div>
Junio C Hamanoba4b9282008-07-06 05:20:31594<h2 id="_description">DESCRIPTION</h2>
Junio C Hamano1a4e8412005-12-27 08:17:23595<div class="sectionbody">
Junio C Hamano97bcb482010-11-25 03:16:07596<div class="paragraph"><p>Updates files in the working tree to match the version in the index
Junio C Hamanobb88cf42010-06-21 15:23:55597or the specified tree. If no paths are given, <em>git checkout</em> will
598also update <tt>HEAD</tt> to set the specified branch as the current
Junio C Hamano3bd66e92009-04-18 06:17:56599branch.</p></div>
Junio C Hamano97bcb482010-11-25 03:16:07600<div class="dlist"><dl>
601<dt class="hdlist1">
Junio C Hamanobb88cf42010-06-21 15:23:55602<em>git checkout</em> [&lt;branch&gt;]
603</dt>
Junio C Hamano97bcb482010-11-25 03:16:07604<dt class="hdlist1">
Junio C Hamano619596a2010-08-18 22:15:35605<em>git checkout</em> -b|-B &lt;new_branch&gt; [&lt;start point&gt;]
Junio C Hamanobb88cf42010-06-21 15:23:55606</dt>
Junio C Hamano63c2bc92011-02-28 06:41:28607<dt class="hdlist1">
608<em>git checkout</em> [--detach] [&lt;commit&gt;]
609</dt>
Junio C Hamanobb88cf42010-06-21 15:23:55610<dd>
611<p>
612 This form switches branches by updating the index, working
Junio C Hamano63c2bc92011-02-28 06:41:28613 tree, and HEAD to reflect the specified branch or commit.
Junio C Hamanobb88cf42010-06-21 15:23:55614</p>
Junio C Hamano97bcb482010-11-25 03:16:07615<div class="paragraph"><p>If <tt>-b</tt> is given, a new branch is created as if <a href="git-branch.html">git-branch(1)</a>
Junio C Hamanobb88cf42010-06-21 15:23:55616were called and then checked out; in this case you can
617use the <tt>--track</tt> or <tt>--no-track</tt> options, which will be passed to
618<em>git branch</em>. As a convenience, <tt>--track</tt> without <tt>-b</tt> implies branch
619creation; see the description of <tt>--track</tt> below.</p></div>
Junio C Hamano97bcb482010-11-25 03:16:07620<div class="paragraph"><p>If <tt>-B</tt> is given, &lt;new_branch&gt; is created if it doesn&#8217;t exist; otherwise, it
Junio C Hamano619596a2010-08-18 22:15:35621is reset. This is the transactional equivalent of</p></div>
622<div class="listingblock">
623<div class="content">
624<pre><tt>$ git branch -f &lt;branch&gt; [&lt;start point&gt;]
625$ git checkout &lt;branch&gt;</tt></pre>
626</div></div>
Junio C Hamano97bcb482010-11-25 03:16:07627<div class="paragraph"><p>that is to say, the branch is not reset/created unless "git checkout" is
Junio C Hamano619596a2010-08-18 22:15:35628successful.</p></div>
Junio C Hamanobb88cf42010-06-21 15:23:55629</dd>
Junio C Hamano97bcb482010-11-25 03:16:07630<dt class="hdlist1">
Junio C Hamano9eb58352011-05-11 20:09:24631<em>git checkout</em> [-p|--patch] [&lt;tree-ish&gt;] [--] &lt;pathspec&gt;&#8230;
Junio C Hamanobb88cf42010-06-21 15:23:55632</dt>
633<dd>
634<p>
Junio C Hamano442206c2010-09-28 05:51:23635 When &lt;paths&gt; or <tt>--patch</tt> are given, <em>git checkout</em> does <strong>not</strong>
636 switch branches. It updates the named paths in the working tree
637 from the index file or from a named &lt;tree-ish&gt; (most often a
638 commit). In this case, the <tt>-b</tt> and <tt>--track</tt> options are
639 meaningless and giving either of them results in an error. The
640 &lt;tree-ish&gt; argument can be used to specify a specific tree-ish
641 (i.e. commit, tag or tree) to update the index for the given
642 paths before updating the working tree.
Junio C Hamanobb88cf42010-06-21 15:23:55643</p>
Junio C Hamano97bcb482010-11-25 03:16:07644<div class="paragraph"><p>The index may contain unmerged entries because of a previous failed merge.
Junio C Hamanobb88cf42010-06-21 15:23:55645By default, if you try to check out such an entry from the index, the
Junio C Hamanoa476efa2008-10-10 15:31:42646checkout operation will fail and nothing will be checked out.
Junio C Hamanobb88cf42010-06-21 15:23:55647Using <tt>-f</tt> will ignore these unmerged entries. The contents from a
Junio C Hamanoa476efa2008-10-10 15:31:42648specific side of the merge can be checked out of the index by
Junio C Hamanobb88cf42010-06-21 15:23:55649using <tt>--ours</tt> or <tt>--theirs</tt>. With <tt>-m</tt>, changes made to the working tree
650file can be discarded to re-create the original conflicted merge result.</p></div>
651</dd>
652</dl></div>
Junio C Hamano1a4e8412005-12-27 08:17:23653</div>
Junio C Hamanoba4b9282008-07-06 05:20:31654<h2 id="_options">OPTIONS</h2>
Junio C Hamano1a4e8412005-12-27 08:17:23655<div class="sectionbody">
Junio C Hamano97bcb482010-11-25 03:16:07656<div class="dlist"><dl>
657<dt class="hdlist1">
Junio C Hamano39381a72007-02-02 07:35:15658-q
659</dt>
Junio C Hamano97bcb482010-11-25 03:16:07660<dt class="hdlist1">
Junio C Hamano68cfa3a2009-08-30 00:22:55661--quiet
662</dt>
Junio C Hamano39381a72007-02-02 07:35:15663<dd>
664<p>
Junio C Hamanocae86272007-08-21 02:20:49665 Quiet, suppress feedback messages.
Junio C Hamano39381a72007-02-02 07:35:15666</p>
667</dd>
Junio C Hamano97bcb482010-11-25 03:16:07668<dt class="hdlist1">
Junio C Hamano1a4e8412005-12-27 08:17:23669-f
670</dt>
Junio C Hamano97bcb482010-11-25 03:16:07671<dt class="hdlist1">
Junio C Hamano68cfa3a2009-08-30 00:22:55672--force
673</dt>
Junio C Hamano1a4e8412005-12-27 08:17:23674<dd>
675<p>
Junio C Hamanoa476efa2008-10-10 15:31:42676 When switching branches, proceed even if the index or the
677 working tree differs from HEAD. This is used to throw away
678 local changes.
679</p>
Junio C Hamano97bcb482010-11-25 03:16:07680<div class="paragraph"><p>When checking out paths from the index, do not fail upon unmerged
Junio C Hamanoa476efa2008-10-10 15:31:42681entries; instead, unmerged entries are ignored.</p></div>
682</dd>
Junio C Hamano97bcb482010-11-25 03:16:07683<dt class="hdlist1">
Junio C Hamanoa476efa2008-10-10 15:31:42684--ours
685</dt>
Junio C Hamano97bcb482010-11-25 03:16:07686<dt class="hdlist1">
Junio C Hamanoa476efa2008-10-10 15:31:42687--theirs
688</dt>
689<dd>
690<p>
691 When checking out paths from the index, check out stage #2
692 (<em>ours</em>) or #3 (<em>theirs</em>) for unmerged paths.
Junio C Hamano1a4e8412005-12-27 08:17:23693</p>
694</dd>
Junio C Hamano97bcb482010-11-25 03:16:07695<dt class="hdlist1">
Junio C Hamano1a4e8412005-12-27 08:17:23696-b
697</dt>
698<dd>
699<p>
Junio C Hamanob2f5edd2006-05-21 10:50:09700 Create a new branch named &lt;new_branch&gt; and start it at
Junio C Hamano3bd66e92009-04-18 06:17:56701 &lt;start_point&gt;; see <a href="git-branch.html">git-branch(1)</a> for details.
Junio C Hamano1a4e8412005-12-27 08:17:23702</p>
703</dd>
Junio C Hamano97bcb482010-11-25 03:16:07704<dt class="hdlist1">
Junio C Hamano619596a2010-08-18 22:15:35705-B
706</dt>
707<dd>
708<p>
709 Creates the branch &lt;new_branch&gt; and start it at &lt;start_point&gt;;
710 if it already exists, then reset it to &lt;start_point&gt;. This is
711 equivalent to running "git branch" with "-f"; see
712 <a href="git-branch.html">git-branch(1)</a> for details.
713</p>
714</dd>
Junio C Hamano97bcb482010-11-25 03:16:07715<dt class="hdlist1">
Junio C Hamanoeb415992008-06-08 22:49:47716-t
717</dt>
Junio C Hamano97bcb482010-11-25 03:16:07718<dt class="hdlist1">
Junio C Hamanoeb415992008-06-08 22:49:47719--track
Junio C Hamano103ad7f2007-03-14 11:19:26720</dt>
721<dd>
722<p>
Junio C Hamano3bd66e92009-04-18 06:17:56723 When creating a new branch, set up "upstream" configuration. See
724 "--track" in <a href="git-branch.html">git-branch(1)</a> for details.
Junio C Hamano103ad7f2007-03-14 11:19:26725</p>
Junio C Hamano97bcb482010-11-25 03:16:07726<div class="paragraph"><p>If no <em>-b</em> option is given, the name of the new branch will be
727derived from the remote-tracking branch. If "remotes/" or "refs/remotes/"
Junio C Hamano57053932009-03-11 08:48:32728is prefixed it is stripped away, and then the part up to the
Junio C Hamano043628e2008-08-24 03:34:11729next slash (which would be the nickname of the remote) is removed.
730This would tell us to use "hack" as the local branch when branching
731off of "origin/hack" (or "remotes/origin/hack", or even
732"refs/remotes/origin/hack"). If the given name has no slash, or the above
733guessing results in an empty name, the guessing is aborted. You can
Junio C Hamano7d06a8a2008-10-20 05:42:33734explicitly give a name with <em>-b</em> in such a case.</p></div>
Junio C Hamano103ad7f2007-03-14 11:19:26735</dd>
Junio C Hamano97bcb482010-11-25 03:16:07736<dt class="hdlist1">
Junio C Hamano103ad7f2007-03-14 11:19:26737--no-track
738</dt>
739<dd>
740<p>
Junio C Hamano3bd66e92009-04-18 06:17:56741 Do not set up "upstream" configuration, even if the
742 branch.autosetupmerge configuration variable is true.
Junio C Hamano103ad7f2007-03-14 11:19:26743</p>
744</dd>
Junio C Hamano97bcb482010-11-25 03:16:07745<dt class="hdlist1">
Junio C Hamano341071d2006-06-04 07:24:48746-l
747</dt>
748<dd>
749<p>
Junio C Hamano97bcb482010-11-25 03:16:07750 Create the new branch&#8217;s reflog; see <a href="git-branch.html">git-branch(1)</a> for
Junio C Hamano3bd66e92009-04-18 06:17:56751 details.
Junio C Hamano341071d2006-06-04 07:24:48752</p>
753</dd>
Junio C Hamano97bcb482010-11-25 03:16:07754<dt class="hdlist1">
Junio C Hamano63c2bc92011-02-28 06:41:28755--detach
756</dt>
757<dd>
758<p>
759 Rather than checking out a branch to work on it, check out a
760 commit for inspection and discardable experiments.
761 This is the default behavior of "git checkout &lt;commit&gt;" when
762 &lt;commit&gt; is not a branch name. See the "DETACHED HEAD" section
763 below for details.
764</p>
765</dd>
766<dt class="hdlist1">
Junio C Hamanocc7636a2010-05-21 14:57:53767--orphan
768</dt>
769<dd>
770<p>
Junio C Hamanobb88cf42010-06-21 15:23:55771 Create a new <em>orphan</em> branch, named &lt;new_branch&gt;, started from
772 &lt;start_point&gt; and switch to it. The first commit made on this
773 new branch will have no parents and it will be the root of a new
774 history totally disconnected from all the other branches and
775 commits.
Junio C Hamanocc7636a2010-05-21 14:57:53776</p>
Junio C Hamano97bcb482010-11-25 03:16:07777<div class="paragraph"><p>The index and the working tree are adjusted as if you had previously run
Junio C Hamanobb88cf42010-06-21 15:23:55778"git checkout &lt;start_point&gt;". This allows you to start a new history
779that records a set of paths similar to &lt;start_point&gt; by easily running
780"git commit -a" to make the root commit.</p></div>
Junio C Hamano97bcb482010-11-25 03:16:07781<div class="paragraph"><p>This can be useful when you want to publish the tree from a commit
Junio C Hamanobb88cf42010-06-21 15:23:55782without exposing its full history. You might want to do this to publish
783an open source branch of a project whose current tree is "clean", but
784whose full history contains proprietary or otherwise encumbered bits of
785code.</p></div>
Junio C Hamano97bcb482010-11-25 03:16:07786<div class="paragraph"><p>If you want to start a disconnected history that records a set of paths
Junio C Hamanobb88cf42010-06-21 15:23:55787that is totally different from the one of &lt;start_point&gt;, then you should
788clear the index and the working tree right after creating the orphan
789branch by running "git rm -rf ." from the top level of the working tree.
790Afterwards you will be ready to prepare your new files, repopulating the
791working tree, by copying them from elsewhere, extracting a tarball, etc.</p></div>
Junio C Hamanocc7636a2010-05-21 14:57:53792</dd>
Junio C Hamano97bcb482010-11-25 03:16:07793<dt class="hdlist1">
Junio C Hamano74e8a2d2006-01-14 03:58:41794-m
795</dt>
Junio C Hamano97bcb482010-11-25 03:16:07796<dt class="hdlist1">
Junio C Hamanoa476efa2008-10-10 15:31:42797--merge
798</dt>
Junio C Hamano74e8a2d2006-01-14 03:58:41799<dd>
800<p>
Junio C Hamanoa476efa2008-10-10 15:31:42801 When switching branches,
802 if you have local modifications to one or more files that
Junio C Hamano2b135272006-03-18 07:45:42803 are different between the current branch and the branch to
804 which you are switching, the command refuses to switch
805 branches in order to preserve your modifications in context.
806 However, with this option, a three-way merge between the current
Junio C Hamano74e8a2d2006-01-14 03:58:41807 branch, your working tree contents, and the new branch
808 is done, and you will be on the new branch.
809</p>
Junio C Hamano97bcb482010-11-25 03:16:07810<div class="paragraph"><p>When a merge conflict happens, the index entries for conflicting
Junio C Hamano74e8a2d2006-01-14 03:58:41811paths are left unmerged, and you need to resolve the conflicts
Junio C Hamano89d4e0f2007-02-18 00:34:59812and mark the resolved paths with <tt>git add</tt> (or <tt>git rm</tt> if the merge
Junio C Hamanoba4b9282008-07-06 05:20:31813should result in deletion of the path).</p></div>
Junio C Hamano97bcb482010-11-25 03:16:07814<div class="paragraph"><p>When checking out paths from the index, this option lets you recreate
Junio C Hamanoa476efa2008-10-10 15:31:42815the conflicted merge in the specified paths.</p></div>
816</dd>
Junio C Hamano97bcb482010-11-25 03:16:07817<dt class="hdlist1">
Junio C Hamanoa476efa2008-10-10 15:31:42818--conflict=&lt;style&gt;
819</dt>
820<dd>
821<p>
822 The same as --merge option above, but changes the way the
823 conflicting hunks are presented, overriding the
824 merge.conflictstyle configuration variable. Possible values are
825 "merge" (default) and "diff3" (in addition to what is shown by
826 "merge" style, shows the original contents).
827</p>
Junio C Hamano74e8a2d2006-01-14 03:58:41828</dd>
Junio C Hamano97bcb482010-11-25 03:16:07829<dt class="hdlist1">
Junio C Hamanoc28068f2009-09-08 00:55:23830-p
831</dt>
Junio C Hamano97bcb482010-11-25 03:16:07832<dt class="hdlist1">
Junio C Hamanoc28068f2009-09-08 00:55:23833--patch
834</dt>
835<dd>
836<p>
837 Interactively select hunks in the difference between the
838 &lt;tree-ish&gt; (or the index, if unspecified) and the working
839 tree. The chosen hunks are then applied in reverse to the
840 working tree (and if a &lt;tree-ish&gt; was specified, the index).
841</p>
Junio C Hamano97bcb482010-11-25 03:16:07842<div class="paragraph"><p>This means that you can use <tt>git checkout -p</tt> to selectively discard
Junio C Hamanob76a6862012-05-02 22:02:46843edits from your current working tree. See the <tt>`Interactive Mode''
844section of linkgit:git-add[1] to learn how to operate the `--patch</tt> mode.</p></div>
Junio C Hamanoc28068f2009-09-08 00:55:23845</dd>
Junio C Hamano97bcb482010-11-25 03:16:07846<dt class="hdlist1">
Junio C Hamano3bd66e92009-04-18 06:17:56847&lt;branch&gt;
848</dt>
849<dd>
850<p>
851 Branch to checkout; if it refers to a branch (i.e., a name that,
852 when prepended with "refs/heads/", is a valid ref), then that
853 branch is checked out. Otherwise, if it refers to a valid
854 commit, your HEAD becomes "detached" and you are no longer on
855 any branch (see below for details).
856</p>
Junio C Hamano97bcb482010-11-25 03:16:07857<div class="paragraph"><p>As a special case, the <tt>"@{-N}"</tt> syntax for the N-th last branch
Junio C Hamano3bd66e92009-04-18 06:17:56858checks out the branch (instead of detaching). You may also specify
859<tt>-</tt> which is synonymous with <tt>"@{-1}"</tt>.</p></div>
Junio C Hamano97bcb482010-11-25 03:16:07860<div class="paragraph"><p>As a further special case, you may use <tt>"A...B"</tt> as a shortcut for the
Junio C Hamanoe32ec8b2010-06-02 23:32:31861merge base of <tt>A</tt> and <tt>B</tt> if there is exactly one merge base. You can
862leave out at most one of <tt>A</tt> and <tt>B</tt>, in which case it defaults to <tt>HEAD</tt>.</p></div>
Junio C Hamano3bd66e92009-04-18 06:17:56863</dd>
Junio C Hamano97bcb482010-11-25 03:16:07864<dt class="hdlist1">
Junio C Hamano1a4e8412005-12-27 08:17:23865&lt;new_branch&gt;
866</dt>
867<dd>
868<p>
869 Name for the new branch.
870</p>
871</dd>
Junio C Hamano97bcb482010-11-25 03:16:07872<dt class="hdlist1">
Junio C Hamano3bd66e92009-04-18 06:17:56873&lt;start_point&gt;
874</dt>
875<dd>
876<p>
877 The name of a commit at which to start the new branch; see
878 <a href="git-branch.html">git-branch(1)</a> for details. Defaults to HEAD.
879</p>
880</dd>
Junio C Hamano97bcb482010-11-25 03:16:07881<dt class="hdlist1">
Junio C Hamanob4a9ede2009-04-08 07:36:32882&lt;tree-ish&gt;
883</dt>
884<dd>
885<p>
886 Tree to checkout from (when paths are given). If not specified,
887 the index will be used.
888</p>
889</dd>
Junio C Hamanoba4b9282008-07-06 05:20:31890</dl></div>
Junio C Hamano1a4e8412005-12-27 08:17:23891</div>
Junio C Hamano63c2bc92011-02-28 06:41:28892<h2 id="_detached_head">DETACHED HEAD</h2>
Junio C Hamano4f9a6052007-01-17 20:25:16893<div class="sectionbody">
Junio C Hamano63c2bc92011-02-28 06:41:28894<div class="paragraph"><p>HEAD normally refers to a named branch (e.g. <em>master</em>). Meanwhile, each
895branch refers to a specific commit. Let&#8217;s look at a repo with three
896commits, one of them tagged, and with branch <em>master</em> checked out:</p></div>
Junio C Hamano4f9a6052007-01-17 20:25:16897<div class="listingblock">
898<div class="content">
Junio C Hamano63c2bc92011-02-28 06:41:28899<pre><tt> HEAD (refers to branch 'master')
900 |
901 v
902a---b---c branch 'master' (refers to commit 'c')
903 ^
904 |
905 tag 'v2.0' (refers to commit 'b')</tt></pre>
Junio C Hamano4f9a6052007-01-17 20:25:16906</div></div>
Junio C Hamano63c2bc92011-02-28 06:41:28907<div class="paragraph"><p>When a commit is created in this state, the branch is updated to refer to
908the new commit. Specifically, <em>git commit</em> creates a new commit <em>d</em>, whose
909parent is commit <em>c</em>, and then updates branch <em>master</em> to refer to new
910commit <em>d</em>. HEAD still refers to branch <em>master</em> and so indirectly now refers
911to commit <em>d</em>:</p></div>
Junio C Hamano9d52e572007-02-13 23:48:20912<div class="listingblock">
913<div class="content">
Junio C Hamano63c2bc92011-02-28 06:41:28914<pre><tt>$ edit; git add; git commit
915
916 HEAD (refers to branch 'master')
917 |
918 v
919a---b---c---d branch 'master' (refers to commit 'd')
920 ^
921 |
922 tag 'v2.0' (refers to commit 'b')</tt></pre>
923</div></div>
924<div class="paragraph"><p>It is sometimes useful to be able to checkout a commit that is not at
925the tip of any named branch, or even to create a new commit that is not
926referenced by a named branch. Let&#8217;s look at what happens when we
927checkout commit <em>b</em> (here we show two ways this may be done):</p></div>
928<div class="listingblock">
929<div class="content">
930<pre><tt>$ git checkout v2.0 # or
931$ git checkout master^^
932
933 HEAD (refers to commit 'b')
934 |
935 v
936a---b---c---d branch 'master' (refers to commit 'd')
937 ^
938 |
939 tag 'v2.0' (refers to commit 'b')</tt></pre>
940</div></div>
941<div class="paragraph"><p>Notice that regardless of which checkout command we use, HEAD now refers
942directly to commit <em>b</em>. This is known as being in detached HEAD state.
943It means simply that HEAD refers to a specific commit, as opposed to
944referring to a named branch. Let&#8217;s see what happens when we create a commit:</p></div>
945<div class="listingblock">
946<div class="content">
947<pre><tt>$ edit; git add; git commit
948
949 HEAD (refers to commit 'e')
950 |
951 v
952 e
953 /
954a---b---c---d branch 'master' (refers to commit 'd')
955 ^
956 |
957 tag 'v2.0' (refers to commit 'b')</tt></pre>
958</div></div>
959<div class="paragraph"><p>There is now a new commit <em>e</em>, but it is referenced only by HEAD. We can
960of course add yet another commit in this state:</p></div>
961<div class="listingblock">
962<div class="content">
963<pre><tt>$ edit; git add; git commit
964
965 HEAD (refers to commit 'f')
966 |
967 v
968 e---f
969 /
970a---b---c---d branch 'master' (refers to commit 'd')
971 ^
972 |
973 tag 'v2.0' (refers to commit 'b')</tt></pre>
974</div></div>
975<div class="paragraph"><p>In fact, we can perform all the normal git operations. But, let&#8217;s look
976at what happens when we then checkout master:</p></div>
977<div class="listingblock">
978<div class="content">
979<pre><tt>$ git checkout master
980
981 HEAD (refers to branch 'master')
982 e---f |
983 / v
984a---b---c---d branch 'master' (refers to commit 'd')
985 ^
986 |
987 tag 'v2.0' (refers to commit 'b')</tt></pre>
988</div></div>
989<div class="paragraph"><p>It is important to realize that at this point nothing refers to commit
990<em>f</em>. Eventually commit <em>f</em> (and by extension commit <em>e</em>) will be deleted
991by the routine git garbage collection process, unless we create a reference
992before that happens. If we have not yet moved away from commit <em>f</em>,
993any of these will create a reference to it:</p></div>
994<div class="listingblock">
995<div class="content">
996<pre><tt>$ git checkout -b foo <b>&lt;1&gt;</b>
997$ git branch foo <b>&lt;2&gt;</b>
998$ git tag foo <b>&lt;3&gt;</b></tt></pre>
999</div></div>
1000<div class="colist arabic"><ol>
1001<li>
1002<p>
1003creates a new branch <em>foo</em>, which refers to commit <em>f</em>, and then
1004updates HEAD to refer to branch <em>foo</em>. In other words, we&#8217;ll no longer
1005be in detached HEAD state after this command.
1006</p>
1007</li>
1008<li>
1009<p>
1010similarly creates a new branch <em>foo</em>, which refers to commit <em>f</em>,
1011but leaves HEAD detached.
1012</p>
1013</li>
1014<li>
1015<p>
1016creates a new tag <em>foo</em>, which refers to commit <em>f</em>,
1017leaving HEAD detached.
1018</p>
1019</li>
1020</ol></div>
1021<div class="paragraph"><p>If we have moved away from commit <em>f</em>, then we must first recover its object
1022name (typically by using git reflog), and then we can create a reference to
1023it. For example, to see the last two commits to which HEAD referred, we
1024can use either of these commands:</p></div>
1025<div class="listingblock">
1026<div class="content">
1027<pre><tt>$ git reflog -2 HEAD # or
1028$ git log -g -2 HEAD</tt></pre>
Junio C Hamano9d52e572007-02-13 23:48:201029</div></div>
Junio C Hamano4f9a6052007-01-17 20:25:161030</div>
Junio C Hamanoba4b9282008-07-06 05:20:311031<h2 id="_examples">EXAMPLES</h2>
Junio C Hamano1a4e8412005-12-27 08:17:231032<div class="sectionbody">
Junio C Hamano97bcb482010-11-25 03:16:071033<div class="olist arabic"><ol class="arabic">
Junio C Hamano74e8a2d2006-01-14 03:58:411034<li>
1035<p>
1036The following sequence checks out the <tt>master</tt> branch, reverts
Junio C Hamano1a4e8412005-12-27 08:17:231037the <tt>Makefile</tt> to two revisions back, deletes hello.c by
Junio C Hamano74e8a2d2006-01-14 03:58:411038mistake, and gets it back from the index.
1039</p>
Junio C Hamano1a4e8412005-12-27 08:17:231040<div class="listingblock">
1041<div class="content">
Junio C Hamano97bcb482010-11-25 03:16:071042<pre><tt>$ git checkout master <b>&lt;1&gt;</b>
1043$ git checkout master~2 Makefile <b>&lt;2&gt;</b>
Junio C Hamano1a4e8412005-12-27 08:17:231044$ rm -f hello.c
Junio C Hamano97bcb482010-11-25 03:16:071045$ git checkout hello.c <b>&lt;3&gt;</b></tt></pre>
Junio C Hamano1a4e8412005-12-27 08:17:231046</div></div>
Junio C Hamano97bcb482010-11-25 03:16:071047<div class="colist arabic"><ol>
Junio C Hamanoc8d88c22006-04-29 07:02:011048<li>
1049<p>
1050switch branch
1051</p>
1052</li>
1053<li>
1054<p>
Junio C Hamano57053932009-03-11 08:48:321055take a file out of another commit
Junio C Hamanoc8d88c22006-04-29 07:02:011056</p>
1057</li>
1058<li>
1059<p>
Junio C Hamanob4a9ede2009-04-08 07:36:321060restore hello.c from the index
Junio C Hamanoc8d88c22006-04-29 07:02:011061</p>
Junio C Hamano97bcb482010-11-25 03:16:071062<div class="paragraph"><p>If you have an unfortunate branch that is named <tt>hello.c</tt>, this
Junio C Hamanoc8d88c22006-04-29 07:02:011063step would be confused as an instruction to switch to that branch.
Junio C Hamanoba4b9282008-07-06 05:20:311064You should instead write:</p></div>
Junio C Hamano1a4e8412005-12-27 08:17:231065<div class="listingblock">
1066<div class="content">
1067<pre><tt>$ git checkout -- hello.c</tt></pre>
1068</div></div>
Junio C Hamano74e8a2d2006-01-14 03:58:411069</li>
Junio C Hamanoba4b9282008-07-06 05:20:311070</ol></div>
Junio C Hamanoc8d88c22006-04-29 07:02:011071</li>
Junio C Hamano74e8a2d2006-01-14 03:58:411072<li>
1073<p>
Junio C Hamano57053932009-03-11 08:48:321074After working in the wrong branch, switching to the correct
Junio C Hamano2b135272006-03-18 07:45:421075branch would be done using:
Junio C Hamano74e8a2d2006-01-14 03:58:411076</p>
1077<div class="listingblock">
1078<div class="content">
1079<pre><tt>$ git checkout mytopic</tt></pre>
1080</div></div>
Junio C Hamano97bcb482010-11-25 03:16:071081<div class="paragraph"><p>However, your "wrong" branch and correct "mytopic" branch may
Junio C Hamano57053932009-03-11 08:48:321082differ in files that you have modified locally, in which case
Junio C Hamanoba4b9282008-07-06 05:20:311083the above checkout would fail like this:</p></div>
Junio C Hamano74e8a2d2006-01-14 03:58:411084<div class="listingblock">
1085<div class="content">
1086<pre><tt>$ git checkout mytopic
Junio C Hamanof2d3a372010-07-12 14:14:181087error: You have local changes to 'frotz'; not switching branches.</tt></pre>
Junio C Hamano74e8a2d2006-01-14 03:58:411088</div></div>
Junio C Hamano97bcb482010-11-25 03:16:071089<div class="paragraph"><p>You can give the <tt>-m</tt> flag to the command, which would try a
Junio C Hamanoba4b9282008-07-06 05:20:311090three-way merge:</p></div>
Junio C Hamano74e8a2d2006-01-14 03:58:411091<div class="listingblock">
1092<div class="content">
1093<pre><tt>$ git checkout -m mytopic
1094Auto-merging frotz</tt></pre>
1095</div></div>
Junio C Hamano97bcb482010-11-25 03:16:071096<div class="paragraph"><p>After this three-way merge, the local modifications are <em>not</em>
Junio C Hamano74e8a2d2006-01-14 03:58:411097registered in your index file, so <tt>git diff</tt> would show you what
Junio C Hamanoba4b9282008-07-06 05:20:311098changes you made since the tip of the new branch.</p></div>
Junio C Hamano74e8a2d2006-01-14 03:58:411099</li>
1100<li>
1101<p>
1102When a merge conflict happens during switching branches with
1103the <tt>-m</tt> option, you would see something like this:
1104</p>
1105<div class="listingblock">
1106<div class="content">
1107<pre><tt>$ git checkout -m mytopic
1108Auto-merging frotz
Junio C Hamano74e8a2d2006-01-14 03:58:411109ERROR: Merge conflict in frotz
1110fatal: merge program failed</tt></pre>
1111</div></div>
Junio C Hamano97bcb482010-11-25 03:16:071112<div class="paragraph"><p>At this point, <tt>git diff</tt> shows the changes cleanly merged as in
Junio C Hamano74e8a2d2006-01-14 03:58:411113the previous example, as well as the changes in the conflicted
1114files. Edit and resolve the conflict and mark it resolved with
Junio C Hamanoba4b9282008-07-06 05:20:311115<tt>git add</tt> as usual:</p></div>
Junio C Hamano74e8a2d2006-01-14 03:58:411116<div class="listingblock">
1117<div class="content">
1118<pre><tt>$ edit frotz
Junio C Hamano89d4e0f2007-02-18 00:34:591119$ git add frotz</tt></pre>
Junio C Hamano74e8a2d2006-01-14 03:58:411120</div></div>
1121</li>
Junio C Hamanoba4b9282008-07-06 05:20:311122</ol></div>
Junio C Hamano1a4e8412005-12-27 08:17:231123</div>
Junio C Hamanoba4b9282008-07-06 05:20:311124<h2 id="_git">GIT</h2>
Junio C Hamano1a4e8412005-12-27 08:17:231125<div class="sectionbody">
Junio C Hamano97bcb482010-11-25 03:16:071126<div class="paragraph"><p>Part of the <a href="git.html">git(1)</a> suite</p></div>
Junio C Hamano1a4e8412005-12-27 08:17:231127</div>
Junio C Hamano7bd050f2011-09-22 06:32:221128</div>
1129<div id="footnotes"><hr /></div>
Junio C Hamano1a4e8412005-12-27 08:17:231130<div id="footer">
1131<div id="footer-text">
Junio C Hamanob76a6862012-05-02 22:02:461132Last updated 2012-05-02 15:00:44 PDT
Junio C Hamano1a4e8412005-12-27 08:17:231133</div>
1134</div>
1135</body>
1136</html>