Autogenerated HTML docs for v2.42.0-241-g6bdb5
[git-htmldocs.git] / git-checkout.html
blobadd5ff02557e67139e1c7de4592bb511d336da3e
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
5 <head>
6 <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
7 <meta name="generator" content="AsciiDoc 10.2.0" />
8 <title>git-checkout(1)</title>
9 <style type="text/css">
10 /* Shared CSS for AsciiDoc xhtml11 and html5 backends */
12 /* Default font. */
13 body {
14 font-family: Georgia,serif;
17 /* Title font. */
18 h1, h2, h3, h4, h5, h6,
19 div.title, caption.title,
20 thead, p.table.header,
21 #toctitle,
22 #author, #revnumber, #revdate, #revremark,
23 #footer {
24 font-family: Arial,Helvetica,sans-serif;
27 body {
28 margin: 1em 5% 1em 5%;
31 a {
32 color: blue;
33 text-decoration: underline;
35 a:visited {
36 color: fuchsia;
39 em {
40 font-style: italic;
41 color: navy;
44 strong {
45 font-weight: bold;
46 color: #083194;
49 h1, h2, h3, h4, h5, h6 {
50 color: #527bbd;
51 margin-top: 1.2em;
52 margin-bottom: 0.5em;
53 line-height: 1.3;
56 h1, h2, h3 {
57 border-bottom: 2px solid silver;
59 h2 {
60 padding-top: 0.5em;
62 h3 {
63 float: left;
65 h3 + * {
66 clear: left;
68 h5 {
69 font-size: 1.0em;
72 div.sectionbody {
73 margin-left: 0;
76 hr {
77 border: 1px solid silver;
80 p {
81 margin-top: 0.5em;
82 margin-bottom: 0.5em;
85 ul, ol, li > p {
86 margin-top: 0;
88 ul > li { color: #aaa; }
89 ul > li > * { color: black; }
91 .monospaced, code, pre {
92 font-family: "Courier New", Courier, monospace;
93 font-size: inherit;
94 color: navy;
95 padding: 0;
96 margin: 0;
98 pre {
99 white-space: pre-wrap;
102 #author {
103 color: #527bbd;
104 font-weight: bold;
105 font-size: 1.1em;
107 #email {
109 #revnumber, #revdate, #revremark {
112 #footer {
113 font-size: small;
114 border-top: 2px solid silver;
115 padding-top: 0.5em;
116 margin-top: 4.0em;
118 #footer-text {
119 float: left;
120 padding-bottom: 0.5em;
122 #footer-badges {
123 float: right;
124 padding-bottom: 0.5em;
127 #preamble {
128 margin-top: 1.5em;
129 margin-bottom: 1.5em;
131 div.imageblock, div.exampleblock, div.verseblock,
132 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
133 div.admonitionblock {
134 margin-top: 1.0em;
135 margin-bottom: 1.5em;
137 div.admonitionblock {
138 margin-top: 2.0em;
139 margin-bottom: 2.0em;
140 margin-right: 10%;
141 color: #606060;
144 div.content { /* Block element content. */
145 padding: 0;
148 /* Block element titles. */
149 div.title, caption.title {
150 color: #527bbd;
151 font-weight: bold;
152 text-align: left;
153 margin-top: 1.0em;
154 margin-bottom: 0.5em;
156 div.title + * {
157 margin-top: 0;
160 td div.title:first-child {
161 margin-top: 0.0em;
163 div.content div.title:first-child {
164 margin-top: 0.0em;
166 div.content + div.title {
167 margin-top: 0.0em;
170 div.sidebarblock > div.content {
171 background: #ffffee;
172 border: 1px solid #dddddd;
173 border-left: 4px solid #f0f0f0;
174 padding: 0.5em;
177 div.listingblock > div.content {
178 border: 1px solid #dddddd;
179 border-left: 5px solid #f0f0f0;
180 background: #f8f8f8;
181 padding: 0.5em;
184 div.quoteblock, div.verseblock {
185 padding-left: 1.0em;
186 margin-left: 1.0em;
187 margin-right: 10%;
188 border-left: 5px solid #f0f0f0;
189 color: #888;
192 div.quoteblock > div.attribution {
193 padding-top: 0.5em;
194 text-align: right;
197 div.verseblock > pre.content {
198 font-family: inherit;
199 font-size: inherit;
201 div.verseblock > div.attribution {
202 padding-top: 0.75em;
203 text-align: left;
205 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
206 div.verseblock + div.attribution {
207 text-align: left;
210 div.admonitionblock .icon {
211 vertical-align: top;
212 font-size: 1.1em;
213 font-weight: bold;
214 text-decoration: underline;
215 color: #527bbd;
216 padding-right: 0.5em;
218 div.admonitionblock td.content {
219 padding-left: 0.5em;
220 border-left: 3px solid #dddddd;
223 div.exampleblock > div.content {
224 border-left: 3px solid #dddddd;
225 padding-left: 0.5em;
228 div.imageblock div.content { padding-left: 0; }
229 span.image img { border-style: none; vertical-align: text-bottom; }
230 a.image:visited { color: white; }
232 dl {
233 margin-top: 0.8em;
234 margin-bottom: 0.8em;
236 dt {
237 margin-top: 0.5em;
238 margin-bottom: 0;
239 font-style: normal;
240 color: navy;
242 dd > *:first-child {
243 margin-top: 0.1em;
246 ul, ol {
247 list-style-position: outside;
249 ol.arabic {
250 list-style-type: decimal;
252 ol.loweralpha {
253 list-style-type: lower-alpha;
255 ol.upperalpha {
256 list-style-type: upper-alpha;
258 ol.lowerroman {
259 list-style-type: lower-roman;
261 ol.upperroman {
262 list-style-type: upper-roman;
265 div.compact ul, div.compact ol,
266 div.compact p, div.compact p,
267 div.compact div, div.compact div {
268 margin-top: 0.1em;
269 margin-bottom: 0.1em;
272 tfoot {
273 font-weight: bold;
275 td > div.verse {
276 white-space: pre;
279 div.hdlist {
280 margin-top: 0.8em;
281 margin-bottom: 0.8em;
283 div.hdlist tr {
284 padding-bottom: 15px;
286 dt.hdlist1.strong, td.hdlist1.strong {
287 font-weight: bold;
289 td.hdlist1 {
290 vertical-align: top;
291 font-style: normal;
292 padding-right: 0.8em;
293 color: navy;
295 td.hdlist2 {
296 vertical-align: top;
298 div.hdlist.compact tr {
299 margin: 0;
300 padding-bottom: 0;
303 .comment {
304 background: yellow;
307 .footnote, .footnoteref {
308 font-size: 0.8em;
311 span.footnote, span.footnoteref {
312 vertical-align: super;
315 #footnotes {
316 margin: 20px 0 20px 0;
317 padding: 7px 0 0 0;
320 #footnotes div.footnote {
321 margin: 0 0 5px 0;
324 #footnotes hr {
325 border: none;
326 border-top: 1px solid silver;
327 height: 1px;
328 text-align: left;
329 margin-left: 0;
330 width: 20%;
331 min-width: 100px;
334 div.colist td {
335 padding-right: 0.5em;
336 padding-bottom: 0.3em;
337 vertical-align: top;
339 div.colist td img {
340 margin-top: 0.3em;
343 @media print {
344 #footer-badges { display: none; }
347 #toc {
348 margin-bottom: 2.5em;
351 #toctitle {
352 color: #527bbd;
353 font-size: 1.1em;
354 font-weight: bold;
355 margin-top: 1.0em;
356 margin-bottom: 0.1em;
359 div.toclevel0, div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
360 margin-top: 0;
361 margin-bottom: 0;
363 div.toclevel2 {
364 margin-left: 2em;
365 font-size: 0.9em;
367 div.toclevel3 {
368 margin-left: 4em;
369 font-size: 0.9em;
371 div.toclevel4 {
372 margin-left: 6em;
373 font-size: 0.9em;
376 span.aqua { color: aqua; }
377 span.black { color: black; }
378 span.blue { color: blue; }
379 span.fuchsia { color: fuchsia; }
380 span.gray { color: gray; }
381 span.green { color: green; }
382 span.lime { color: lime; }
383 span.maroon { color: maroon; }
384 span.navy { color: navy; }
385 span.olive { color: olive; }
386 span.purple { color: purple; }
387 span.red { color: red; }
388 span.silver { color: silver; }
389 span.teal { color: teal; }
390 span.white { color: white; }
391 span.yellow { color: yellow; }
393 span.aqua-background { background: aqua; }
394 span.black-background { background: black; }
395 span.blue-background { background: blue; }
396 span.fuchsia-background { background: fuchsia; }
397 span.gray-background { background: gray; }
398 span.green-background { background: green; }
399 span.lime-background { background: lime; }
400 span.maroon-background { background: maroon; }
401 span.navy-background { background: navy; }
402 span.olive-background { background: olive; }
403 span.purple-background { background: purple; }
404 span.red-background { background: red; }
405 span.silver-background { background: silver; }
406 span.teal-background { background: teal; }
407 span.white-background { background: white; }
408 span.yellow-background { background: yellow; }
410 span.big { font-size: 2em; }
411 span.small { font-size: 0.6em; }
413 span.underline { text-decoration: underline; }
414 span.overline { text-decoration: overline; }
415 span.line-through { text-decoration: line-through; }
417 div.unbreakable { page-break-inside: avoid; }
421 * xhtml11 specific
423 * */
425 div.tableblock {
426 margin-top: 1.0em;
427 margin-bottom: 1.5em;
429 div.tableblock > table {
430 border: 3px solid #527bbd;
432 thead, p.table.header {
433 font-weight: bold;
434 color: #527bbd;
436 p.table {
437 margin-top: 0;
439 /* Because the table frame attribute is overridden by CSS in most browsers. */
440 div.tableblock > table[frame="void"] {
441 border-style: none;
443 div.tableblock > table[frame="hsides"] {
444 border-left-style: none;
445 border-right-style: none;
447 div.tableblock > table[frame="vsides"] {
448 border-top-style: none;
449 border-bottom-style: none;
454 * html5 specific
456 * */
458 table.tableblock {
459 margin-top: 1.0em;
460 margin-bottom: 1.5em;
462 thead, p.tableblock.header {
463 font-weight: bold;
464 color: #527bbd;
466 p.tableblock {
467 margin-top: 0;
469 table.tableblock {
470 border-width: 3px;
471 border-spacing: 0px;
472 border-style: solid;
473 border-color: #527bbd;
474 border-collapse: collapse;
476 th.tableblock, td.tableblock {
477 border-width: 1px;
478 padding: 4px;
479 border-style: solid;
480 border-color: #527bbd;
483 table.tableblock.frame-topbot {
484 border-left-style: hidden;
485 border-right-style: hidden;
487 table.tableblock.frame-sides {
488 border-top-style: hidden;
489 border-bottom-style: hidden;
491 table.tableblock.frame-none {
492 border-style: hidden;
495 th.tableblock.halign-left, td.tableblock.halign-left {
496 text-align: left;
498 th.tableblock.halign-center, td.tableblock.halign-center {
499 text-align: center;
501 th.tableblock.halign-right, td.tableblock.halign-right {
502 text-align: right;
505 th.tableblock.valign-top, td.tableblock.valign-top {
506 vertical-align: top;
508 th.tableblock.valign-middle, td.tableblock.valign-middle {
509 vertical-align: middle;
511 th.tableblock.valign-bottom, td.tableblock.valign-bottom {
512 vertical-align: bottom;
517 * manpage specific
519 * */
521 body.manpage h1 {
522 padding-top: 0.5em;
523 padding-bottom: 0.5em;
524 border-top: 2px solid silver;
525 border-bottom: 2px solid silver;
527 body.manpage h2 {
528 border-style: none;
530 body.manpage div.sectionbody {
531 margin-left: 3em;
534 @media print {
535 body.manpage div#toc { display: none; }
539 </style>
540 <script type="text/javascript">
541 /*<![CDATA[*/
542 var asciidoc = { // Namespace.
544 /////////////////////////////////////////////////////////////////////
545 // Table Of Contents generator
546 /////////////////////////////////////////////////////////////////////
548 /* Author: Mihai Bazon, September 2002
549 * http://students.infoiasi.ro/~mishoo
551 * Table Of Content generator
552 * Version: 0.4
554 * Feel free to use this script under the terms of the GNU General Public
555 * License, as long as you do not remove or alter this notice.
558 /* modified by Troy D. Hanson, September 2006. License: GPL */
559 /* modified by Stuart Rackham, 2006, 2009. License: GPL */
561 // toclevels = 1..4.
562 toc: function (toclevels) {
564 function getText(el) {
565 var text = "";
566 for (var i = el.firstChild; i != null; i = i.nextSibling) {
567 if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
568 text += i.data;
569 else if (i.firstChild != null)
570 text += getText(i);
572 return text;
575 function TocEntry(el, text, toclevel) {
576 this.element = el;
577 this.text = text;
578 this.toclevel = toclevel;
581 function tocEntries(el, toclevels) {
582 var result = new Array;
583 var re = new RegExp('[hH]([1-'+(toclevels+1)+'])');
584 // Function that scans the DOM tree for header elements (the DOM2
585 // nodeIterator API would be a better technique but not supported by all
586 // browsers).
587 var iterate = function (el) {
588 for (var i = el.firstChild; i != null; i = i.nextSibling) {
589 if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
590 var mo = re.exec(i.tagName);
591 if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") {
592 result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
594 iterate(i);
598 iterate(el);
599 return result;
602 var toc = document.getElementById("toc");
603 if (!toc) {
604 return;
607 // Delete existing TOC entries in case we're reloading the TOC.
608 var tocEntriesToRemove = [];
609 var i;
610 for (i = 0; i < toc.childNodes.length; i++) {
611 var entry = toc.childNodes[i];
612 if (entry.nodeName.toLowerCase() == 'div'
613 && entry.getAttribute("class")
614 && entry.getAttribute("class").match(/^toclevel/))
615 tocEntriesToRemove.push(entry);
617 for (i = 0; i < tocEntriesToRemove.length; i++) {
618 toc.removeChild(tocEntriesToRemove[i]);
621 // Rebuild TOC entries.
622 var entries = tocEntries(document.getElementById("content"), toclevels);
623 for (var i = 0; i < entries.length; ++i) {
624 var entry = entries[i];
625 if (entry.element.id == "")
626 entry.element.id = "_toc_" + i;
627 var a = document.createElement("a");
628 a.href = "#" + entry.element.id;
629 a.appendChild(document.createTextNode(entry.text));
630 var div = document.createElement("div");
631 div.appendChild(a);
632 div.className = "toclevel" + entry.toclevel;
633 toc.appendChild(div);
635 if (entries.length == 0)
636 toc.parentNode.removeChild(toc);
640 /////////////////////////////////////////////////////////////////////
641 // Footnotes generator
642 /////////////////////////////////////////////////////////////////////
644 /* Based on footnote generation code from:
645 * http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
648 footnotes: function () {
649 // Delete existing footnote entries in case we're reloading the footnodes.
650 var i;
651 var noteholder = document.getElementById("footnotes");
652 if (!noteholder) {
653 return;
655 var entriesToRemove = [];
656 for (i = 0; i < noteholder.childNodes.length; i++) {
657 var entry = noteholder.childNodes[i];
658 if (entry.nodeName.toLowerCase() == 'div' && entry.getAttribute("class") == "footnote")
659 entriesToRemove.push(entry);
661 for (i = 0; i < entriesToRemove.length; i++) {
662 noteholder.removeChild(entriesToRemove[i]);
665 // Rebuild footnote entries.
666 var cont = document.getElementById("content");
667 var spans = cont.getElementsByTagName("span");
668 var refs = {};
669 var n = 0;
670 for (i=0; i<spans.length; i++) {
671 if (spans[i].className == "footnote") {
672 n++;
673 var note = spans[i].getAttribute("data-note");
674 if (!note) {
675 // Use [\s\S] in place of . so multi-line matches work.
676 // Because JavaScript has no s (dotall) regex flag.
677 note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1];
678 spans[i].innerHTML =
679 "[<a id='_footnoteref_" + n + "' href='#_footnote_" + n +
680 "' title='View footnote' class='footnote'>" + n + "</a>]";
681 spans[i].setAttribute("data-note", note);
683 noteholder.innerHTML +=
684 "<div class='footnote' id='_footnote_" + n + "'>" +
685 "<a href='#_footnoteref_" + n + "' title='Return to text'>" +
686 n + "</a>. " + note + "</div>";
687 var id =spans[i].getAttribute("id");
688 if (id != null) refs["#"+id] = n;
691 if (n == 0)
692 noteholder.parentNode.removeChild(noteholder);
693 else {
694 // Process footnoterefs.
695 for (i=0; i<spans.length; i++) {
696 if (spans[i].className == "footnoteref") {
697 var href = spans[i].getElementsByTagName("a")[0].getAttribute("href");
698 href = href.match(/#.*/)[0]; // Because IE return full URL.
699 n = refs[href];
700 spans[i].innerHTML =
701 "[<a href='#_footnote_" + n +
702 "' title='View footnote' class='footnote'>" + n + "</a>]";
708 install: function(toclevels) {
709 var timerId;
711 function reinstall() {
712 asciidoc.footnotes();
713 if (toclevels) {
714 asciidoc.toc(toclevels);
718 function reinstallAndRemoveTimer() {
719 clearInterval(timerId);
720 reinstall();
723 timerId = setInterval(reinstall, 500);
724 if (document.addEventListener)
725 document.addEventListener("DOMContentLoaded", reinstallAndRemoveTimer, false);
726 else
727 window.onload = reinstallAndRemoveTimer;
731 asciidoc.install();
732 /*]]>*/
733 </script>
734 </head>
735 <body class="manpage">
736 <div id="header">
737 <h1>
738 git-checkout(1) Manual Page
739 </h1>
740 <h2>NAME</h2>
741 <div class="sectionbody">
742 <p>git-checkout -
743 Switch branches or restore working tree files
744 </p>
745 </div>
746 </div>
747 <div id="content">
748 <div class="sect1">
749 <h2 id="_synopsis">SYNOPSIS</h2>
750 <div class="sectionbody">
751 <div class="verseblock">
752 <pre class="content"><em>git checkout</em> [-q] [-f] [-m] [&lt;branch&gt;]
753 <em>git checkout</em> [-q] [-f] [-m] --detach [&lt;branch&gt;]
754 <em>git checkout</em> [-q] [-f] [-m] [--detach] &lt;commit&gt;
755 <em>git checkout</em> [-q] [-f] [-m] [[-b|-B|--orphan] &lt;new-branch&gt;] [&lt;start-point&gt;]
756 <em>git checkout</em> [-f|--ours|--theirs|-m|--conflict=&lt;style&gt;] [&lt;tree-ish&gt;] [--] &lt;pathspec&gt;&#8230;
757 <em>git checkout</em> [-f|--ours|--theirs|-m|--conflict=&lt;style&gt;] [&lt;tree-ish&gt;] --pathspec-from-file=&lt;file&gt; [--pathspec-file-nul]
758 <em>git checkout</em> (-p|--patch) [&lt;tree-ish&gt;] [--] [&lt;pathspec&gt;&#8230;]</pre>
759 <div class="attribution">
760 </div></div>
761 </div>
762 </div>
763 <div class="sect1">
764 <h2 id="_description">DESCRIPTION</h2>
765 <div class="sectionbody">
766 <div class="paragraph"><p>Updates files in the working tree to match the version in the index
767 or the specified tree. If no pathspec was given, <em>git checkout</em> will
768 also update <code>HEAD</code> to set the specified branch as the current
769 branch.</p></div>
770 <div class="dlist"><dl>
771 <dt class="hdlist1">
772 <em>git checkout</em> [&lt;branch&gt;]
773 </dt>
774 <dd>
776 To prepare for working on <code>&lt;branch&gt;</code>, switch to it by updating
777 the index and the files in the working tree, and by pointing
778 <code>HEAD</code> at the branch. Local modifications to the files in the
779 working tree are kept, so that they can be committed to the
780 <code>&lt;branch&gt;</code>.
781 </p>
782 <div class="paragraph"><p>If <code>&lt;branch&gt;</code> is not found but there does exist a tracking branch in
783 exactly one remote (call it <code>&lt;remote&gt;</code>) with a matching name and
784 <code>--no-guess</code> is not specified, treat as equivalent to</p></div>
785 <div class="listingblock">
786 <div class="content">
787 <pre><code>$ git checkout -b &lt;branch&gt; --track &lt;remote&gt;/&lt;branch&gt;</code></pre>
788 </div></div>
789 <div class="paragraph"><p>You could omit <code>&lt;branch&gt;</code>, in which case the command degenerates to
790 "check out the current branch", which is a glorified no-op with
791 rather expensive side-effects to show only the tracking information,
792 if exists, for the current branch.</p></div>
793 </dd>
794 <dt class="hdlist1">
795 <em>git checkout</em> -b|-B &lt;new-branch&gt; [&lt;start-point&gt;]
796 </dt>
797 <dd>
799 Specifying <code>-b</code> causes a new branch to be created as if
800 <a href="git-branch.html">git-branch(1)</a> were called and then checked out. In
801 this case you can use the <code>--track</code> or <code>--no-track</code> options,
802 which will be passed to <em>git branch</em>. As a convenience,
803 <code>--track</code> without <code>-b</code> implies branch creation; see the
804 description of <code>--track</code> below.
805 </p>
806 <div class="paragraph"><p>If <code>-B</code> is given, <code>&lt;new-branch&gt;</code> is created if it doesn&#8217;t exist; otherwise, it
807 is reset. This is the transactional equivalent of</p></div>
808 <div class="listingblock">
809 <div class="content">
810 <pre><code>$ git branch -f &lt;branch&gt; [&lt;start-point&gt;]
811 $ git checkout &lt;branch&gt;</code></pre>
812 </div></div>
813 <div class="paragraph"><p>that is to say, the branch is not reset/created unless "git checkout" is
814 successful.</p></div>
815 </dd>
816 <dt class="hdlist1">
817 <em>git checkout</em> --detach [&lt;branch&gt;]
818 </dt>
819 <dt class="hdlist1">
820 <em>git checkout</em> [--detach] &lt;commit&gt;
821 </dt>
822 <dd>
824 Prepare to work on top of <code>&lt;commit&gt;</code>, by detaching <code>HEAD</code> at it
825 (see "DETACHED HEAD" section), and updating the index and the
826 files in the working tree. Local modifications to the files
827 in the working tree are kept, so that the resulting working
828 tree will be the state recorded in the commit plus the local
829 modifications.
830 </p>
831 <div class="paragraph"><p>When the <code>&lt;commit&gt;</code> argument is a branch name, the <code>--detach</code> option can
832 be used to detach <code>HEAD</code> at the tip of the branch (<code>git checkout
833 &lt;branch&gt;</code> would check out that branch without detaching <code>HEAD</code>).</p></div>
834 <div class="paragraph"><p>Omitting <code>&lt;branch&gt;</code> detaches <code>HEAD</code> at the tip of the current branch.</p></div>
835 </dd>
836 <dt class="hdlist1">
837 <em>git checkout</em> [-f|--ours|--theirs|-m|--conflict=&lt;style&gt;] [&lt;tree-ish&gt;] [--] &lt;pathspec&gt;&#8230;
838 </dt>
839 <dt class="hdlist1">
840 <em>git checkout</em> [-f|--ours|--theirs|-m|--conflict=&lt;style&gt;] [&lt;tree-ish&gt;] --pathspec-from-file=&lt;file&gt; [--pathspec-file-nul]
841 </dt>
842 <dd>
844 Overwrite the contents of the files that match the pathspec.
845 When the <code>&lt;tree-ish&gt;</code> (most often a commit) is not given,
846 overwrite working tree with the contents in the index.
847 When the <code>&lt;tree-ish&gt;</code> is given, overwrite both the index and
848 the working tree with the contents at the <code>&lt;tree-ish&gt;</code>.
849 </p>
850 <div class="paragraph"><p>The index may contain unmerged entries because of a previous failed merge.
851 By default, if you try to check out such an entry from the index, the
852 checkout operation will fail and nothing will be checked out.
853 Using <code>-f</code> will ignore these unmerged entries. The contents from a
854 specific side of the merge can be checked out of the index by
855 using <code>--ours</code> or <code>--theirs</code>. With <code>-m</code>, changes made to the working tree
856 file can be discarded to re-create the original conflicted merge result.</p></div>
857 </dd>
858 <dt class="hdlist1">
859 <em>git checkout</em> (-p|--patch) [&lt;tree-ish&gt;] [--] [&lt;pathspec&gt;&#8230;]
860 </dt>
861 <dd>
863 This is similar to the previous mode, but lets you use the
864 interactive interface to show the "diff" output and choose which
865 hunks to use in the result. See below for the description of
866 <code>--patch</code> option.
867 </p>
868 </dd>
869 </dl></div>
870 </div>
871 </div>
872 <div class="sect1">
873 <h2 id="_options">OPTIONS</h2>
874 <div class="sectionbody">
875 <div class="dlist"><dl>
876 <dt class="hdlist1">
878 </dt>
879 <dt class="hdlist1">
880 --quiet
881 </dt>
882 <dd>
884 Quiet, suppress feedback messages.
885 </p>
886 </dd>
887 <dt class="hdlist1">
888 --progress
889 </dt>
890 <dt class="hdlist1">
891 --no-progress
892 </dt>
893 <dd>
895 Progress status is reported on the standard error stream
896 by default when it is attached to a terminal, unless <code>--quiet</code>
897 is specified. This flag enables progress reporting even if not
898 attached to a terminal, regardless of <code>--quiet</code>.
899 </p>
900 </dd>
901 <dt class="hdlist1">
903 </dt>
904 <dt class="hdlist1">
905 --force
906 </dt>
907 <dd>
909 When switching branches, proceed even if the index or the
910 working tree differs from <code>HEAD</code>, and even if there are untracked
911 files in the way. This is used to throw away local changes and
912 any untracked files or directories that are in the way.
913 </p>
914 <div class="paragraph"><p>When checking out paths from the index, do not fail upon unmerged
915 entries; instead, unmerged entries are ignored.</p></div>
916 </dd>
917 <dt class="hdlist1">
918 --ours
919 </dt>
920 <dt class="hdlist1">
921 --theirs
922 </dt>
923 <dd>
925 When checking out paths from the index, check out stage #2
926 (<em>ours</em>) or #3 (<em>theirs</em>) for unmerged paths.
927 </p>
928 <div class="paragraph"><p>Note that during <code>git rebase</code> and <code>git pull --rebase</code>, <em>ours</em> and
929 <em>theirs</em> may appear swapped; <code>--ours</code> gives the version from the
930 branch the changes are rebased onto, while <code>--theirs</code> gives the
931 version from the branch that holds your work that is being rebased.</p></div>
932 <div class="paragraph"><p>This is because <code>rebase</code> is used in a workflow that treats the
933 history at the remote as the shared canonical one, and treats the
934 work done on the branch you are rebasing as the third-party work to
935 be integrated, and you are temporarily assuming the role of the
936 keeper of the canonical history during the rebase. As the keeper of
937 the canonical history, you need to view the history from the remote
938 as <code>ours</code> (i.e. "our shared canonical history"), while what you did
939 on your side branch as <code>theirs</code> (i.e. "one contributor&#8217;s work on top
940 of it").</p></div>
941 </dd>
942 <dt class="hdlist1">
943 -b &lt;new-branch&gt;
944 </dt>
945 <dd>
947 Create a new branch named <code>&lt;new-branch&gt;</code>, start it at
948 <code>&lt;start-point&gt;</code>, and check the resulting branch out;
949 see <a href="git-branch.html">git-branch(1)</a> for details.
950 </p>
951 </dd>
952 <dt class="hdlist1">
953 -B &lt;new-branch&gt;
954 </dt>
955 <dd>
957 Creates the branch <code>&lt;new-branch&gt;</code>, start it at <code>&lt;start-point&gt;</code>;
958 if it already exists, then reset it to <code>&lt;start-point&gt;</code>. And then
959 check the resulting branch out. This is equivalent to running
960 "git branch" with "-f" followed by "git checkout" of that branch;
961 see <a href="git-branch.html">git-branch(1)</a> for details.
962 </p>
963 </dd>
964 <dt class="hdlist1">
966 </dt>
967 <dt class="hdlist1">
968 --track[=(direct|inherit)]
969 </dt>
970 <dd>
972 When creating a new branch, set up "upstream" configuration. See
973 "--track" in <a href="git-branch.html">git-branch(1)</a> for details.
974 </p>
975 <div class="paragraph"><p>If no <code>-b</code> option is given, the name of the new branch will be
976 derived from the remote-tracking branch, by looking at the local part of
977 the refspec configured for the corresponding remote, and then stripping
978 the initial part up to the "*".
979 This would tell us to use <code>hack</code> as the local branch when branching
980 off of <code>origin/hack</code> (or <code>remotes/origin/hack</code>, or even
981 <code>refs/remotes/origin/hack</code>). If the given name has no slash, or the above
982 guessing results in an empty name, the guessing is aborted. You can
983 explicitly give a name with <code>-b</code> in such a case.</p></div>
984 </dd>
985 <dt class="hdlist1">
986 --no-track
987 </dt>
988 <dd>
990 Do not set up "upstream" configuration, even if the
991 <code>branch.autoSetupMerge</code> configuration variable is true.
992 </p>
993 </dd>
994 <dt class="hdlist1">
995 --guess
996 </dt>
997 <dt class="hdlist1">
998 --no-guess
999 </dt>
1000 <dd>
1002 If <code>&lt;branch&gt;</code> is not found but there does exist a tracking
1003 branch in exactly one remote (call it <code>&lt;remote&gt;</code>) with a
1004 matching name, treat as equivalent to
1005 </p>
1006 <div class="listingblock">
1007 <div class="content">
1008 <pre><code>$ git checkout -b &lt;branch&gt; --track &lt;remote&gt;/&lt;branch&gt;</code></pre>
1009 </div></div>
1010 <div class="paragraph"><p>If the branch exists in multiple remotes and one of them is named by
1011 the <code>checkout.defaultRemote</code> configuration variable, we&#8217;ll use that
1012 one for the purposes of disambiguation, even if the <code>&lt;branch&gt;</code> isn&#8217;t
1013 unique across all remotes. Set it to
1014 e.g. <code>checkout.defaultRemote=origin</code> to always checkout remote
1015 branches from there if <code>&lt;branch&gt;</code> is ambiguous but exists on the
1016 <em>origin</em> remote. See also <code>checkout.defaultRemote</code> in
1017 <a href="git-config.html">git-config(1)</a>.</p></div>
1018 <div class="paragraph"><p><code>--guess</code> is the default behavior. Use <code>--no-guess</code> to disable it.</p></div>
1019 <div class="paragraph"><p>The default behavior can be set via the <code>checkout.guess</code> configuration
1020 variable.</p></div>
1021 </dd>
1022 <dt class="hdlist1">
1024 </dt>
1025 <dd>
1027 Create the new branch&#8217;s reflog; see <a href="git-branch.html">git-branch(1)</a> for
1028 details.
1029 </p>
1030 </dd>
1031 <dt class="hdlist1">
1033 </dt>
1034 <dt class="hdlist1">
1035 --detach
1036 </dt>
1037 <dd>
1039 Rather than checking out a branch to work on it, check out a
1040 commit for inspection and discardable experiments.
1041 This is the default behavior of <code>git checkout &lt;commit&gt;</code> when
1042 <code>&lt;commit&gt;</code> is not a branch name. See the "DETACHED HEAD" section
1043 below for details.
1044 </p>
1045 </dd>
1046 <dt class="hdlist1">
1047 --orphan &lt;new-branch&gt;
1048 </dt>
1049 <dd>
1051 Create a new <em>orphan</em> branch, named <code>&lt;new-branch&gt;</code>, started from
1052 <code>&lt;start-point&gt;</code> and switch to it. The first commit made on this
1053 new branch will have no parents and it will be the root of a new
1054 history totally disconnected from all the other branches and
1055 commits.
1056 </p>
1057 <div class="paragraph"><p>The index and the working tree are adjusted as if you had previously run
1058 <code>git checkout &lt;start-point&gt;</code>. This allows you to start a new history
1059 that records a set of paths similar to <code>&lt;start-point&gt;</code> by easily running
1060 <code>git commit -a</code> to make the root commit.</p></div>
1061 <div class="paragraph"><p>This can be useful when you want to publish the tree from a commit
1062 without exposing its full history. You might want to do this to publish
1063 an open source branch of a project whose current tree is "clean", but
1064 whose full history contains proprietary or otherwise encumbered bits of
1065 code.</p></div>
1066 <div class="paragraph"><p>If you want to start a disconnected history that records a set of paths
1067 that is totally different from the one of <code>&lt;start-point&gt;</code>, then you should
1068 clear the index and the working tree right after creating the orphan
1069 branch by running <code>git rm -rf .</code> from the top level of the working tree.
1070 Afterwards you will be ready to prepare your new files, repopulating the
1071 working tree, by copying them from elsewhere, extracting a tarball, etc.</p></div>
1072 </dd>
1073 <dt class="hdlist1">
1074 --ignore-skip-worktree-bits
1075 </dt>
1076 <dd>
1078 In sparse checkout mode, <code>git checkout -- &lt;paths&gt;</code> would
1079 update only entries matched by <code>&lt;paths&gt;</code> and sparse patterns
1080 in <code>$GIT_DIR/info/sparse-checkout</code>. This option ignores
1081 the sparse patterns and adds back any files in <code>&lt;paths&gt;</code>.
1082 </p>
1083 </dd>
1084 <dt class="hdlist1">
1086 </dt>
1087 <dt class="hdlist1">
1088 --merge
1089 </dt>
1090 <dd>
1092 When switching branches,
1093 if you have local modifications to one or more files that
1094 are different between the current branch and the branch to
1095 which you are switching, the command refuses to switch
1096 branches in order to preserve your modifications in context.
1097 However, with this option, a three-way merge between the current
1098 branch, your working tree contents, and the new branch
1099 is done, and you will be on the new branch.
1100 </p>
1101 <div class="paragraph"><p>When a merge conflict happens, the index entries for conflicting
1102 paths are left unmerged, and you need to resolve the conflicts
1103 and mark the resolved paths with <code>git add</code> (or <code>git rm</code> if the merge
1104 should result in deletion of the path).</p></div>
1105 <div class="paragraph"><p>When checking out paths from the index, this option lets you recreate
1106 the conflicted merge in the specified paths.</p></div>
1107 <div class="paragraph"><p>When switching branches with <code>--merge</code>, staged changes may be lost.</p></div>
1108 </dd>
1109 <dt class="hdlist1">
1110 --conflict=&lt;style&gt;
1111 </dt>
1112 <dd>
1114 The same as <code>--merge</code> option above, but changes the way the
1115 conflicting hunks are presented, overriding the
1116 <code>merge.conflictStyle</code> configuration variable. Possible values are
1117 "merge" (default), "diff3", and "zdiff3".
1118 </p>
1119 </dd>
1120 <dt class="hdlist1">
1122 </dt>
1123 <dt class="hdlist1">
1124 --patch
1125 </dt>
1126 <dd>
1128 Interactively select hunks in the difference between the
1129 <code>&lt;tree-ish&gt;</code> (or the index, if unspecified) and the working
1130 tree. The chosen hunks are then applied in reverse to the
1131 working tree (and if a <code>&lt;tree-ish&gt;</code> was specified, the index).
1132 </p>
1133 <div class="paragraph"><p>This means that you can use <code>git checkout -p</code> to selectively discard
1134 edits from your current working tree. See the &#8220;Interactive Mode&#8221;
1135 section of <a href="git-add.html">git-add(1)</a> to learn how to operate the <code>--patch</code> mode.</p></div>
1136 <div class="paragraph"><p>Note that this option uses the no overlay mode by default (see also
1137 <code>--overlay</code>), and currently doesn&#8217;t support overlay mode.</p></div>
1138 </dd>
1139 <dt class="hdlist1">
1140 --ignore-other-worktrees
1141 </dt>
1142 <dd>
1144 <code>git checkout</code> refuses when the wanted ref is already checked
1145 out by another worktree. This option makes it check the ref
1146 out anyway. In other words, the ref can be held by more than one
1147 worktree.
1148 </p>
1149 </dd>
1150 <dt class="hdlist1">
1151 --overwrite-ignore
1152 </dt>
1153 <dt class="hdlist1">
1154 --no-overwrite-ignore
1155 </dt>
1156 <dd>
1158 Silently overwrite ignored files when switching branches. This
1159 is the default behavior. Use <code>--no-overwrite-ignore</code> to abort
1160 the operation when the new branch contains ignored files.
1161 </p>
1162 </dd>
1163 <dt class="hdlist1">
1164 --recurse-submodules
1165 </dt>
1166 <dt class="hdlist1">
1167 --no-recurse-submodules
1168 </dt>
1169 <dd>
1171 Using <code>--recurse-submodules</code> will update the content of all active
1172 submodules according to the commit recorded in the superproject. If
1173 local modifications in a submodule would be overwritten the checkout
1174 will fail unless <code>-f</code> is used. If nothing (or <code>--no-recurse-submodules</code>)
1175 is used, submodules working trees will not be updated.
1176 Just like <a href="git-submodule.html">git-submodule(1)</a>, this will detach <code>HEAD</code> of the
1177 submodule.
1178 </p>
1179 </dd>
1180 <dt class="hdlist1">
1181 --overlay
1182 </dt>
1183 <dt class="hdlist1">
1184 --no-overlay
1185 </dt>
1186 <dd>
1188 In the default overlay mode, <code>git checkout</code> never
1189 removes files from the index or the working tree. When
1190 specifying <code>--no-overlay</code>, files that appear in the index and
1191 working tree, but not in <code>&lt;tree-ish&gt;</code> are removed, to make them
1192 match <code>&lt;tree-ish&gt;</code> exactly.
1193 </p>
1194 </dd>
1195 <dt class="hdlist1">
1196 --pathspec-from-file=&lt;file&gt;
1197 </dt>
1198 <dd>
1200 Pathspec is passed in <code>&lt;file&gt;</code> instead of commandline args. If
1201 <code>&lt;file&gt;</code> is exactly <code>-</code> then standard input is used. Pathspec
1202 elements are separated by LF or CR/LF. Pathspec elements can be
1203 quoted as explained for the configuration variable <code>core.quotePath</code>
1204 (see <a href="git-config.html">git-config(1)</a>). See also <code>--pathspec-file-nul</code> and
1205 global <code>--literal-pathspecs</code>.
1206 </p>
1207 </dd>
1208 <dt class="hdlist1">
1209 --pathspec-file-nul
1210 </dt>
1211 <dd>
1213 Only meaningful with <code>--pathspec-from-file</code>. Pathspec elements are
1214 separated with NUL character and all other characters are taken
1215 literally (including newlines and quotes).
1216 </p>
1217 </dd>
1218 <dt class="hdlist1">
1219 &lt;branch&gt;
1220 </dt>
1221 <dd>
1223 Branch to checkout; if it refers to a branch (i.e., a name that,
1224 when prepended with "refs/heads/", is a valid ref), then that
1225 branch is checked out. Otherwise, if it refers to a valid
1226 commit, your <code>HEAD</code> becomes "detached" and you are no longer on
1227 any branch (see below for details).
1228 </p>
1229 <div class="paragraph"><p>You can use the <code>@{-N}</code> syntax to refer to the N-th last
1230 branch/commit checked out using "git checkout" operation. You may
1231 also specify <code>-</code> which is synonymous to <code>@{-1}</code>.</p></div>
1232 <div class="paragraph"><p>As a special case, you may use <code>A...B</code> as a shortcut for the
1233 merge base of <code>A</code> and <code>B</code> if there is exactly one merge base. You can
1234 leave out at most one of <code>A</code> and <code>B</code>, in which case it defaults to <code>HEAD</code>.</p></div>
1235 </dd>
1236 <dt class="hdlist1">
1237 &lt;new-branch&gt;
1238 </dt>
1239 <dd>
1241 Name for the new branch.
1242 </p>
1243 </dd>
1244 <dt class="hdlist1">
1245 &lt;start-point&gt;
1246 </dt>
1247 <dd>
1249 The name of a commit at which to start the new branch; see
1250 <a href="git-branch.html">git-branch(1)</a> for details. Defaults to <code>HEAD</code>.
1251 </p>
1252 <div class="paragraph"><p>As a special case, you may use <code>"A...B"</code> as a shortcut for the
1253 merge base of <code>A</code> and <code>B</code> if there is exactly one merge base. You can
1254 leave out at most one of <code>A</code> and <code>B</code>, in which case it defaults to <code>HEAD</code>.</p></div>
1255 </dd>
1256 <dt class="hdlist1">
1257 &lt;tree-ish&gt;
1258 </dt>
1259 <dd>
1261 Tree to checkout from (when paths are given). If not specified,
1262 the index will be used.
1263 </p>
1264 <div class="paragraph"><p>As a special case, you may use <code>"A...B"</code> as a shortcut for the
1265 merge base of <code>A</code> and <code>B</code> if there is exactly one merge base. You can
1266 leave out at most one of <code>A</code> and <code>B</code>, in which case it defaults to <code>HEAD</code>.</p></div>
1267 </dd>
1268 <dt class="hdlist1">
1270 </dt>
1271 <dd>
1273 Do not interpret any more arguments as options.
1274 </p>
1275 </dd>
1276 <dt class="hdlist1">
1277 &lt;pathspec&gt;&#8230;
1278 </dt>
1279 <dd>
1281 Limits the paths affected by the operation.
1282 </p>
1283 <div class="paragraph"><p>For more details, see the <em>pathspec</em> entry in <a href="gitglossary.html">gitglossary(7)</a>.</p></div>
1284 </dd>
1285 </dl></div>
1286 </div>
1287 </div>
1288 <div class="sect1">
1289 <h2 id="_detached_head">DETACHED HEAD</h2>
1290 <div class="sectionbody">
1291 <div class="paragraph"><p><code>HEAD</code> normally refers to a named branch (e.g. <code>master</code>). Meanwhile, each
1292 branch refers to a specific commit. Let&#8217;s look at a repo with three
1293 commits, one of them tagged, and with branch <code>master</code> checked out:</p></div>
1294 <div class="listingblock">
1295 <div class="content">
1296 <pre><code> HEAD (refers to branch 'master')
1299 a---b---c branch 'master' (refers to commit 'c')
1302 tag 'v2.0' (refers to commit 'b')</code></pre>
1303 </div></div>
1304 <div class="paragraph"><p>When a commit is created in this state, the branch is updated to refer to
1305 the new commit. Specifically, <em>git commit</em> creates a new commit <code>d</code>, whose
1306 parent is commit <code>c</code>, and then updates branch <code>master</code> to refer to new
1307 commit <code>d</code>. <code>HEAD</code> still refers to branch <code>master</code> and so indirectly now refers
1308 to commit <code>d</code>:</p></div>
1309 <div class="listingblock">
1310 <div class="content">
1311 <pre><code>$ edit; git add; git commit
1313 HEAD (refers to branch 'master')
1316 a---b---c---d branch 'master' (refers to commit 'd')
1319 tag 'v2.0' (refers to commit 'b')</code></pre>
1320 </div></div>
1321 <div class="paragraph"><p>It is sometimes useful to be able to checkout a commit that is not at
1322 the tip of any named branch, or even to create a new commit that is not
1323 referenced by a named branch. Let&#8217;s look at what happens when we
1324 checkout commit <code>b</code> (here we show two ways this may be done):</p></div>
1325 <div class="listingblock">
1326 <div class="content">
1327 <pre><code>$ git checkout v2.0 # or
1328 $ git checkout master^^
1330 HEAD (refers to commit 'b')
1333 a---b---c---d branch 'master' (refers to commit 'd')
1336 tag 'v2.0' (refers to commit 'b')</code></pre>
1337 </div></div>
1338 <div class="paragraph"><p>Notice that regardless of which checkout command we use, <code>HEAD</code> now refers
1339 directly to commit <code>b</code>. This is known as being in detached <code>HEAD</code> state.
1340 It means simply that <code>HEAD</code> refers to a specific commit, as opposed to
1341 referring to a named branch. Let&#8217;s see what happens when we create a commit:</p></div>
1342 <div class="listingblock">
1343 <div class="content">
1344 <pre><code>$ edit; git add; git commit
1346 HEAD (refers to commit 'e')
1351 a---b---c---d branch 'master' (refers to commit 'd')
1354 tag 'v2.0' (refers to commit 'b')</code></pre>
1355 </div></div>
1356 <div class="paragraph"><p>There is now a new commit <code>e</code>, but it is referenced only by <code>HEAD</code>. We can
1357 of course add yet another commit in this state:</p></div>
1358 <div class="listingblock">
1359 <div class="content">
1360 <pre><code>$ edit; git add; git commit
1362 HEAD (refers to commit 'f')
1365 e---f
1367 a---b---c---d branch 'master' (refers to commit 'd')
1370 tag 'v2.0' (refers to commit 'b')</code></pre>
1371 </div></div>
1372 <div class="paragraph"><p>In fact, we can perform all the normal Git operations. But, let&#8217;s look
1373 at what happens when we then checkout <code>master</code>:</p></div>
1374 <div class="listingblock">
1375 <div class="content">
1376 <pre><code>$ git checkout master
1378 HEAD (refers to branch 'master')
1379 e---f |
1381 a---b---c---d branch 'master' (refers to commit 'd')
1384 tag 'v2.0' (refers to commit 'b')</code></pre>
1385 </div></div>
1386 <div class="paragraph"><p>It is important to realize that at this point nothing refers to commit
1387 <code>f</code>. Eventually commit <code>f</code> (and by extension commit <code>e</code>) will be deleted
1388 by the routine Git garbage collection process, unless we create a reference
1389 before that happens. If we have not yet moved away from commit <code>f</code>,
1390 any of these will create a reference to it:</p></div>
1391 <div class="listingblock">
1392 <div class="content">
1393 <pre><code>$ git checkout -b foo # or "git switch -c foo" <b>&lt;1&gt;</b>
1394 $ git branch foo <b>&lt;2&gt;</b>
1395 $ git tag foo <b>&lt;3&gt;</b></code></pre>
1396 </div></div>
1397 <div class="colist arabic"><ol>
1398 <li>
1400 creates a new branch <code>foo</code>, which refers to commit <code>f</code>, and then
1401 updates <code>HEAD</code> to refer to branch <code>foo</code>. In other words, we&#8217;ll no longer
1402 be in detached <code>HEAD</code> state after this command.
1403 </p>
1404 </li>
1405 <li>
1407 similarly creates a new branch <code>foo</code>, which refers to commit <code>f</code>,
1408 but leaves <code>HEAD</code> detached.
1409 </p>
1410 </li>
1411 <li>
1413 creates a new tag <code>foo</code>, which refers to commit <code>f</code>,
1414 leaving <code>HEAD</code> detached.
1415 </p>
1416 </li>
1417 </ol></div>
1418 <div class="paragraph"><p>If we have moved away from commit <code>f</code>, then we must first recover its object
1419 name (typically by using git reflog), and then we can create a reference to
1420 it. For example, to see the last two commits to which <code>HEAD</code> referred, we
1421 can use either of these commands:</p></div>
1422 <div class="listingblock">
1423 <div class="content">
1424 <pre><code>$ git reflog -2 HEAD # or
1425 $ git log -g -2 HEAD</code></pre>
1426 </div></div>
1427 </div>
1428 </div>
1429 <div class="sect1">
1430 <h2 id="_argument_disambiguation">ARGUMENT DISAMBIGUATION</h2>
1431 <div class="sectionbody">
1432 <div class="paragraph"><p>When there is only one argument given and it is not <code>--</code> (e.g. <code>git
1433 checkout abc</code>), and when the argument is both a valid <code>&lt;tree-ish&gt;</code>
1434 (e.g. a branch <code>abc</code> exists) and a valid <code>&lt;pathspec&gt;</code> (e.g. a file
1435 or a directory whose name is "abc" exists), Git would usually ask
1436 you to disambiguate. Because checking out a branch is so common an
1437 operation, however, <code>git checkout abc</code> takes "abc" as a <code>&lt;tree-ish&gt;</code>
1438 in such a situation. Use <code>git checkout -- &lt;pathspec&gt;</code> if you want
1439 to checkout these paths out of the index.</p></div>
1440 </div>
1441 </div>
1442 <div class="sect1">
1443 <h2 id="_examples">EXAMPLES</h2>
1444 <div class="sectionbody">
1445 <div class="sect2">
1446 <h3 id="_1_paths">1. Paths</h3>
1447 <div class="paragraph"><p>The following sequence checks out the <code>master</code> branch, reverts
1448 the <code>Makefile</code> to two revisions back, deletes <code>hello.c</code> by
1449 mistake, and gets it back from the index.</p></div>
1450 <div class="listingblock">
1451 <div class="content">
1452 <pre><code>$ git checkout master <b>&lt;1&gt;</b>
1453 $ git checkout master~2 Makefile <b>&lt;2&gt;</b>
1454 $ rm -f hello.c
1455 $ git checkout hello.c <b>&lt;3&gt;</b></code></pre>
1456 </div></div>
1457 <div class="colist arabic"><ol>
1458 <li>
1460 switch branch
1461 </p>
1462 </li>
1463 <li>
1465 take a file out of another commit
1466 </p>
1467 </li>
1468 <li>
1470 restore <code>hello.c</code> from the index
1471 </p>
1472 </li>
1473 </ol></div>
1474 <div class="paragraph"><p>If you want to check out <em>all</em> C source files out of the index,
1475 you can say</p></div>
1476 <div class="listingblock">
1477 <div class="content">
1478 <pre><code>$ git checkout -- '*.c'</code></pre>
1479 </div></div>
1480 <div class="paragraph"><p>Note the quotes around <code>*.c</code>. The file <code>hello.c</code> will also be
1481 checked out, even though it is no longer in the working tree,
1482 because the file globbing is used to match entries in the index
1483 (not in the working tree by the shell).</p></div>
1484 <div class="paragraph"><p>If you have an unfortunate branch that is named <code>hello.c</code>, this
1485 step would be confused as an instruction to switch to that branch.
1486 You should instead write:</p></div>
1487 <div class="listingblock">
1488 <div class="content">
1489 <pre><code>$ git checkout -- hello.c</code></pre>
1490 </div></div>
1491 </div>
1492 <div class="sect2">
1493 <h3 id="_2_merge">2. Merge</h3>
1494 <div class="paragraph"><p>After working in the wrong branch, switching to the correct
1495 branch would be done using:</p></div>
1496 <div class="listingblock">
1497 <div class="content">
1498 <pre><code>$ git checkout mytopic</code></pre>
1499 </div></div>
1500 <div class="paragraph"><p>However, your "wrong" branch and correct <code>mytopic</code> branch may
1501 differ in files that you have modified locally, in which case
1502 the above checkout would fail like this:</p></div>
1503 <div class="listingblock">
1504 <div class="content">
1505 <pre><code>$ git checkout mytopic
1506 error: You have local changes to 'frotz'; not switching branches.</code></pre>
1507 </div></div>
1508 <div class="paragraph"><p>You can give the <code>-m</code> flag to the command, which would try a
1509 three-way merge:</p></div>
1510 <div class="listingblock">
1511 <div class="content">
1512 <pre><code>$ git checkout -m mytopic
1513 Auto-merging frotz</code></pre>
1514 </div></div>
1515 <div class="paragraph"><p>After this three-way merge, the local modifications are <em>not</em>
1516 registered in your index file, so <code>git diff</code> would show you what
1517 changes you made since the tip of the new branch.</p></div>
1518 </div>
1519 <div class="sect2">
1520 <h3 id="_3_merge_conflict">3. Merge conflict</h3>
1521 <div class="paragraph"><p>When a merge conflict happens during switching branches with
1522 the <code>-m</code> option, you would see something like this:</p></div>
1523 <div class="listingblock">
1524 <div class="content">
1525 <pre><code>$ git checkout -m mytopic
1526 Auto-merging frotz
1527 ERROR: Merge conflict in frotz
1528 fatal: merge program failed</code></pre>
1529 </div></div>
1530 <div class="paragraph"><p>At this point, <code>git diff</code> shows the changes cleanly merged as in
1531 the previous example, as well as the changes in the conflicted
1532 files. Edit and resolve the conflict and mark it resolved with
1533 <code>git add</code> as usual:</p></div>
1534 <div class="listingblock">
1535 <div class="content">
1536 <pre><code>$ edit frotz
1537 $ git add frotz</code></pre>
1538 </div></div>
1539 </div>
1540 </div>
1541 </div>
1542 <div class="sect1">
1543 <h2 id="_configuration">CONFIGURATION</h2>
1544 <div class="sectionbody">
1545 <div class="paragraph"><p>Everything below this line in this section is selectively included
1546 from the <a href="git-config.html">git-config(1)</a> documentation. The content is the same
1547 as what&#8217;s found there:</p></div>
1548 <div class="dlist"><dl>
1549 <dt class="hdlist1">
1550 checkout.defaultRemote
1551 </dt>
1552 <dd>
1554 When you run <code>git checkout &lt;something&gt;</code>
1555 or <code>git switch &lt;something&gt;</code> and only have one
1556 remote, it may implicitly fall back on checking out and
1557 tracking e.g. <code>origin/&lt;something&gt;</code>. This stops working as soon
1558 as you have more than one remote with a <code>&lt;something&gt;</code>
1559 reference. This setting allows for setting the name of a
1560 preferred remote that should always win when it comes to
1561 disambiguation. The typical use-case is to set this to
1562 <code>origin</code>.
1563 </p>
1564 <div class="paragraph"><p>Currently this is used by <a href="git-switch.html">git-switch(1)</a> and
1565 <a href="git-checkout.html">git-checkout(1)</a> when <code>git checkout &lt;something&gt;</code>
1566 or <code>git switch &lt;something&gt;</code>
1567 will checkout the <code>&lt;something&gt;</code> branch on another remote,
1568 and by <a href="git-worktree.html">git-worktree(1)</a> when <code>git worktree add</code> refers to a
1569 remote branch. This setting might be used for other checkout-like
1570 commands or functionality in the future.</p></div>
1571 </dd>
1572 <dt class="hdlist1">
1573 checkout.guess
1574 </dt>
1575 <dd>
1577 Provides the default value for the <code>--guess</code> or <code>--no-guess</code>
1578 option in <code>git checkout</code> and <code>git switch</code>. See
1579 <a href="git-switch.html">git-switch(1)</a> and <a href="git-checkout.html">git-checkout(1)</a>.
1580 </p>
1581 </dd>
1582 <dt class="hdlist1">
1583 checkout.workers
1584 </dt>
1585 <dd>
1587 The number of parallel workers to use when updating the working tree.
1588 The default is one, i.e. sequential execution. If set to a value less
1589 than one, Git will use as many workers as the number of logical cores
1590 available. This setting and <code>checkout.thresholdForParallelism</code> affect
1591 all commands that perform checkout. E.g. checkout, clone, reset,
1592 sparse-checkout, etc.
1593 </p>
1594 <div class="paragraph"><p>Note: parallel checkout usually delivers better performance for repositories
1595 located on SSDs or over NFS. For repositories on spinning disks and/or machines
1596 with a small number of cores, the default sequential checkout often performs
1597 better. The size and compression level of a repository might also influence how
1598 well the parallel version performs.</p></div>
1599 </dd>
1600 <dt class="hdlist1">
1601 checkout.thresholdForParallelism
1602 </dt>
1603 <dd>
1605 When running parallel checkout with a small number of files, the cost
1606 of subprocess spawning and inter-process communication might outweigh
1607 the parallelization gains. This setting allows to define the minimum
1608 number of files for which parallel checkout should be attempted. The
1609 default is 100.
1610 </p>
1611 </dd>
1612 </dl></div>
1613 </div>
1614 </div>
1615 <div class="sect1">
1616 <h2 id="_see_also">SEE ALSO</h2>
1617 <div class="sectionbody">
1618 <div class="paragraph"><p><a href="git-switch.html">git-switch(1)</a>,
1619 <a href="git-restore.html">git-restore(1)</a></p></div>
1620 </div>
1621 </div>
1622 <div class="sect1">
1623 <h2 id="_git">GIT</h2>
1624 <div class="sectionbody">
1625 <div class="paragraph"><p>Part of the <a href="git.html">git(1)</a> suite</p></div>
1626 </div>
1627 </div>
1628 </div>
1629 <div id="footnotes"><hr /></div>
1630 <div id="footer">
1631 <div id="footer-text">
1632 Last updated
1633 2023-04-27 16:21:11 PDT
1634 </div>
1635 </div>
1636 </body>
1637 </html>