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-worktree(
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-worktree(
1) Manual Page
741 <div class=
"sectionbody">
743 Manage multiple working trees
749 <h2 id=
"_synopsis">SYNOPSIS
</h2>
750 <div class=
"sectionbody">
751 <div class=
"verseblock">
752 <pre class=
"content"><em>git worktree add
</em> [-f] [--detach] [--checkout] [--lock [--reason
<string
>]] [-b
<new-branch
>]
<path
> [
<commit-ish
>]
753 <em>git worktree list
</em> [-v | --porcelain [-z]]
754 <em>git worktree lock
</em> [--reason
<string
>]
<worktree
>
755 <em>git worktree move
</em> <worktree
> <new-path
>
756 <em>git worktree prune
</em> [-n] [-v] [--expire
<expire
>]
757 <em>git worktree remove
</em> [-f]
<worktree
>
758 <em>git worktree repair
</em> [
<path
>…]
759 <em>git worktree unlock
</em> <worktree
></pre>
760 <div class=
"attribution">
765 <h2 id=
"_description">DESCRIPTION
</h2>
766 <div class=
"sectionbody">
767 <div class=
"paragraph"><p>Manage multiple working trees attached to the same repository.
</p></div>
768 <div class=
"paragraph"><p>A git repository can support multiple working trees, allowing you to check
769 out more than one branch at a time. With
<code>git worktree add
</code> a new working
770 tree is associated with the repository, along with additional metadata
771 that differentiates that working tree from others in the same repository.
772 The working tree, along with this metadata, is called a
"worktree".
</p></div>
773 <div class=
"paragraph"><p>This new worktree is called a
"linked worktree" as opposed to the
"main
774 worktree" prepared by
<a href=
"git-init.html">git-init(
1)
</a> or
<a href=
"git-clone.html">git-clone(
1)
</a>.
775 A repository has one main worktree (if it
’s not a bare repository) and
776 zero or more linked worktrees. When you are done with a linked worktree,
777 remove it with
<code>git worktree remove
</code>.
</p></div>
778 <div class=
"paragraph"><p>In its simplest form,
<code>git worktree add
<path
></code> automatically creates a
779 new branch whose name is the final component of
<code><path
></code>, which is
780 convenient if you plan to work on a new topic. For instance,
<code>git
781 worktree add ../hotfix
</code> creates new branch
<code>hotfix
</code> and checks it out at
782 path
<code>../hotfix
</code>. To instead work on an existing branch in a new worktree,
783 use
<code>git worktree add
<path
> <branch
></code>. On the other hand, if you just
784 plan to make some experimental changes or do testing without disturbing
785 existing development, it is often convenient to create a
<em>throwaway
</em>
786 worktree not associated with any branch. For instance,
787 <code>git worktree add -d
<path
></code> creates a new worktree with a detached
<code>HEAD
</code>
788 at the same commit as the current branch.
</p></div>
789 <div class=
"paragraph"><p>If a working tree is deleted without using
<code>git worktree remove
</code>, then
790 its associated administrative files, which reside in the repository
791 (see
"DETAILS" below), will eventually be removed automatically (see
792 <code>gc.worktreePruneExpire
</code> in
<a href=
"git-config.html">git-config(
1)
</a>), or you can run
793 <code>git worktree prune
</code> in the main or any linked worktree to clean up any
794 stale administrative files.
</p></div>
795 <div class=
"paragraph"><p>If the working tree for a linked worktree is stored on a portable device
796 or network share which is not always mounted, you can prevent its
797 administrative files from being pruned by issuing the
<code>git worktree lock
</code>
798 command, optionally specifying
<code>--reason
</code> to explain why the worktree is
803 <h2 id=
"_commands">COMMANDS
</h2>
804 <div class=
"sectionbody">
805 <div class=
"dlist"><dl>
807 add
<path
> [
<commit-ish
>]
811 Create a worktree at
<code><path
></code> and checkout
<code><commit-ish
></code> into it. The new worktree
812 is linked to the current repository, sharing everything except per-worktree
813 files such as
<code>HEAD
</code>,
<code>index
</code>, etc. As a convenience,
<code><commit-ish
></code> may
814 be a bare
"<code>-</code>", which is synonymous with
<code>@{-
1}
</code>.
816 <div class=
"paragraph"><p>If
<code><commit-ish
></code> is a branch name (call it
<code><branch
></code>) and is not found,
817 and neither
<code>-b
</code> nor
<code>-B
</code> nor
<code>--detach
</code> are used, but there does
818 exist a tracking branch in exactly one remote (call it
<code><remote
></code>)
819 with a matching name, treat as equivalent to:
</p></div>
820 <div class=
"listingblock">
821 <div class=
"content">
822 <pre><code>$ git worktree add --track -b
<branch
> <path
> <remote
>/
<branch
></code></pre>
824 <div class=
"paragraph"><p>If the branch exists in multiple remotes and one of them is named by
825 the
<code>checkout.defaultRemote
</code> configuration variable, we
’ll use that
826 one for the purposes of disambiguation, even if the
<code><branch
></code> isn
’t
827 unique across all remotes. Set it to
828 e.g.
<code>checkout.defaultRemote=origin
</code> to always checkout remote
829 branches from there if
<code><branch
></code> is ambiguous but exists on the
830 <code>origin
</code> remote. See also
<code>checkout.defaultRemote
</code> in
831 <a href=
"git-config.html">git-config(
1)
</a>.
</p></div>
832 <div class=
"paragraph"><p>If
<code><commit-ish
></code> is omitted and neither
<code>-b
</code> nor
<code>-B
</code> nor
<code>--detach
</code> used,
833 then, as a convenience, the new worktree is associated with a branch (call
834 it
<code><branch
></code>) named after
<code>$(basename
<path
>)
</code>. If
<code><branch
></code> doesn
’t
835 exist, a new branch based on
<code>HEAD
</code> is automatically created as if
836 <code>-b
<branch
></code> was given. If
<code><branch
></code> does exist, it will be checked out
837 in the new worktree, if it
’s not checked out anywhere else, otherwise the
838 command will refuse to create the worktree (unless
<code>--force
</code> is used).
</p></div>
845 List details of each worktree. The main worktree is listed first,
846 followed by each of the linked worktrees. The output details include
847 whether the worktree is bare, the revision currently checked out, the
848 branch currently checked out (or
"detached HEAD" if none),
"locked" if
849 the worktree is locked,
"prunable" if the worktree can be pruned by the
850 <code>prune
</code> command.
858 If a worktree is on a portable device or network share which is not always
859 mounted, lock it to prevent its administrative files from being pruned
860 automatically. This also prevents it from being moved or deleted.
861 Optionally, specify a reason for the lock with
<code>--reason
</code>.
869 Move a worktree to a new location. Note that the main worktree or linked
870 worktrees containing submodules cannot be moved with this command. (The
871 <code>git worktree repair
</code> command, however, can reestablish the connection
872 with linked worktrees if you move the main worktree manually.)
880 Prune worktree information in
<code>$GIT_DIR/worktrees
</code>.
888 Remove a worktree. Only clean worktrees (no untracked files and no
889 modification in tracked files) can be removed. Unclean worktrees or ones
890 with submodules can be removed with
<code>--force
</code>. The main worktree cannot be
895 repair [
<path
>…]
899 Repair worktree administrative files, if possible, if they have become
900 corrupted or outdated due to external factors.
902 <div class=
"paragraph"><p>For instance, if the main worktree (or bare repository) is moved, linked
903 worktrees will be unable to locate it. Running
<code>repair
</code> in the main
904 worktree will reestablish the connection from linked worktrees back to the
905 main worktree.
</p></div>
906 <div class=
"paragraph"><p>Similarly, if the working tree for a linked worktree is moved without
907 using
<code>git worktree move
</code>, the main worktree (or bare repository) will be
908 unable to locate it. Running
<code>repair
</code> within the recently-moved worktree
909 will reestablish the connection. If multiple linked worktrees are moved,
910 running
<code>repair
</code> from any worktree with each tree
’s new
<code><path
></code> as an
911 argument, will reestablish the connection to all the specified paths.
</p></div>
912 <div class=
"paragraph"><p>If both the main worktree and linked worktrees have been moved manually,
913 then running
<code>repair
</code> in the main worktree and specifying the new
<code><path
></code>
914 of each linked worktree will reestablish all connections in both
915 directions.
</p></div>
922 Unlock a worktree, allowing it to be pruned, moved or deleted.
929 <h2 id=
"_options">OPTIONS
</h2>
930 <div class=
"sectionbody">
931 <div class=
"dlist"><dl>
940 By default,
<code>add
</code> refuses to create a new worktree when
941 <code><commit-ish
></code> is a branch name and is already checked out by
942 another worktree, or if
<code><path
></code> is already assigned to some
943 worktree but is missing (for instance, if
<code><path
></code> was deleted
944 manually). This option overrides these safeguards. To add a missing but
945 locked worktree path, specify
<code>--force
</code> twice.
947 <div class=
"paragraph"><p><code>move
</code> refuses to move a locked worktree unless
<code>--force
</code> is specified
948 twice. If the destination is already assigned to some other worktree but is
949 missing (for instance, if
<code><new-path
></code> was deleted manually), then
<code>--force
</code>
950 allows the move to proceed; use
<code>--force
</code> twice if the destination is locked.
</p></div>
951 <div class=
"paragraph"><p><code>remove
</code> refuses to remove an unclean worktree unless
<code>--force
</code> is used.
952 To remove a locked worktree, specify
<code>--force
</code> twice.
</p></div>
955 -b
<new-branch
>
958 -B
<new-branch
>
962 With
<code>add
</code>, create a new branch named
<code><new-branch
></code> starting at
963 <code><commit-ish
></code>, and check out
<code><new-branch
></code> into the new worktree.
964 If
<code><commit-ish
></code> is omitted, it defaults to
<code>HEAD
</code>.
965 By default,
<code>-b
</code> refuses to create a new branch if it already
966 exists.
<code>-B
</code> overrides this safeguard, resetting
<code><new-branch
></code> to
967 <code><commit-ish
></code>.
978 With
<code>add
</code>, detach
<code>HEAD
</code> in the new worktree. See
"DETACHED HEAD"
979 in
<a href=
"git-checkout.html">git-checkout(
1)
</a>.
987 By default,
<code>add
</code> checks out
<code><commit-ish
></code>, however,
<code>--no-checkout
</code> can
988 be used to suppress checkout in order to make customizations,
989 such as configuring sparse-checkout. See
"Sparse checkout"
990 in
<a href=
"git-read-tree.html">git-read-tree(
1)
</a>.
998 With
<code>worktree add
<path
></code>, without
<code><commit-ish
></code>, instead
999 of creating a new branch from
<code>HEAD
</code>, if there exists a tracking
1000 branch in exactly one remote matching the basename of
<code><path
></code>,
1001 base the new branch on the remote-tracking branch, and mark
1002 the remote-tracking branch as
"upstream" from the new branch.
1004 <div class=
"paragraph"><p>This can also be set up as the default behaviour by using the
1005 <code>worktree.guessRemote
</code> config option.
</p></div>
1007 <dt class=
"hdlist1">
1012 When creating a new branch, if
<code><commit-ish
></code> is a branch,
1013 mark it as
"upstream" from the new branch. This is the
1014 default if
<code><commit-ish
></code> is a remote-tracking branch. See
1015 <code>--track
</code> in
<a href=
"git-branch.html">git-branch(
1)
</a> for details.
1018 <dt class=
"hdlist1">
1023 Keep the worktree locked after creation. This is the
1024 equivalent of
<code>git worktree lock
</code> after
<code>git worktree add
</code>,
1025 but without a race condition.
1028 <dt class=
"hdlist1">
1031 <dt class=
"hdlist1">
1036 With
<code>prune
</code>, do not remove anything; just report what it would
1040 <dt class=
"hdlist1">
1045 With
<code>list
</code>, output in an easy-to-parse format for scripts.
1046 This format will remain stable across Git versions and regardless of user
1047 configuration. It is recommended to combine this with
<code>-z
</code>.
1048 See below for details.
1051 <dt class=
"hdlist1">
1056 Terminate each line with a NUL rather than a newline when
1057 <code>--porcelain
</code> is specified with
<code>list
</code>. This makes it possible
1058 to parse the output when a worktree path contains a newline
1062 <dt class=
"hdlist1">
1065 <dt class=
"hdlist1">
1070 With
<code>add
</code>, suppress feedback messages.
1073 <dt class=
"hdlist1">
1076 <dt class=
"hdlist1">
1081 With
<code>prune
</code>, report all removals.
1083 <div class=
"paragraph"><p>With
<code>list
</code>, output additional information about worktrees (see below).
</p></div>
1085 <dt class=
"hdlist1">
1086 --expire
<time
>
1090 With
<code>prune
</code>, only expire unused worktrees older than
<code><time
></code>.
1092 <div class=
"paragraph"><p>With
<code>list
</code>, annotate missing worktrees as prunable if they are older than
1093 <code><time
></code>.
</p></div>
1095 <dt class=
"hdlist1">
1096 --reason
<string
>
1100 With
<code>lock
</code> or with
<code>add --lock
</code>, an explanation why the worktree
1104 <dt class=
"hdlist1">
1109 Worktrees can be identified by path, either relative or absolute.
1111 <div class=
"paragraph"><p>If the last path components in the worktree
’s path is unique among
1112 worktrees, it can be used to identify a worktree. For example if you only
1113 have two worktrees, at
<code>/abc/def/ghi
</code> and
<code>/abc/def/ggg
</code>, then
<code>ghi
</code> or
1114 <code>def/ghi
</code> is enough to point to the former worktree.
</p></div>
1120 <h2 id=
"_refs">REFS
</h2>
1121 <div class=
"sectionbody">
1122 <div class=
"paragraph"><p>When using multiple worktrees, some refs are shared between all worktrees,
1123 but others are specific to an individual worktree. One example is
<code>HEAD
</code>,
1124 which is different for each worktree. This section is about the sharing
1125 rules and how to access refs of one worktree from another.
</p></div>
1126 <div class=
"paragraph"><p>In general, all pseudo refs are per-worktree and all refs starting with
1127 <code>refs/
</code> are shared. Pseudo refs are ones like
<code>HEAD
</code> which are directly
1128 under
<code>$GIT_DIR
</code> instead of inside
<code>$GIT_DIR/refs
</code>. There are exceptions,
1129 however: refs inside
<code>refs/bisect
</code> and
<code>refs/worktree
</code> are not shared.
</p></div>
1130 <div class=
"paragraph"><p>Refs that are per-worktree can still be accessed from another worktree via
1131 two special paths,
<code>main-worktree
</code> and
<code>worktrees
</code>. The former gives
1132 access to per-worktree refs of the main worktree, while the latter to all
1133 linked worktrees.
</p></div>
1134 <div class=
"paragraph"><p>For example,
<code>main-worktree/HEAD
</code> or
<code>main-worktree/refs/bisect/good
</code>
1135 resolve to the same value as the main worktree
’s
<code>HEAD
</code> and
1136 <code>refs/bisect/good
</code> respectively. Similarly,
<code>worktrees/foo/HEAD
</code> or
1137 <code>worktrees/bar/refs/bisect/bad
</code> are the same as
1138 <code>$GIT_COMMON_DIR/worktrees/foo/HEAD
</code> and
1139 <code>$GIT_COMMON_DIR/worktrees/bar/refs/bisect/bad
</code>.
</p></div>
1140 <div class=
"paragraph"><p>To access refs, it
’s best not to look inside
<code>$GIT_DIR
</code> directly. Instead
1141 use commands such as
<a href=
"git-rev-parse.html">git-rev-parse(
1)
</a> or
<a href=
"git-update-ref.html">git-update-ref(
1)
</a>
1142 which will handle refs correctly.
</p></div>
1146 <h2 id=
"_configuration_file">CONFIGURATION FILE
</h2>
1147 <div class=
"sectionbody">
1148 <div class=
"paragraph"><p>By default, the repository
<code>config
</code> file is shared across all worktrees.
1149 If the config variables
<code>core.bare
</code> or
<code>core.worktree
</code> are present in the
1150 common config file and
<code>extensions.worktreeConfig
</code> is disabled, then they
1151 will be applied to the main worktree only.
</p></div>
1152 <div class=
"paragraph"><p>In order to have worktree-specific configuration, you can turn on the
1153 <code>worktreeConfig
</code> extension, e.g.:
</p></div>
1154 <div class=
"listingblock">
1155 <div class=
"content">
1156 <pre><code>$ git config extensions.worktreeConfig true
</code></pre>
1158 <div class=
"paragraph"><p>In this mode, specific configuration stays in the path pointed by
<code>git
1159 rev-parse --git-path config.worktree
</code>. You can add or update
1160 configuration in this file with
<code>git config --worktree
</code>. Older Git
1161 versions will refuse to access repositories with this extension.
</p></div>
1162 <div class=
"paragraph"><p>Note that in this file, the exception for
<code>core.bare
</code> and
<code>core.worktree
</code>
1163 is gone. If they exist in
<code>$GIT_DIR/config
</code>, you must move
1164 them to the
<code>config.worktree
</code> of the main worktree. You may also take this
1165 opportunity to review and move other configuration that you do not want to
1166 share to all worktrees:
</p></div>
1167 <div class=
"ulist"><ul>
1170 <code>core.worktree
</code> should never be shared.
1175 <code>core.bare
</code> should not be shared if the value is
<code>core.bare=true
</code>.
1180 <code>core.sparseCheckout
</code> should not be shared, unless you are sure you
1181 always use sparse checkout for all worktrees.
1185 <div class=
"paragraph"><p>See the documentation of
<code>extensions.worktreeConfig
</code> in
1186 <a href=
"git-config.html">git-config(
1)
</a> for more details.
</p></div>
1190 <h2 id=
"_details">DETAILS
</h2>
1191 <div class=
"sectionbody">
1192 <div class=
"paragraph"><p>Each linked worktree has a private sub-directory in the repository
’s
1193 <code>$GIT_DIR/worktrees
</code> directory. The private sub-directory
’s name is usually
1194 the base name of the linked worktree
’s path, possibly appended with a
1195 number to make it unique. For example, when
<code>$GIT_DIR=/path/main/.git
</code> the
1196 command
<code>git worktree add /path/other/test-next next
</code> creates the linked
1197 worktree in
<code>/path/other/test-next
</code> and also creates a
1198 <code>$GIT_DIR/worktrees/test-next
</code> directory (or
<code>$GIT_DIR/worktrees/test-next1
</code>
1199 if
<code>test-next
</code> is already taken).
</p></div>
1200 <div class=
"paragraph"><p>Within a linked worktree,
<code>$GIT_DIR
</code> is set to point to this private
1201 directory (e.g.
<code>/path/main/.git/worktrees/test-next
</code> in the example) and
1202 <code>$GIT_COMMON_DIR
</code> is set to point back to the main worktree
’s
<code>$GIT_DIR
</code>
1203 (e.g.
<code>/path/main/.git
</code>). These settings are made in a
<code>.git
</code> file located at
1204 the top directory of the linked worktree.
</p></div>
1205 <div class=
"paragraph"><p>Path resolution via
<code>git rev-parse --git-path
</code> uses either
1206 <code>$GIT_DIR
</code> or
<code>$GIT_COMMON_DIR
</code> depending on the path. For example, in the
1207 linked worktree
<code>git rev-parse --git-path HEAD
</code> returns
1208 <code>/path/main/.git/worktrees/test-next/HEAD
</code> (not
1209 <code>/path/other/test-next/.git/HEAD
</code> or
<code>/path/main/.git/HEAD
</code>) while
<code>git
1210 rev-parse --git-path refs/heads/master
</code> uses
1211 <code>$GIT_COMMON_DIR
</code> and returns
<code>/path/main/.git/refs/heads/master
</code>,
1212 since refs are shared across all worktrees, except
<code>refs/bisect
</code> and
1213 <code>refs/worktree
</code>.
</p></div>
1214 <div class=
"paragraph"><p>See
<a href=
"gitrepository-layout.html">gitrepository-layout(
5)
</a> for more information. The rule of
1215 thumb is do not make any assumption about whether a path belongs to
1216 <code>$GIT_DIR
</code> or
<code>$GIT_COMMON_DIR
</code> when you need to directly access something
1217 inside
<code>$GIT_DIR
</code>. Use
<code>git rev-parse --git-path
</code> to get the final path.
</p></div>
1218 <div class=
"paragraph"><p>If you manually move a linked worktree, you need to update the
<code>gitdir
</code> file
1219 in the entry
’s directory. For example, if a linked worktree is moved
1220 to
<code>/newpath/test-next
</code> and its
<code>.git
</code> file points to
1221 <code>/path/main/.git/worktrees/test-next
</code>, then update
1222 <code>/path/main/.git/worktrees/test-next/gitdir
</code> to reference
<code>/newpath/test-next
</code>
1223 instead. Better yet, run
<code>git worktree repair
</code> to reestablish the connection
1224 automatically.
</p></div>
1225 <div class=
"paragraph"><p>To prevent a
<code>$GIT_DIR/worktrees
</code> entry from being pruned (which
1226 can be useful in some situations, such as when the
1227 entry
’s worktree is stored on a portable device), use the
1228 <code>git worktree lock
</code> command, which adds a file named
1229 <code>locked
</code> to the entry
’s directory. The file contains the reason in
1230 plain text. For example, if a linked worktree
’s
<code>.git
</code> file points
1231 to
<code>/path/main/.git/worktrees/test-next
</code> then a file named
1232 <code>/path/main/.git/worktrees/test-next/locked
</code> will prevent the
1233 <code>test-next
</code> entry from being pruned. See
1234 <a href=
"gitrepository-layout.html">gitrepository-layout(
5)
</a> for details.
</p></div>
1235 <div class=
"paragraph"><p>When
<code>extensions.worktreeConfig
</code> is enabled, the config file
1236 <code>.git/worktrees/
<id
>/config.worktree
</code> is read after
<code>.git/config
</code> is.
</p></div>
1240 <h2 id=
"_list_output_format">LIST OUTPUT FORMAT
</h2>
1241 <div class=
"sectionbody">
1242 <div class=
"paragraph"><p>The
<code>worktree list
</code> command has two output formats. The default format shows the
1243 details on a single line with columns. For example:
</p></div>
1244 <div class=
"listingblock">
1245 <div class=
"content">
1246 <pre><code>$ git worktree list
1247 /path/to/bare-source (bare)
1248 /path/to/linked-worktree abcd1234 [master]
1249 /path/to/other-linked-worktree
1234abc (detached HEAD)
</code></pre>
1251 <div class=
"paragraph"><p>The command also shows annotations for each worktree, according to its state.
1252 These annotations are:
</p></div>
1253 <div class=
"ulist"><ul>
1256 <code>locked
</code>, if the worktree is locked.
1261 <code>prunable
</code>, if the worktree can be pruned via
<code>git worktree prune
</code>.
1265 <div class=
"listingblock">
1266 <div class=
"content">
1267 <pre><code>$ git worktree list
1268 /path/to/linked-worktree abcd1234 [master]
1269 /path/to/locked-worktree acbd5678 (brancha) locked
1270 /path/to/prunable-worktree
5678abc (detached HEAD) prunable
</code></pre>
1272 <div class=
"paragraph"><p>For these annotations, a reason might also be available and this can be
1273 seen using the verbose mode. The annotation is then moved to the next line
1274 indented followed by the additional information.
</p></div>
1275 <div class=
"listingblock">
1276 <div class=
"content">
1277 <pre><code>$ git worktree list --verbose
1278 /path/to/linked-worktree abcd1234 [master]
1279 /path/to/locked-worktree-no-reason abcd5678 (detached HEAD) locked
1280 /path/to/locked-worktree-with-reason
1234abcd (brancha)
1281 locked: worktree path is mounted on a portable device
1282 /path/to/prunable-worktree
5678abc1 (detached HEAD)
1283 prunable: gitdir file points to non-existent location
</code></pre>
1285 <div class=
"paragraph"><p>Note that the annotation is moved to the next line if the additional
1286 information is available, otherwise it stays on the same line as the
1287 worktree itself.
</p></div>
1289 <h3 id=
"_porcelain_format">Porcelain Format
</h3>
1290 <div class=
"paragraph"><p>The porcelain format has a line per attribute. If
<code>-z
</code> is given then the lines
1291 are terminated with NUL rather than a newline. Attributes are listed with a
1292 label and value separated by a single space. Boolean attributes (like
<code>bare
</code>
1293 and
<code>detached
</code>) are listed as a label only, and are present only
1294 if the value is true. Some attributes (like
<code>locked
</code>) can be listed as a label
1295 only or with a value depending upon whether a reason is available. The first
1296 attribute of a worktree is always
<code>worktree
</code>, an empty line indicates the
1297 end of the record. For example:
</p></div>
1298 <div class=
"listingblock">
1299 <div class=
"content">
1300 <pre><code>$ git worktree list --porcelain
1301 worktree /path/to/bare-source
1304 worktree /path/to/linked-worktree
1305 HEAD abcd1234abcd1234abcd1234abcd1234abcd1234
1306 branch refs/heads/master
1308 worktree /path/to/other-linked-worktree
1309 HEAD
1234abc1234abc1234abc1234abc1234abc1234a
1312 worktree /path/to/linked-worktree-locked-no-reason
1313 HEAD
5678abc5678abc5678abc5678abc5678abc5678c
1314 branch refs/heads/locked-no-reason
1317 worktree /path/to/linked-worktree-locked-with-reason
1318 HEAD
3456def3456def3456def3456def3456def3456b
1319 branch refs/heads/locked-with-reason
1320 locked reason why is locked
1322 worktree /path/to/linked-worktree-prunable
1323 HEAD
1233def1234def1234def1234def1234def1234b
1325 prunable gitdir file points to non-existent location
</code></pre>
1327 <div class=
"paragraph"><p>Unless
<code>-z
</code> is used any
"unusual" characters in the lock reason such as newlines
1328 are escaped and the entire reason is quoted as explained for the
1329 configuration variable
<code>core.quotePath
</code> (see
<a href=
"git-config.html">git-config(
1)
</a>).
1330 For Example:
</p></div>
1331 <div class=
"listingblock">
1332 <div class=
"content">
1333 <pre><code>$ git worktree list --porcelain
1335 locked
"reason\nwhy is locked"
1342 <h2 id=
"_examples">EXAMPLES
</h2>
1343 <div class=
"sectionbody">
1344 <div class=
"paragraph"><p>You are in the middle of a refactoring session and your boss comes in and
1345 demands that you fix something immediately. You might typically use
1346 <a href=
"git-stash.html">git-stash(
1)
</a> to store your changes away temporarily, however, your
1347 working tree is in such a state of disarray (with new, moved, and removed
1348 files, and other bits and pieces strewn around) that you don
’t want to risk
1349 disturbing any of it. Instead, you create a temporary linked worktree to
1350 make the emergency fix, remove it when done, and then resume your earlier
1351 refactoring session.
</p></div>
1352 <div class=
"listingblock">
1353 <div class=
"content">
1354 <pre><code>$ git worktree add -b emergency-fix ../temp master
1356 # ... hack hack hack ...
1357 $ git commit -a -m 'emergency fix for boss'
1359 $ git worktree remove ../temp
</code></pre>
1364 <h2 id=
"_bugs">BUGS
</h2>
1365 <div class=
"sectionbody">
1366 <div class=
"paragraph"><p>Multiple checkout in general is still experimental, and the support
1367 for submodules is incomplete. It is NOT recommended to make multiple
1368 checkouts of a superproject.
</p></div>
1372 <h2 id=
"_git">GIT
</h2>
1373 <div class=
"sectionbody">
1374 <div class=
"paragraph"><p>Part of the
<a href=
"git.html">git(
1)
</a> suite
</p></div>
1378 <div id=
"footnotes"><hr /></div>
1380 <div id=
"footer-text">
1382 2022-
04-
04 11:
19:
32 PDT