Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I can't be sure, because I am not the author of that sentence. I'll take a shot that the confusion the author is describing is the common confusion between "tracking" and "remote tracking" branches. <a href="http://www.gitguys.com/topics/tracking-branches-and-remote-tracking-branches/">gitguys</a> has a great article on this, so really, you should just read that. They have nice pictures and everything.</p> <p>Here's my take on it...</p> <h2>The Setting</h2> <p>As an example, let's assume we have a very simple git repository on github that has a single <code>master</code> branch with a few commits (C1 and C2, where C2 is the current commit). When you clone that repository...</p> <pre><code>git clone git@github.com:example/repo.git </code></pre> <p>...two things happen:</p> <ol> <li>You copy all of the commits (C1 and C2) to your local computer.</li> <li>You also create a new branch on your local computer called <code>master</code>. This branch is a "tracking branch", and its HEAD is on C2. This branch is referred to as the "tracking branch".</li> </ol> <h2>A New Commit</h2> <p>So far, nothing special. But in the time you read these explanations, someone committed another commit (C3) and push it to the remote repository. Now imagine you hear about this new amazing commit, and decide to retrieve it yourself.</p> <pre><code>git fetch </code></pre> <p>This does two things:</p> <ol> <li>Copies the new commits that are needed (C3) to your local computer.</li> <li>Updates the local system somehow to let them know that origin's <code>master</code> branch is on now on C3.</li> </ol> <p>But here's the question: how does the local system know that the origin's <code>master</code> branch is on C3? Surely git has some way of storing that information locally? But where? We can't actually make a change to the local <code>master</code> branch since we might have our own commits or other changes on that local branch that we need to merge. Is it just stored in some other, unknown blob?</p> <h2>The Answer</h2> <p>It turns out, git just uses a <em>third</em> branch. Right now, we knew about two branches:</p> <ol> <li>The branch physically located on github.</li> <li>The "tracking branch", located on your computer (what you would call <code>master</code>).</li> </ol> <p>It turns out there is a third. You've probably seen it before: it's called <code>origin/master</code>. And it's not the same as either of these two branches. It is what is known as a "remote-tracking branch".</p> <p>You can think of it as the branch that sits between your local <code>master</code> branch and the origin's <code>master</code> branch. It is an actual git branch on your computer (just like <code>master</code>) and as such you can play with it similarly to how you can jump around your other branches. However, there there are limitations.</p> <p>For example, you can check it out...</p> <pre><code>git checkout origin/master </code></pre> <p>However, you'd get a funny looking message...</p> <pre><code>Note: checking out 'origin/master'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b new_branch_name HEAD is now at 12dbe6a... My awesome commit! </code></pre> <p>This message is displayed is because "remote tracking branches" are READ-ONLY. The user cannot manipulate them like they can <code>master</code>, only the git system itself is allowed to make changes to it (which it will do during fetches). As such, from an implementation standpoint, you can think of them as just any other branch. However, because of their read-only nature, you don't typically use them like any other branch.</p> <p>So, really, we have three branches in the mix:</p> <ol> <li>The branch physically located on github.</li> <li>The <code>origin/master</code> branch physically located on your machine ("remote tracking branch").</li> <li>The <code>master</code> branch physically located on your machine ("tracking branch").</li> </ol> <h2>To Answer The Question...</h2> <p>Therefore, my assumption is that really the confusion could lie between "tracking" and "remote tracking" branches. It would make sense that someone would confuse <code>master</code> as a "remote tracking branch" (after all, it does get commits from <code>origin/master</code>!), but in reality, it is not. It is a "tracking branch", and the branch it tracks is <code>origin/master</code>. <code>origin/master</code> is the "remote tracking branch".</p> <p>When someone talks about "tracking" in terms of git branch --track, they are talking about the "tracking" branch that you can modify.</p> <p>When someone talks about "remote-tracking branches", they are talking about the read-only branch that tracks a remote's branch.</p>
 

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