Autogenerated HTML docs for v2.42.0-526-g3130c1
[git-htmldocs.git] / git-checkout.html
blobc9d94da280db7ed80400bc981d37441edd636f39
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] &lt;tree-ish&gt; [--] &lt;pathspec&gt;&#8230;
757 <em>git checkout</em> [-f] &lt;tree-ish&gt; --pathspec-from-file=&lt;file&gt; [--pathspec-file-nul]
758 <em>git checkout</em> [-f|--ours|--theirs|-m|--conflict=&lt;style&gt;] [--] &lt;pathspec&gt;&#8230;
759 <em>git checkout</em> [-f|--ours|--theirs|-m|--conflict=&lt;style&gt;] --pathspec-from-file=&lt;file&gt; [--pathspec-file-nul]
760 <em>git checkout</em> (-p|--patch) [&lt;tree-ish&gt;] [--] [&lt;pathspec&gt;&#8230;]</pre>
761 <div class="attribution">
762 </div></div>
763 </div>
764 </div>
765 <div class="sect1">
766 <h2 id="_description">DESCRIPTION</h2>
767 <div class="sectionbody">
768 <div class="paragraph"><p>Updates files in the working tree to match the version in the index
769 or the specified tree. If no pathspec was given, <em>git checkout</em> will
770 also update <code>HEAD</code> to set the specified branch as the current
771 branch.</p></div>
772 <div class="dlist"><dl>
773 <dt class="hdlist1">
774 <em>git checkout</em> [&lt;branch&gt;]
775 </dt>
776 <dd>
778 To prepare for working on <code>&lt;branch&gt;</code>, switch to it by updating
779 the index and the files in the working tree, and by pointing
780 <code>HEAD</code> at the branch. Local modifications to the files in the
781 working tree are kept, so that they can be committed to the
782 <code>&lt;branch&gt;</code>.
783 </p>
784 <div class="paragraph"><p>If <code>&lt;branch&gt;</code> is not found but there does exist a tracking branch in
785 exactly one remote (call it <code>&lt;remote&gt;</code>) with a matching name and
786 <code>--no-guess</code> is not specified, treat as equivalent to</p></div>
787 <div class="listingblock">
788 <div class="content">
789 <pre><code>$ git checkout -b &lt;branch&gt; --track &lt;remote&gt;/&lt;branch&gt;</code></pre>
790 </div></div>
791 <div class="paragraph"><p>You could omit <code>&lt;branch&gt;</code>, in which case the command degenerates to
792 "check out the current branch", which is a glorified no-op with
793 rather expensive side-effects to show only the tracking information,
794 if it exists, for the current branch.</p></div>
795 </dd>
796 <dt class="hdlist1">
797 <em>git checkout</em> -b|-B &lt;new-branch&gt; [&lt;start-point&gt;]
798 </dt>
799 <dd>
801 Specifying <code>-b</code> causes a new branch to be created as if
802 <a href="git-branch.html">git-branch(1)</a> were called and then checked out. In
803 this case you can use the <code>--track</code> or <code>--no-track</code> options,
804 which will be passed to <em>git branch</em>. As a convenience,
805 <code>--track</code> without <code>-b</code> implies branch creation; see the
806 description of <code>--track</code> below.
807 </p>
808 <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
809 is reset. This is the transactional equivalent of</p></div>
810 <div class="listingblock">
811 <div class="content">
812 <pre><code>$ git branch -f &lt;branch&gt; [&lt;start-point&gt;]
813 $ git checkout &lt;branch&gt;</code></pre>
814 </div></div>
815 <div class="paragraph"><p>that is to say, the branch is not reset/created unless "git checkout" is
816 successful.</p></div>
817 </dd>
818 <dt class="hdlist1">
819 <em>git checkout</em> --detach [&lt;branch&gt;]
820 </dt>
821 <dt class="hdlist1">
822 <em>git checkout</em> [--detach] &lt;commit&gt;
823 </dt>
824 <dd>
826 Prepare to work on top of <code>&lt;commit&gt;</code>, by detaching <code>HEAD</code> at it
827 (see "DETACHED HEAD" section), and updating the index and the
828 files in the working tree. Local modifications to the files
829 in the working tree are kept, so that the resulting working
830 tree will be the state recorded in the commit plus the local
831 modifications.
832 </p>
833 <div class="paragraph"><p>When the <code>&lt;commit&gt;</code> argument is a branch name, the <code>--detach</code> option can
834 be used to detach <code>HEAD</code> at the tip of the branch (<code>git checkout
835 &lt;branch&gt;</code> would check out that branch without detaching <code>HEAD</code>).</p></div>
836 <div class="paragraph"><p>Omitting <code>&lt;branch&gt;</code> detaches <code>HEAD</code> at the tip of the current branch.</p></div>
837 </dd>
838 <dt class="hdlist1">
839 <em>git checkout</em> [-f|--ours|--theirs|-m|--conflict=&lt;style&gt;] [&lt;tree-ish&gt;] [--] &lt;pathspec&gt;&#8230;
840 </dt>
841 <dt class="hdlist1">
842 <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]
843 </dt>
844 <dd>
846 Overwrite the contents of the files that match the pathspec.
847 When the <code>&lt;tree-ish&gt;</code> (most often a commit) is not given,
848 overwrite working tree with the contents in the index.
849 When the <code>&lt;tree-ish&gt;</code> is given, overwrite both the index and
850 the working tree with the contents at the <code>&lt;tree-ish&gt;</code>.
851 </p>
852 <div class="paragraph"><p>The index may contain unmerged entries because of a previous failed merge.
853 By default, if you try to check out such an entry from the index, the
854 checkout operation will fail and nothing will be checked out.
855 Using <code>-f</code> will ignore these unmerged entries. The contents from a
856 specific side of the merge can be checked out of the index by
857 using <code>--ours</code> or <code>--theirs</code>. With <code>-m</code>, changes made to the working tree
858 file can be discarded to re-create the original conflicted merge result.</p></div>
859 </dd>
860 <dt class="hdlist1">
861 <em>git checkout</em> (-p|--patch) [&lt;tree-ish&gt;] [--] [&lt;pathspec&gt;&#8230;]
862 </dt>
863 <dd>
865 This is similar to the previous mode, but lets you use the
866 interactive interface to show the "diff" output and choose which
867 hunks to use in the result. See below for the description of
868 <code>--patch</code> option.
869 </p>
870 </dd>
871 </dl></div>
872 </div>
873 </div>
874 <div class="sect1">
875 <h2 id="_options">OPTIONS</h2>
876 <div class="sectionbody">
877 <div class="dlist"><dl>
878 <dt class="hdlist1">
880 </dt>
881 <dt class="hdlist1">
882 --quiet
883 </dt>
884 <dd>
886 Quiet, suppress feedback messages.
887 </p>
888 </dd>
889 <dt class="hdlist1">
890 --progress
891 </dt>
892 <dt class="hdlist1">
893 --no-progress
894 </dt>
895 <dd>
897 Progress status is reported on the standard error stream
898 by default when it is attached to a terminal, unless <code>--quiet</code>
899 is specified. This flag enables progress reporting even if not
900 attached to a terminal, regardless of <code>--quiet</code>.
901 </p>
902 </dd>
903 <dt class="hdlist1">
905 </dt>
906 <dt class="hdlist1">
907 --force
908 </dt>
909 <dd>
911 When switching branches, proceed even if the index or the
912 working tree differs from <code>HEAD</code>, and even if there are untracked
913 files in the way. This is used to throw away local changes and
914 any untracked files or directories that are in the way.
915 </p>
916 <div class="paragraph"><p>When checking out paths from the index, do not fail upon unmerged
917 entries; instead, unmerged entries are ignored.</p></div>
918 </dd>
919 <dt class="hdlist1">
920 --ours
921 </dt>
922 <dt class="hdlist1">
923 --theirs
924 </dt>
925 <dd>
927 When checking out paths from the index, check out stage #2
928 (<em>ours</em>) or #3 (<em>theirs</em>) for unmerged paths.
929 </p>
930 <div class="paragraph"><p>Note that during <code>git rebase</code> and <code>git pull --rebase</code>, <em>ours</em> and
931 <em>theirs</em> may appear swapped; <code>--ours</code> gives the version from the
932 branch the changes are rebased onto, while <code>--theirs</code> gives the
933 version from the branch that holds your work that is being rebased.</p></div>
934 <div class="paragraph"><p>This is because <code>rebase</code> is used in a workflow that treats the
935 history at the remote as the shared canonical one, and treats the
936 work done on the branch you are rebasing as the third-party work to
937 be integrated, and you are temporarily assuming the role of the
938 keeper of the canonical history during the rebase. As the keeper of
939 the canonical history, you need to view the history from the remote
940 as <code>ours</code> (i.e. "our shared canonical history"), while what you did
941 on your side branch as <code>theirs</code> (i.e. "one contributor&#8217;s work on top
942 of it").</p></div>
943 </dd>
944 <dt class="hdlist1">
945 -b &lt;new-branch&gt;
946 </dt>
947 <dd>
949 Create a new branch named <code>&lt;new-branch&gt;</code>, start it at
950 <code>&lt;start-point&gt;</code>, and check the resulting branch out;
951 see <a href="git-branch.html">git-branch(1)</a> for details.
952 </p>
953 </dd>
954 <dt class="hdlist1">
955 -B &lt;new-branch&gt;
956 </dt>
957 <dd>
959 Creates the branch <code>&lt;new-branch&gt;</code>, start it at <code>&lt;start-point&gt;</code>;
960 if it already exists, then reset it to <code>&lt;start-point&gt;</code>. And then
961 check the resulting branch out. This is equivalent to running
962 "git branch" with "-f" followed by "git checkout" of that branch;
963 see <a href="git-branch.html">git-branch(1)</a> for details.
964 </p>
965 </dd>
966 <dt class="hdlist1">
968 </dt>
969 <dt class="hdlist1">
970 --track[=(direct|inherit)]
971 </dt>
972 <dd>
974 When creating a new branch, set up "upstream" configuration. See
975 "--track" in <a href="git-branch.html">git-branch(1)</a> for details.
976 </p>
977 <div class="paragraph"><p>If no <code>-b</code> option is given, the name of the new branch will be
978 derived from the remote-tracking branch, by looking at the local part of
979 the refspec configured for the corresponding remote, and then stripping
980 the initial part up to the "*".
981 This would tell us to use <code>hack</code> as the local branch when branching
982 off of <code>origin/hack</code> (or <code>remotes/origin/hack</code>, or even
983 <code>refs/remotes/origin/hack</code>). If the given name has no slash, or the above
984 guessing results in an empty name, the guessing is aborted. You can
985 explicitly give a name with <code>-b</code> in such a case.</p></div>
986 </dd>
987 <dt class="hdlist1">
988 --no-track
989 </dt>
990 <dd>
992 Do not set up "upstream" configuration, even if the
993 <code>branch.autoSetupMerge</code> configuration variable is true.
994 </p>
995 </dd>
996 <dt class="hdlist1">
997 --guess
998 </dt>
999 <dt class="hdlist1">
1000 --no-guess
1001 </dt>
1002 <dd>
1004 If <code>&lt;branch&gt;</code> is not found but there does exist a tracking
1005 branch in exactly one remote (call it <code>&lt;remote&gt;</code>) with a
1006 matching name, treat as equivalent to
1007 </p>
1008 <div class="listingblock">
1009 <div class="content">
1010 <pre><code>$ git checkout -b &lt;branch&gt; --track &lt;remote&gt;/&lt;branch&gt;</code></pre>
1011 </div></div>
1012 <div class="paragraph"><p>If the branch exists in multiple remotes and one of them is named by
1013 the <code>checkout.defaultRemote</code> configuration variable, we&#8217;ll use that
1014 one for the purposes of disambiguation, even if the <code>&lt;branch&gt;</code> isn&#8217;t
1015 unique across all remotes. Set it to
1016 e.g. <code>checkout.defaultRemote=origin</code> to always checkout remote
1017 branches from there if <code>&lt;branch&gt;</code> is ambiguous but exists on the
1018 <em>origin</em> remote. See also <code>checkout.defaultRemote</code> in
1019 <a href="git-config.html">git-config(1)</a>.</p></div>
1020 <div class="paragraph"><p><code>--guess</code> is the default behavior. Use <code>--no-guess</code> to disable it.</p></div>
1021 <div class="paragraph"><p>The default behavior can be set via the <code>checkout.guess</code> configuration
1022 variable.</p></div>
1023 </dd>
1024 <dt class="hdlist1">
1026 </dt>
1027 <dd>
1029 Create the new branch&#8217;s reflog; see <a href="git-branch.html">git-branch(1)</a> for
1030 details.
1031 </p>
1032 </dd>
1033 <dt class="hdlist1">
1035 </dt>
1036 <dt class="hdlist1">
1037 --detach
1038 </dt>
1039 <dd>
1041 Rather than checking out a branch to work on it, check out a
1042 commit for inspection and discardable experiments.
1043 This is the default behavior of <code>git checkout &lt;commit&gt;</code> when
1044 <code>&lt;commit&gt;</code> is not a branch name. See the "DETACHED HEAD" section
1045 below for details.
1046 </p>
1047 </dd>
1048 <dt class="hdlist1">
1049 --orphan &lt;new-branch&gt;
1050 </dt>
1051 <dd>
1053 Create a new <em>orphan</em> branch, named <code>&lt;new-branch&gt;</code>, started from
1054 <code>&lt;start-point&gt;</code> and switch to it. The first commit made on this
1055 new branch will have no parents and it will be the root of a new
1056 history totally disconnected from all the other branches and
1057 commits.
1058 </p>
1059 <div class="paragraph"><p>The index and the working tree are adjusted as if you had previously run
1060 <code>git checkout &lt;start-point&gt;</code>. This allows you to start a new history
1061 that records a set of paths similar to <code>&lt;start-point&gt;</code> by easily running
1062 <code>git commit -a</code> to make the root commit.</p></div>
1063 <div class="paragraph"><p>This can be useful when you want to publish the tree from a commit
1064 without exposing its full history. You might want to do this to publish
1065 an open source branch of a project whose current tree is "clean", but
1066 whose full history contains proprietary or otherwise encumbered bits of
1067 code.</p></div>
1068 <div class="paragraph"><p>If you want to start a disconnected history that records a set of paths
1069 that is totally different from the one of <code>&lt;start-point&gt;</code>, then you should
1070 clear the index and the working tree right after creating the orphan
1071 branch by running <code>git rm -rf .</code> from the top level of the working tree.
1072 Afterwards you will be ready to prepare your new files, repopulating the
1073 working tree, by copying them from elsewhere, extracting a tarball, etc.</p></div>
1074 </dd>
1075 <dt class="hdlist1">
1076 --ignore-skip-worktree-bits
1077 </dt>
1078 <dd>
1080 In sparse checkout mode, <code>git checkout -- &lt;paths&gt;</code> would
1081 update only entries matched by <code>&lt;paths&gt;</code> and sparse patterns
1082 in <code>$GIT_DIR/info/sparse-checkout</code>. This option ignores
1083 the sparse patterns and adds back any files in <code>&lt;paths&gt;</code>.
1084 </p>
1085 </dd>
1086 <dt class="hdlist1">
1088 </dt>
1089 <dt class="hdlist1">
1090 --merge
1091 </dt>
1092 <dd>
1094 When switching branches,
1095 if you have local modifications to one or more files that
1096 are different between the current branch and the branch to
1097 which you are switching, the command refuses to switch
1098 branches in order to preserve your modifications in context.
1099 However, with this option, a three-way merge between the current
1100 branch, your working tree contents, and the new branch
1101 is done, and you will be on the new branch.
1102 </p>
1103 <div class="paragraph"><p>When a merge conflict happens, the index entries for conflicting
1104 paths are left unmerged, and you need to resolve the conflicts
1105 and mark the resolved paths with <code>git add</code> (or <code>git rm</code> if the merge
1106 should result in deletion of the path).</p></div>
1107 <div class="paragraph"><p>When checking out paths from the index, this option lets you recreate
1108 the conflicted merge in the specified paths. This option cannot be
1109 used when checking out paths from a tree-ish.</p></div>
1110 <div class="paragraph"><p>When switching branches with <code>--merge</code>, staged changes may be lost.</p></div>
1111 </dd>
1112 <dt class="hdlist1">
1113 --conflict=&lt;style&gt;
1114 </dt>
1115 <dd>
1117 The same as <code>--merge</code> option above, but changes the way the
1118 conflicting hunks are presented, overriding the
1119 <code>merge.conflictStyle</code> configuration variable. Possible values are
1120 "merge" (default), "diff3", and "zdiff3".
1121 </p>
1122 </dd>
1123 <dt class="hdlist1">
1125 </dt>
1126 <dt class="hdlist1">
1127 --patch
1128 </dt>
1129 <dd>
1131 Interactively select hunks in the difference between the
1132 <code>&lt;tree-ish&gt;</code> (or the index, if unspecified) and the working
1133 tree. The chosen hunks are then applied in reverse to the
1134 working tree (and if a <code>&lt;tree-ish&gt;</code> was specified, the index).
1135 </p>
1136 <div class="paragraph"><p>This means that you can use <code>git checkout -p</code> to selectively discard
1137 edits from your current working tree. See the &#8220;Interactive Mode&#8221;
1138 section of <a href="git-add.html">git-add(1)</a> to learn how to operate the <code>--patch</code> mode.</p></div>
1139 <div class="paragraph"><p>Note that this option uses the no overlay mode by default (see also
1140 <code>--overlay</code>), and currently doesn&#8217;t support overlay mode.</p></div>
1141 </dd>
1142 <dt class="hdlist1">
1143 --ignore-other-worktrees
1144 </dt>
1145 <dd>
1147 <code>git checkout</code> refuses when the wanted ref is already checked
1148 out by another worktree. This option makes it check the ref
1149 out anyway. In other words, the ref can be held by more than one
1150 worktree.
1151 </p>
1152 </dd>
1153 <dt class="hdlist1">
1154 --overwrite-ignore
1155 </dt>
1156 <dt class="hdlist1">
1157 --no-overwrite-ignore
1158 </dt>
1159 <dd>
1161 Silently overwrite ignored files when switching branches. This
1162 is the default behavior. Use <code>--no-overwrite-ignore</code> to abort
1163 the operation when the new branch contains ignored files.
1164 </p>
1165 </dd>
1166 <dt class="hdlist1">
1167 --recurse-submodules
1168 </dt>
1169 <dt class="hdlist1">
1170 --no-recurse-submodules
1171 </dt>
1172 <dd>
1174 Using <code>--recurse-submodules</code> will update the content of all active
1175 submodules according to the commit recorded in the superproject. If
1176 local modifications in a submodule would be overwritten the checkout
1177 will fail unless <code>-f</code> is used. If nothing (or <code>--no-recurse-submodules</code>)
1178 is used, submodules working trees will not be updated.
1179 Just like <a href="git-submodule.html">git-submodule(1)</a>, this will detach <code>HEAD</code> of the
1180 submodule.
1181 </p>
1182 </dd>
1183 <dt class="hdlist1">
1184 --overlay
1185 </dt>
1186 <dt class="hdlist1">
1187 --no-overlay
1188 </dt>
1189 <dd>
1191 In the default overlay mode, <code>git checkout</code> never
1192 removes files from the index or the working tree. When
1193 specifying <code>--no-overlay</code>, files that appear in the index and
1194 working tree, but not in <code>&lt;tree-ish&gt;</code> are removed, to make them
1195 match <code>&lt;tree-ish&gt;</code> exactly.
1196 </p>
1197 </dd>
1198 <dt class="hdlist1">
1199 --pathspec-from-file=&lt;file&gt;
1200 </dt>
1201 <dd>
1203 Pathspec is passed in <code>&lt;file&gt;</code> instead of commandline args. If
1204 <code>&lt;file&gt;</code> is exactly <code>-</code> then standard input is used. Pathspec
1205 elements are separated by LF or CR/LF. Pathspec elements can be
1206 quoted as explained for the configuration variable <code>core.quotePath</code>
1207 (see <a href="git-config.html">git-config(1)</a>). See also <code>--pathspec-file-nul</code> and
1208 global <code>--literal-pathspecs</code>.
1209 </p>
1210 </dd>
1211 <dt class="hdlist1">
1212 --pathspec-file-nul
1213 </dt>
1214 <dd>
1216 Only meaningful with <code>--pathspec-from-file</code>. Pathspec elements are
1217 separated with NUL character and all other characters are taken
1218 literally (including newlines and quotes).
1219 </p>
1220 </dd>
1221 <dt class="hdlist1">
1222 &lt;branch&gt;
1223 </dt>
1224 <dd>
1226 Branch to checkout; if it refers to a branch (i.e., a name that,
1227 when prepended with "refs/heads/", is a valid ref), then that
1228 branch is checked out. Otherwise, if it refers to a valid
1229 commit, your <code>HEAD</code> becomes "detached" and you are no longer on
1230 any branch (see below for details).
1231 </p>
1232 <div class="paragraph"><p>You can use the <code>@{-N}</code> syntax to refer to the N-th last
1233 branch/commit checked out using "git checkout" operation. You may
1234 also specify <code>-</code> which is synonymous to <code>@{-1}</code>.</p></div>
1235 <div class="paragraph"><p>As a special case, you may use <code>A...B</code> as a shortcut for the
1236 merge base of <code>A</code> and <code>B</code> if there is exactly one merge base. You can
1237 leave out at most one of <code>A</code> and <code>B</code>, in which case it defaults to <code>HEAD</code>.</p></div>
1238 </dd>
1239 <dt class="hdlist1">
1240 &lt;new-branch&gt;
1241 </dt>
1242 <dd>
1244 Name for the new branch.
1245 </p>
1246 </dd>
1247 <dt class="hdlist1">
1248 &lt;start-point&gt;
1249 </dt>
1250 <dd>
1252 The name of a commit at which to start the new branch; see
1253 <a href="git-branch.html">git-branch(1)</a> for details. Defaults to <code>HEAD</code>.
1254 </p>
1255 <div class="paragraph"><p>As a special case, you may use <code>"A...B"</code> as a shortcut for the
1256 merge base of <code>A</code> and <code>B</code> if there is exactly one merge base. You can
1257 leave out at most one of <code>A</code> and <code>B</code>, in which case it defaults to <code>HEAD</code>.</p></div>
1258 </dd>
1259 <dt class="hdlist1">
1260 &lt;tree-ish&gt;
1261 </dt>
1262 <dd>
1264 Tree to checkout from (when paths are given). If not specified,
1265 the index will be used.
1266 </p>
1267 <div class="paragraph"><p>As a special case, you may use <code>"A...B"</code> as a shortcut for the
1268 merge base of <code>A</code> and <code>B</code> if there is exactly one merge base. You can
1269 leave out at most one of <code>A</code> and <code>B</code>, in which case it defaults to <code>HEAD</code>.</p></div>
1270 </dd>
1271 <dt class="hdlist1">
1273 </dt>
1274 <dd>
1276 Do not interpret any more arguments as options.
1277 </p>
1278 </dd>
1279 <dt class="hdlist1">
1280 &lt;pathspec&gt;&#8230;
1281 </dt>
1282 <dd>
1284 Limits the paths affected by the operation.
1285 </p>
1286 <div class="paragraph"><p>For more details, see the <em>pathspec</em> entry in <a href="gitglossary.html">gitglossary(7)</a>.</p></div>
1287 </dd>
1288 </dl></div>
1289 </div>
1290 </div>
1291 <div class="sect1">
1292 <h2 id="_detached_head">DETACHED HEAD</h2>
1293 <div class="sectionbody">
1294 <div class="paragraph"><p><code>HEAD</code> normally refers to a named branch (e.g. <code>master</code>). Meanwhile, each
1295 branch refers to a specific commit. Let&#8217;s look at a repo with three
1296 commits, one of them tagged, and with branch <code>master</code> checked out:</p></div>
1297 <div class="listingblock">
1298 <div class="content">
1299 <pre><code> HEAD (refers to branch 'master')
1302 a---b---c branch 'master' (refers to commit 'c')
1305 tag 'v2.0' (refers to commit 'b')</code></pre>
1306 </div></div>
1307 <div class="paragraph"><p>When a commit is created in this state, the branch is updated to refer to
1308 the new commit. Specifically, <em>git commit</em> creates a new commit <code>d</code>, whose
1309 parent is commit <code>c</code>, and then updates branch <code>master</code> to refer to new
1310 commit <code>d</code>. <code>HEAD</code> still refers to branch <code>master</code> and so indirectly now refers
1311 to commit <code>d</code>:</p></div>
1312 <div class="listingblock">
1313 <div class="content">
1314 <pre><code>$ edit; git add; git commit
1316 HEAD (refers to branch 'master')
1319 a---b---c---d branch 'master' (refers to commit 'd')
1322 tag 'v2.0' (refers to commit 'b')</code></pre>
1323 </div></div>
1324 <div class="paragraph"><p>It is sometimes useful to be able to checkout a commit that is not at
1325 the tip of any named branch, or even to create a new commit that is not
1326 referenced by a named branch. Let&#8217;s look at what happens when we
1327 checkout commit <code>b</code> (here we show two ways this may be done):</p></div>
1328 <div class="listingblock">
1329 <div class="content">
1330 <pre><code>$ git checkout v2.0 # or
1331 $ git checkout master^^
1333 HEAD (refers to commit 'b')
1336 a---b---c---d branch 'master' (refers to commit 'd')
1339 tag 'v2.0' (refers to commit 'b')</code></pre>
1340 </div></div>
1341 <div class="paragraph"><p>Notice that regardless of which checkout command we use, <code>HEAD</code> now refers
1342 directly to commit <code>b</code>. This is known as being in detached <code>HEAD</code> state.
1343 It means simply that <code>HEAD</code> refers to a specific commit, as opposed to
1344 referring to a named branch. Let&#8217;s see what happens when we create a commit:</p></div>
1345 <div class="listingblock">
1346 <div class="content">
1347 <pre><code>$ edit; git add; git commit
1349 HEAD (refers to commit 'e')
1354 a---b---c---d branch 'master' (refers to commit 'd')
1357 tag 'v2.0' (refers to commit 'b')</code></pre>
1358 </div></div>
1359 <div class="paragraph"><p>There is now a new commit <code>e</code>, but it is referenced only by <code>HEAD</code>. We can
1360 of course add yet another commit in this state:</p></div>
1361 <div class="listingblock">
1362 <div class="content">
1363 <pre><code>$ edit; git add; git commit
1365 HEAD (refers to commit 'f')
1368 e---f
1370 a---b---c---d branch 'master' (refers to commit 'd')
1373 tag 'v2.0' (refers to commit 'b')</code></pre>
1374 </div></div>
1375 <div class="paragraph"><p>In fact, we can perform all the normal Git operations. But, let&#8217;s look
1376 at what happens when we then checkout <code>master</code>:</p></div>
1377 <div class="listingblock">
1378 <div class="content">
1379 <pre><code>$ git checkout master
1381 HEAD (refers to branch 'master')
1382 e---f |
1384 a---b---c---d branch 'master' (refers to commit 'd')
1387 tag 'v2.0' (refers to commit 'b')</code></pre>
1388 </div></div>
1389 <div class="paragraph"><p>It is important to realize that at this point nothing refers to commit
1390 <code>f</code>. Eventually commit <code>f</code> (and by extension commit <code>e</code>) will be deleted
1391 by the routine Git garbage collection process, unless we create a reference
1392 before that happens. If we have not yet moved away from commit <code>f</code>,
1393 any of these will create a reference to it:</p></div>
1394 <div class="listingblock">
1395 <div class="content">
1396 <pre><code>$ git checkout -b foo # or "git switch -c foo" <b>&lt;1&gt;</b>
1397 $ git branch foo <b>&lt;2&gt;</b>
1398 $ git tag foo <b>&lt;3&gt;</b></code></pre>
1399 </div></div>
1400 <div class="colist arabic"><ol>
1401 <li>
1403 creates a new branch <code>foo</code>, which refers to commit <code>f</code>, and then
1404 updates <code>HEAD</code> to refer to branch <code>foo</code>. In other words, we&#8217;ll no longer
1405 be in detached <code>HEAD</code> state after this command.
1406 </p>
1407 </li>
1408 <li>
1410 similarly creates a new branch <code>foo</code>, which refers to commit <code>f</code>,
1411 but leaves <code>HEAD</code> detached.
1412 </p>
1413 </li>
1414 <li>
1416 creates a new tag <code>foo</code>, which refers to commit <code>f</code>,
1417 leaving <code>HEAD</code> detached.
1418 </p>
1419 </li>
1420 </ol></div>
1421 <div class="paragraph"><p>If we have moved away from commit <code>f</code>, then we must first recover its object
1422 name (typically by using git reflog), and then we can create a reference to
1423 it. For example, to see the last two commits to which <code>HEAD</code> referred, we
1424 can use either of these commands:</p></div>
1425 <div class="listingblock">
1426 <div class="content">
1427 <pre><code>$ git reflog -2 HEAD # or
1428 $ git log -g -2 HEAD</code></pre>
1429 </div></div>
1430 </div>
1431 </div>
1432 <div class="sect1">
1433 <h2 id="_argument_disambiguation">ARGUMENT DISAMBIGUATION</h2>
1434 <div class="sectionbody">
1435 <div class="paragraph"><p>When there is only one argument given and it is not <code>--</code> (e.g. <code>git
1436 checkout abc</code>), and when the argument is both a valid <code>&lt;tree-ish&gt;</code>
1437 (e.g. a branch <code>abc</code> exists) and a valid <code>&lt;pathspec&gt;</code> (e.g. a file
1438 or a directory whose name is "abc" exists), Git would usually ask
1439 you to disambiguate. Because checking out a branch is so common an
1440 operation, however, <code>git checkout abc</code> takes "abc" as a <code>&lt;tree-ish&gt;</code>
1441 in such a situation. Use <code>git checkout -- &lt;pathspec&gt;</code> if you want
1442 to checkout these paths out of the index.</p></div>
1443 </div>
1444 </div>
1445 <div class="sect1">
1446 <h2 id="_examples">EXAMPLES</h2>
1447 <div class="sectionbody">
1448 <div class="sect2">
1449 <h3 id="_1_paths">1. Paths</h3>
1450 <div class="paragraph"><p>The following sequence checks out the <code>master</code> branch, reverts
1451 the <code>Makefile</code> to two revisions back, deletes <code>hello.c</code> by
1452 mistake, and gets it back from the index.</p></div>
1453 <div class="listingblock">
1454 <div class="content">
1455 <pre><code>$ git checkout master <b>&lt;1&gt;</b>
1456 $ git checkout master~2 Makefile <b>&lt;2&gt;</b>
1457 $ rm -f hello.c
1458 $ git checkout hello.c <b>&lt;3&gt;</b></code></pre>
1459 </div></div>
1460 <div class="colist arabic"><ol>
1461 <li>
1463 switch branch
1464 </p>
1465 </li>
1466 <li>
1468 take a file out of another commit
1469 </p>
1470 </li>
1471 <li>
1473 restore <code>hello.c</code> from the index
1474 </p>
1475 </li>
1476 </ol></div>
1477 <div class="paragraph"><p>If you want to check out <em>all</em> C source files out of the index,
1478 you can say</p></div>
1479 <div class="listingblock">
1480 <div class="content">
1481 <pre><code>$ git checkout -- '*.c'</code></pre>
1482 </div></div>
1483 <div class="paragraph"><p>Note the quotes around <code>*.c</code>. The file <code>hello.c</code> will also be
1484 checked out, even though it is no longer in the working tree,
1485 because the file globbing is used to match entries in the index
1486 (not in the working tree by the shell).</p></div>
1487 <div class="paragraph"><p>If you have an unfortunate branch that is named <code>hello.c</code>, this
1488 step would be confused as an instruction to switch to that branch.
1489 You should instead write:</p></div>
1490 <div class="listingblock">
1491 <div class="content">
1492 <pre><code>$ git checkout -- hello.c</code></pre>
1493 </div></div>
1494 </div>
1495 <div class="sect2">
1496 <h3 id="_2_merge">2. Merge</h3>
1497 <div class="paragraph"><p>After working in the wrong branch, switching to the correct
1498 branch would be done using:</p></div>
1499 <div class="listingblock">
1500 <div class="content">
1501 <pre><code>$ git checkout mytopic</code></pre>
1502 </div></div>
1503 <div class="paragraph"><p>However, your "wrong" branch and correct <code>mytopic</code> branch may
1504 differ in files that you have modified locally, in which case
1505 the above checkout would fail like this:</p></div>
1506 <div class="listingblock">
1507 <div class="content">
1508 <pre><code>$ git checkout mytopic
1509 error: You have local changes to 'frotz'; not switching branches.</code></pre>
1510 </div></div>
1511 <div class="paragraph"><p>You can give the <code>-m</code> flag to the command, which would try a
1512 three-way merge:</p></div>
1513 <div class="listingblock">
1514 <div class="content">
1515 <pre><code>$ git checkout -m mytopic
1516 Auto-merging frotz</code></pre>
1517 </div></div>
1518 <div class="paragraph"><p>After this three-way merge, the local modifications are <em>not</em>
1519 registered in your index file, so <code>git diff</code> would show you what
1520 changes you made since the tip of the new branch.</p></div>
1521 </div>
1522 <div class="sect2">
1523 <h3 id="_3_merge_conflict">3. Merge conflict</h3>
1524 <div class="paragraph"><p>When a merge conflict happens during switching branches with
1525 the <code>-m</code> option, you would see something like this:</p></div>
1526 <div class="listingblock">
1527 <div class="content">
1528 <pre><code>$ git checkout -m mytopic
1529 Auto-merging frotz
1530 ERROR: Merge conflict in frotz
1531 fatal: merge program failed</code></pre>
1532 </div></div>
1533 <div class="paragraph"><p>At this point, <code>git diff</code> shows the changes cleanly merged as in
1534 the previous example, as well as the changes in the conflicted
1535 files. Edit and resolve the conflict and mark it resolved with
1536 <code>git add</code> as usual:</p></div>
1537 <div class="listingblock">
1538 <div class="content">
1539 <pre><code>$ edit frotz
1540 $ git add frotz</code></pre>
1541 </div></div>
1542 </div>
1543 </div>
1544 </div>
1545 <div class="sect1">
1546 <h2 id="_configuration">CONFIGURATION</h2>
1547 <div class="sectionbody">
1548 <div class="paragraph"><p>Everything below this line in this section is selectively included
1549 from the <a href="git-config.html">git-config(1)</a> documentation. The content is the same
1550 as what&#8217;s found there:</p></div>
1551 <div class="dlist"><dl>
1552 <dt class="hdlist1">
1553 checkout.defaultRemote
1554 </dt>
1555 <dd>
1557 When you run <code>git checkout &lt;something&gt;</code>
1558 or <code>git switch &lt;something&gt;</code> and only have one
1559 remote, it may implicitly fall back on checking out and
1560 tracking e.g. <code>origin/&lt;something&gt;</code>. This stops working as soon
1561 as you have more than one remote with a <code>&lt;something&gt;</code>
1562 reference. This setting allows for setting the name of a
1563 preferred remote that should always win when it comes to
1564 disambiguation. The typical use-case is to set this to
1565 <code>origin</code>.
1566 </p>
1567 <div class="paragraph"><p>Currently this is used by <a href="git-switch.html">git-switch(1)</a> and
1568 <a href="git-checkout.html">git-checkout(1)</a> when <code>git checkout &lt;something&gt;</code>
1569 or <code>git switch &lt;something&gt;</code>
1570 will checkout the <code>&lt;something&gt;</code> branch on another remote,
1571 and by <a href="git-worktree.html">git-worktree(1)</a> when <code>git worktree add</code> refers to a
1572 remote branch. This setting might be used for other checkout-like
1573 commands or functionality in the future.</p></div>
1574 </dd>
1575 <dt class="hdlist1">
1576 checkout.guess
1577 </dt>
1578 <dd>
1580 Provides the default value for the <code>--guess</code> or <code>--no-guess</code>
1581 option in <code>git checkout</code> and <code>git switch</code>. See
1582 <a href="git-switch.html">git-switch(1)</a> and <a href="git-checkout.html">git-checkout(1)</a>.
1583 </p>
1584 </dd>
1585 <dt class="hdlist1">
1586 checkout.workers
1587 </dt>
1588 <dd>
1590 The number of parallel workers to use when updating the working tree.
1591 The default is one, i.e. sequential execution. If set to a value less
1592 than one, Git will use as many workers as the number of logical cores
1593 available. This setting and <code>checkout.thresholdForParallelism</code> affect
1594 all commands that perform checkout. E.g. checkout, clone, reset,
1595 sparse-checkout, etc.
1596 </p>
1597 <div class="paragraph"><p>Note: Parallel checkout usually delivers better performance for repositories
1598 located on SSDs or over NFS. For repositories on spinning disks and/or machines
1599 with a small number of cores, the default sequential checkout often performs
1600 better. The size and compression level of a repository might also influence how
1601 well the parallel version performs.</p></div>
1602 </dd>
1603 <dt class="hdlist1">
1604 checkout.thresholdForParallelism
1605 </dt>
1606 <dd>
1608 When running parallel checkout with a small number of files, the cost
1609 of subprocess spawning and inter-process communication might outweigh
1610 the parallelization gains. This setting allows you to define the minimum
1611 number of files for which parallel checkout should be attempted. The
1612 default is 100.
1613 </p>
1614 </dd>
1615 </dl></div>
1616 </div>
1617 </div>
1618 <div class="sect1">
1619 <h2 id="_see_also">SEE ALSO</h2>
1620 <div class="sectionbody">
1621 <div class="paragraph"><p><a href="git-switch.html">git-switch(1)</a>,
1622 <a href="git-restore.html">git-restore(1)</a></p></div>
1623 </div>
1624 </div>
1625 <div class="sect1">
1626 <h2 id="_git">GIT</h2>
1627 <div class="sectionbody">
1628 <div class="paragraph"><p>Part of the <a href="git.html">git(1)</a> suite</p></div>
1629 </div>
1630 </div>
1631 </div>
1632 <div id="footnotes"><hr /></div>
1633 <div id="footer">
1634 <div id="footer-text">
1635 Last updated
1636 2023-10-24 06:43:46 JST
1637 </div>
1638 </div>
1639 </body>
1640 </html>