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