Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A branch when checked out is only a pointer to a commit (<a href="https://stackoverflow.com/questions/1655361/how-to-clone-an-old-git-commit-and-some-more-questions-about-git/1655666#1655666">within a graph of commit</a>).<br> As such, <del>Git cannot check out two commits of that graph at the same time</del>.</p> <p>Actually, see "<a href="https://stackoverflow.com/a/30185564/6309">Multiple working directories with Git?</a>".<br> With Git 2.5+ (Q2 2015), you can have <strong>multiple working trees</strong> for one git repo, with <code>git checkout --to=&lt;path&gt;</code>.</p> <p>That allows you to Check out a branch in a separate working directory at <code>&lt;path&gt;</code>. A new working directory is linked to the current repository.</p> <p>That link is "portable" (ie works even on Windows) as it is recorded in the main repo <code>$GIT_DIR/worktrees</code> directory.</p> <hr> <p>Original answer (2011):</p> <p><img src="https://i.stack.imgur.com/j8Itp.png" alt="git branches"></p> <p>(Source: Scott Chason, ProGIT Book, <a href="http://progit.org/book/ch3-1.html" rel="nofollow noreferrer">http://progit.org/book/ch3-1.html</a>, CC-BY-NC-SA)</p> <p>If you need to work on two different branches at the same time, simply clone your repo and select (<code>git checkout</code>) the other branch in that clone. You can use the name of the branch as the name of the root directory for that clone.<br> And you can create branches in any of those repos.</p> <hr> <blockquote> <p>So the question is why can't Git have TWO pointers, one for each directory? –</p> </blockquote> <p>As mentioned in "<a href="https://stackoverflow.com/questions/995636/popularity-of-git-mercurial-bazaar-vs-which-to-recommend/995799#995799">Popularity of Git/Mercurial/Bazaar vs. which to recommend</a>", Git is at its core a <em>content</em> management. Each commit represents a full snapshot of the repo.<br> You cannot view two contents in the same container (working directory), even though you can keep reference of as many pointer (branches) as you want.</p> <p><img src="https://i.stack.imgur.com/Ngjx8.png" alt="Git Local operations"></p> <p>You only populate the working directory with <em>one</em> content.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload