Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ul> <li><p>Your description of (and the difference between) the two scenarios is not quite clear , since if the remote has some branches names <code>A</code>, <code>B</code>, and <code>C</code>, it will always exist in your local repo as well as <code>origin/A</code>, <code>origin/B</code> and <code>origin/C</code>, (after you've updated the remote using <code>git fetch</code> or a <code>git pull</code>), irrespective of whether you've checked out the branch locally or not.</p></li> <li><p><code>fetch</code> is used to fetch the updated list of commits from a remote. <code>fetch</code> is done as the first command of a <code>pull</code> operation.</p> <p>The commonly syntax is <code>git fetch &lt;REMOTE&gt; &lt;REFSPEC&gt;</code></p> <p>The refspec argument is optional. If you fail to specify one, git is going to pull all the refs from the remote. By refs, it includes all reachable heads and tags in the refspec.</p></li> <li><p>The <code>git pull &lt;REMOTE&gt;</code> command without any refspecs is going to bring in all the refs from the remote, and <strong>NOT</strong> just the commits corresponding to your current local branch you're merging into.</p></li> <li><p>In Scenario 1, if you run a <code>git pull origin</code> when you've currently checked out branch <code>A</code>, yes git is going to update <code>origin/A</code>, <code>origin/B</code>, and <code>origin/C</code> in your local repo. In addition, it will merge <code>origin/A</code> into <code>A</code>.</p></li> <li><p>In Scenario 1, if you run a <code>git fetch origin C</code>, only <code>origin/C</code> in your local repo is going to get updated. There will be no merges either whatsoever because of this <code>fetch</code>.</p></li> <li><p>Scenario 2 is going to yield the same results as Scenario 1. All the refs from the remote will be updated into your local repo's <code>&lt;REMOTE_NAME&gt;/BLAH</code> branches. In fact Scenario 2 is no different than Scenario 1, just that you have fewer local branches checked out which should not matter in any way for the <code>fetch</code> operation.</p></li> </ul> <p>BTW to answer your question in the comment on what <code>git pull origin &lt;BRANCHNAME&gt;</code> and <code>git fetch origin &lt;BRANCHNAME&gt;</code> do:</p> <ul> <li><p><code>git pull origin &lt;BRANCHNAME&gt;</code> does something different than what you might expect it to do.</p> <ul> <li>git brings in the commits for <code>&lt;BRANCHNAME&gt;</code> from the remote into <code>FETCH_HEAD</code> instead of <code>origin/&lt;BRANCHNAME&gt;</code>.</li> <li>It does not update <code>origin/&lt;BRANCHNAME&gt;</code></li> <li>It merges <code>FETCH_HEAD</code> into your currently checked out branch, and hence achieves the similar end result as far as the local branch state is concerned.</li> </ul></li> <li><p><code>git fetch origin &lt;BRANCHNAME&gt;</code> behaves very similar to <code>git pull origin &lt;BRANCHNAME&gt;</code> described above, except it stops with just bringing in the commits for <code>&lt;BRANCHNAME&gt;</code> from the remote into <code>FETCH_HEAD</code>.</p></li> <li><p>If you really want to fetch only the commits corresponding to a particular branch, you need to use the right refspec argument. Read more on it <a href="http://git-scm.com/book/ch9-5.html" rel="nofollow">here</a>. To fetch only the commits from the remote <code>origin</code> and branch <code>master</code>, the correct command would be:</p> <pre><code> git pull origin refs/heads/master:refs/remotes/origin/master </code></pre></li> <li><p>You could also use refspecs with <code>fetch</code> to only fetch the commits into <code>origin/master</code> without any merges into your local branches:</p> <pre><code> git fetch origin refs/heads/master:refs/remotes/origin/master </code></pre></li> <li><p>If you do not want to type the long refspecs for a <code>git pull</code>, and do not mind having the info about all refs from the remote, and you do not have a remote tracking branch set, then you could just do this:</p> <pre><code>git fetch origin git checkout &lt;BRANCH-THAT-NEEDS-TO-BE-MERGED-INTO&gt; git merge origin/&lt;BRANCH-TO-BE-MERGED-FROM&gt; </code></pre></li> </ul> <p><strong>BONUS - What does the <code>GIT_FETCH_HEAD</code> do ?</strong></p> <p>It is a short-lived ref used by git to keep track of any fetches from the remote repositories. You could see the current value of <code>FETCH_HEAD</code> by looking into the file <code>.git/FETCH_HEAD</code>. For example:</p> <pre><code>72a90cf95456b14630ddff427c3df1b00be24670 branch 'master' of git://github.com/foo/bar.git </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. 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