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">
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 */
14 font-family: Georgia,serif;
18 h1, h2, h3, h4, h5, h6,
19 div.title, caption.title,
20 thead, p.table.header,
22 #author, #revnumber, #revdate, #revremark,
24 font-family: Arial,Helvetica,sans-serif;
28 margin:
1em
5%
1em
5%;
33 text-decoration: underline;
49 h1, h2, h3, h4, h5, h6 {
57 border-bottom:
2px solid silver;
77 border:
1px solid silver;
88 ul
> li { color: #aaa; }
89 ul
> li
> * { color: black; }
91 .monospaced, code, pre {
92 font-family:
"Courier New", Courier, monospace;
99 white-space: pre-wrap;
109 #revnumber, #revdate, #revremark {
114 border-top:
2px solid silver;
120 padding-bottom:
0.5em;
124 padding-bottom:
0.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 {
135 margin-bottom:
1.5em;
137 div.admonitionblock {
139 margin-bottom:
2.0em;
144 div.content { /* Block element content. */
148 /* Block element titles. */
149 div.title, caption.title {
154 margin-bottom:
0.5em;
160 td div.title:first-child {
163 div.content div.title:first-child {
166 div.content + div.title {
170 div.sidebarblock
> div.content {
172 border:
1px solid #dddddd;
173 border-left:
4px solid #f0f0f0;
177 div.listingblock
> div.content {
178 border:
1px solid #dddddd;
179 border-left:
5px solid #f0f0f0;
184 div.quoteblock, div.verseblock {
188 border-left:
5px solid #f0f0f0;
192 div.quoteblock
> div.attribution {
197 div.verseblock
> pre.content {
198 font-family: inherit;
201 div.verseblock
> div.attribution {
205 /* DEPRECATED: Pre version
8.2.7 verse style literal block. */
206 div.verseblock + div.attribution {
210 div.admonitionblock .icon {
214 text-decoration: underline;
216 padding-right:
0.5em;
218 div.admonitionblock td.content {
220 border-left:
3px solid #dddddd;
223 div.exampleblock
> div.content {
224 border-left:
3px solid #dddddd;
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; }
234 margin-bottom:
0.8em;
247 list-style-position: outside;
250 list-style-type: decimal;
253 list-style-type: lower-alpha;
256 list-style-type: upper-alpha;
259 list-style-type: lower-roman;
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 {
269 margin-bottom:
0.1em;
281 margin-bottom:
0.8em;
284 padding-bottom:
15px;
286 dt.hdlist1.strong, td.hdlist1.strong {
292 padding-right:
0.8em;
298 div.hdlist.compact tr {
307 .footnote, .footnoteref {
311 span.footnote, span.footnoteref {
312 vertical-align: super;
316 margin:
20px
0 20px
0;
320 #footnotes div.footnote {
326 border-top:
1px solid silver;
335 padding-right:
0.5em;
336 padding-bottom:
0.3em;
344 #footer-badges { display: none; }
348 margin-bottom:
2.5em;
356 margin-bottom:
0.1em;
359 div.toclevel0, div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
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; }
427 margin-bottom:
1.5em;
429 div.tableblock
> table {
430 border:
3px solid #
527bbd;
432 thead, p.table.header {
439 /* Because the table frame attribute is overridden by CSS in most browsers. */
440 div.tableblock
> table[
frame=
"void"] {
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;
460 margin-bottom:
1.5em;
462 thead, p.tableblock.header {
473 border-color: #
527bbd;
474 border-collapse: collapse;
476 th.tableblock, td.tableblock {
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 {
498 th.tableblock.halign-center, td.tableblock.halign-center {
501 th.tableblock.halign-right, td.tableblock.halign-right {
505 th.tableblock.valign-top, td.tableblock.valign-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;
523 padding-bottom:
0.5em;
524 border-top:
2px solid silver;
525 border-bottom:
2px solid silver;
530 body.manpage div.sectionbody {
535 body.manpage div#toc { display: none; }
540 <script type=
"text/javascript">
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
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 */
562 toc: function (toclevels) {
564 function getText(el) {
566 for (var i = el.firstChild; i != null; i = i.nextSibling) {
567 if (i.nodeType ==
3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
569 else if (i.firstChild != null)
575 function TocEntry(el, text, toclevel) {
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
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);
602 var toc = document.getElementById(
"toc");
607 // Delete existing TOC entries in case we're reloading the TOC.
608 var tocEntriesToRemove = [];
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");
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.
651 var noteholder = document.getElementById(
"footnotes");
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");
670 for (i=
0; i
<spans.length; i++) {
671 if (spans[i].className ==
"footnote") {
673 var note = spans[i].getAttribute(
"data-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];
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;
692 noteholder.parentNode.removeChild(noteholder);
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.
701 "[<a href='#_footnote_" + n +
702 "' title='View footnote' class='footnote'>" + n +
"</a>]";
708 install: function(toclevels) {
711 function reinstall() {
712 asciidoc.footnotes();
714 asciidoc.toc(toclevels);
718 function reinstallAndRemoveTimer() {
719 clearInterval(timerId);
723 timerId = setInterval(reinstall,
500);
724 if (document.addEventListener)
725 document.addEventListener(
"DOMContentLoaded", reinstallAndRemoveTimer, false);
727 window.onload = reinstallAndRemoveTimer;
735 <body class=
"manpage">
738 git-checkout(
1) Manual Page
741 <div class=
"sectionbody">
743 Switch branches or restore working tree files
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] [
<branch
>]
753 <em>git checkout
</em> [-q] [-f] [-m] --detach [
<branch
>]
754 <em>git checkout
</em> [-q] [-f] [-m] [--detach]
<commit
>
755 <em>git checkout
</em> [-q] [-f] [-m] [[-b|-B|--orphan]
<new-branch
>] [
<start-point
>]
756 <em>git checkout
</em> [-f]
<tree-ish
> [--]
<pathspec
>…
757 <em>git checkout
</em> [-f]
<tree-ish
> --pathspec-from-file=
<file
> [--pathspec-file-nul]
758 <em>git checkout
</em> [-f|--ours|--theirs|-m|--conflict=
<style
>] [--]
<pathspec
>…
759 <em>git checkout
</em> [-f|--ours|--theirs|-m|--conflict=
<style
>] --pathspec-from-file=
<file
> [--pathspec-file-nul]
760 <em>git checkout
</em> (-p|--patch) [
<tree-ish
>] [--] [
<pathspec
>…]
</pre>
761 <div class=
"attribution">
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
772 <div class=
"dlist"><dl>
774 <em>git checkout
</em> [
<branch
>]
778 To prepare for working on
<code><branch
></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><branch
></code>.
784 <div class=
"paragraph"><p>If
<code><branch
></code> is not found but there does exist a tracking branch in
785 exactly one remote (call it
<code><remote
></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
<branch
> --track
<remote
>/
<branch
></code></pre>
791 <div class=
"paragraph"><p>You could omit
<code><branch
></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 exists, for the current branch.
</p></div>
797 <em>git checkout
</em> -b|-B
<new-branch
> [
<start-point
>]
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.
808 <div class=
"paragraph"><p>If
<code>-B
</code> is given,
<code><new-branch
></code> is created if it doesn
’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
<branch
> [
<start-point
>]
813 $ git checkout
<branch
></code></pre>
815 <div class=
"paragraph"><p>that is to say, the branch is not reset/created unless
"git checkout" is
816 successful.
</p></div>
819 <em>git checkout
</em> --detach [
<branch
>]
822 <em>git checkout
</em> [--detach]
<commit
>
826 Prepare to work on top of
<code><commit
></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
833 <div class=
"paragraph"><p>When the
<code><commit
></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 <branch
></code> would check out that branch without detaching
<code>HEAD
</code>).
</p></div>
836 <div class=
"paragraph"><p>Omitting
<code><branch
></code> detaches
<code>HEAD
</code> at the tip of the current branch.
</p></div>
839 <em>git checkout
</em> [-f|--ours|--theirs|-m|--conflict=
<style
>] [
<tree-ish
>] [--]
<pathspec
>…
842 <em>git checkout
</em> [-f|--ours|--theirs|-m|--conflict=
<style
>] [
<tree-ish
>] --pathspec-from-file=
<file
> [--pathspec-file-nul]
846 Overwrite the contents of the files that match the pathspec.
847 When the
<code><tree-ish
></code> (most often a commit) is not given,
848 overwrite working tree with the contents in the index.
849 When the
<code><tree-ish
></code> is given, overwrite both the index and
850 the working tree with the contents at the
<code><tree-ish
></code>.
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>
861 <em>git checkout
</em> (-p|--patch) [
<tree-ish
>] [--] [
<pathspec
>…]
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.
875 <h2 id=
"_options">OPTIONS
</h2>
876 <div class=
"sectionbody">
877 <div class=
"dlist"><dl>
886 Quiet, suppress feedback messages.
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>.
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.
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>
927 When checking out paths from the index, check out stage #
2
928 (
<em>ours
</em>) or #
3 (
<em>theirs
</em>) for unmerged paths.
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’s work on top
945 -b
<new-branch
>
949 Create a new branch named
<code><new-branch
></code>, start it at
950 <code><start-point
></code>, and check the resulting branch out;
951 see
<a href=
"git-branch.html">git-branch(
1)
</a> for details.
955 -B
<new-branch
>
959 Creates the branch
<code><new-branch
></code>, start it at
<code><start-point
></code>;
960 if it already exists, then reset it to
<code><start-point
></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.
970 --track[=(direct|inherit)]
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.
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>
992 Do not set up
"upstream" configuration, even if the
993 <code>branch.autoSetupMerge
</code> configuration variable is true.
1004 If
<code><branch
></code> is not found but there does exist a tracking
1005 branch in exactly one remote (call it
<code><remote
></code>) with a
1006 matching name, treat as equivalent to
1008 <div class=
"listingblock">
1009 <div class=
"content">
1010 <pre><code>$ git checkout -b
<branch
> --track
<remote
>/
<branch
></code></pre>
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
’ll use that
1014 one for the purposes of disambiguation, even if the
<code><branch
></code> isn
’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><branch
></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
1024 <dt class=
"hdlist1">
1029 Create the new branch
’s reflog; see
<a href=
"git-branch.html">git-branch(
1)
</a> for
1033 <dt class=
"hdlist1">
1036 <dt class=
"hdlist1">
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
<commit
></code> when
1044 <code><commit
></code> is not a branch name. See the
"DETACHED HEAD" section
1048 <dt class=
"hdlist1">
1049 --orphan
<new-branch
>
1053 Create a new
<em>orphan
</em> branch, named
<code><new-branch
></code>, started from
1054 <code><start-point
></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
1059 <div class=
"paragraph"><p>The index and the working tree are adjusted as if you had previously run
1060 <code>git checkout
<start-point
></code>. This allows you to start a new history
1061 that records a set of paths similar to
<code><start-point
></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
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><start-point
></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>
1075 <dt class=
"hdlist1">
1076 --ignore-skip-worktree-bits
1080 In sparse checkout mode,
<code>git checkout --
<paths
></code> would
1081 update only entries matched by
<code><paths
></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><paths
></code>.
1086 <dt class=
"hdlist1">
1089 <dt class=
"hdlist1">
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.
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>
1112 <dt class=
"hdlist1">
1113 --conflict=
<style
>
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".
1123 <dt class=
"hdlist1">
1126 <dt class=
"hdlist1">
1131 Interactively select hunks in the difference between the
1132 <code><tree-ish
></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><tree-ish
></code> was specified, the index).
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
“Interactive Mode
”
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
’t support overlay mode.
</p></div>
1142 <dt class=
"hdlist1">
1143 --ignore-other-worktrees
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
1153 <dt class=
"hdlist1">
1156 <dt class=
"hdlist1">
1157 --no-overwrite-ignore
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.
1166 <dt class=
"hdlist1">
1167 --recurse-submodules
1169 <dt class=
"hdlist1">
1170 --no-recurse-submodules
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
1183 <dt class=
"hdlist1">
1186 <dt class=
"hdlist1">
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><tree-ish
></code> are removed, to make them
1195 match
<code><tree-ish
></code> exactly.
1198 <dt class=
"hdlist1">
1199 --pathspec-from-file=
<file
>
1203 Pathspec is passed in
<code><file
></code> instead of commandline args. If
1204 <code><file
></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>.
1211 <dt class=
"hdlist1">
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).
1221 <dt class=
"hdlist1">
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).
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>
1239 <dt class=
"hdlist1">
1244 Name for the new branch.
1247 <dt class=
"hdlist1">
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>.
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>
1259 <dt class=
"hdlist1">
1264 Tree to checkout from (when paths are given). If not specified,
1265 the index will be used.
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>
1271 <dt class=
"hdlist1">
1276 Do not interpret any more arguments as options.
1279 <dt class=
"hdlist1">
1280 <pathspec
>…
1284 Limits the paths affected by the operation.
1286 <div class=
"paragraph"><p>For more details, see the
<em>pathspec
</em> entry in
<a href=
"gitglossary.html">gitglossary(
7)
</a>.
</p></div>
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
’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>
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>
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
’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>
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
’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>
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')
1370 a---b---c---d branch 'master' (refers to commit 'd')
1373 tag 'v2.0' (refers to commit 'b')
</code></pre>
1375 <div class=
"paragraph"><p>In fact, we can perform all the normal Git operations. But, let
’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')
1384 a---b---c---d branch 'master' (refers to commit 'd')
1387 tag 'v2.0' (refers to commit 'b')
</code></pre>
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><1></b>
1397 $ git branch foo
<b><2></b>
1398 $ git tag foo
<b><3></b></code></pre>
1400 <div class=
"colist arabic"><ol>
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
’ll no longer
1405 be in detached
<code>HEAD
</code> state after this command.
1410 similarly creates a new branch
<code>foo
</code>, which refers to commit
<code>f
</code>,
1411 but leaves
<code>HEAD
</code> detached.
1416 creates a new tag
<code>foo
</code>, which refers to commit
<code>f
</code>,
1417 leaving
<code>HEAD
</code> detached.
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>
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><tree-ish
></code>
1437 (e.g. a branch
<code>abc
</code> exists) and a valid
<code><pathspec
></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><tree-ish
></code>
1441 in such a situation. Use
<code>git checkout --
<pathspec
></code> if you want
1442 to checkout these paths out of the index.
</p></div>
1446 <h2 id=
"_examples">EXAMPLES
</h2>
1447 <div class=
"sectionbody">
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><1></b>
1456 $ git checkout master~
2 Makefile
<b><2></b>
1458 $ git checkout hello.c
<b><3></b></code></pre>
1460 <div class=
"colist arabic"><ol>
1468 take a file out of another commit
1473 restore
<code>hello.c
</code> from the index
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>
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>
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>
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>
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>
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>
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
1530 ERROR: Merge conflict in frotz
1531 fatal: merge program failed
</code></pre>
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>
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
’s found there:
</p></div>
1551 <div class=
"dlist"><dl>
1552 <dt class=
"hdlist1">
1553 checkout.defaultRemote
1557 When you run
<code>git checkout
<something
></code>
1558 or
<code>git switch
<something
></code> and only have one
1559 remote, it may implicitly fall back on checking out and
1560 tracking e.g.
<code>origin/
<something
></code>. This stops working as soon
1561 as you have more than one remote with a
<code><something
></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>.
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
<something
></code>
1569 or
<code>git switch
<something
></code>
1570 will checkout the
<code><something
></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>
1575 <dt class=
"hdlist1">
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>.
1585 <dt class=
"hdlist1">
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.
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>
1603 <dt class=
"hdlist1">
1604 checkout.thresholdForParallelism
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 to define the minimum
1611 number of files for which parallel checkout should be attempted. The
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>
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>
1632 <div id=
"footnotes"><hr /></div>
1634 <div id=
"footer-text">
1636 2023-
10-
02 12:
46:
05 PDT