Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2><em>git pull</em> Confusion</h2> <h3>Over-specificity</h3> <p>Your <em>git pull</em> command includes too much information.</p> <blockquote> <p>[test2]$ git pull test2 test2:test2<br> From /gitvobs/git_bare/test2<br> ! [rejected] test2 -> test2 (non fast forward)</p> <p>i know that adding a + (git pull test2 +test2:test2) would help but it overwrites local changes.</p> </blockquote> <p>This is what your command means:</p> <pre><code># *------------ (1) remote repository name # / *------- (2) ref in remote repository # / / *-- (3) ref in local repository # / / / git pull test2 test2:test2 # Means this: From remote repository `test2` (1), # fetch branch `test2` (2), store it in local branch `test2` (3), then # merge the fetched history into HEAD. </code></pre> <p>You are telling <em>git pull</em> to overwrite your local <code>test2</code> branch with whatever the remote has on its <code>test2</code> branch and then merge that with HEAD. You probably do not want to include the destination part of the refspec (the <code>:test2</code>).</p> <hr> <p>If the local branch you have checked out is configured to track something (see the “Branches: …” below), just do</p> <pre><code>git pull </code></pre> <p>If you need to supply (or override) a remote and repository, just supply the remote name/url and the local branch on the remote (leave off the final part of the refspec):</p> <pre><code>git pull test2 test2 </code></pre> <h3>Pull Into a Branch That is Not Checked Out</h3> <p><em>git pull</em> is (as mentioned above) a combination of <em>git fetch</em> and <em>git merge</em> (or <em>git rebase</em>).</p> <p>In general, a merge might involve conflict resolution. Conflict resolution requires a working tree. Therefore, it is not possible to perform a normal merge operation without a working tree. This means that your current HEAD has to be one of parents of the merge (it will be the first parent). Doing a rebase also needs a working tree for conflict resolution.</p> <p>Since a pull involves a merge or rebase, it is not possible to pull into a local branch that is not checked out. You can only pull into the currently checked out branch.</p> <h2>Branches: Local, Tracking, Remote Tracking</h2> <p>The various types of Git branches are all the same underlying object: refs. Refs live in the <code>refs/</code> namespace in <code>$GIT_DIR/refs/</code> and <code>$GIT_DIR/packed-refs</code>.</p> <ul> <li>“Local” branches live in the <code>refs/heads/</code> namespace. <ul> <li>To examine the <code>test2</code> local branch ref: <ul> <li><code>git show-ref refs/heads/test2</code>, or <ul> <li><code>cat .git/refs/heads/test2</code>, or</li> <li><code>grep -F refs/heads/test2 .git/packed-refs</code></li> </ul></li> </ul></li> </ul></li> <li>“Remote Tracking” branches live in the <code>refs/remotes/&lt;remote-name&gt;/</code> namespaces. <ul> <li>Remote tracking branches are local copies of branches from a remote repository. <ul> <li>The name “remote tracking” makes sense when you think of it like this, but it can be confused with the unfortunately named <code>--track</code> functionality of <em>git branch</em> and <em>git checkout</em> (see the final branch type).</li> </ul></li> <li>To examine the <code>test2</code> remote tracking branch ref: <ul> <li><code>git show-ref refs/remotes/test2/test2</code>, or <ul> <li><code>cat .git/refs/remotes/test2/test2</code>, or</li> <li><code>grep -F refs/remotes/test2/test2 .git/packed-refs</code></li> </ul></li> </ul></li> </ul></li> <li><p>Local branches that track another branch are normal local branches (in <code>refs/heads/</code>) that have extra configuration in <code>$GIT_DIR/config</code>:</p> <pre><code>[branch "test2"] remote = test2 merge = refs/heads/test2 </code></pre> <p>It is important to note that the <code>merge</code> (or <code>rebase</code>) configuration option names a <em>ref on the remote</em>. So <code>refs/heads/test2</code> here means the local branch <code>test2</code> found on the remote <code>test2</code>. The special remote name <code>.</code> can be used to refer to local branches in the local repository.</p> <ul> <li>The purpose of local branches that “track” some other branch is to make it easy to just type <code>git pull</code> and have it merge in (or rebase on top of) the history in some other branch.</li> </ul></li> </ul> <hr> <p>You said that you wanted to distinguish plain plain local branches from local branches that track some other branch. You can do this by looking for the branch configuration in the <code>$GIT_DIR/config</code> file.</p> <p>You might use <em>git config</em> to do this:</p> <pre><code>branch_tracks_something() { { git config branch."$1".merge || git config branch."$1".rebase } &gt;/dev/null 2&gt;&amp;1 } # test local branch branch_tracks_something test2 &amp;&amp; echo 'test2 tracks something' || echo 'test2 does not track anything' </code></pre> <p>Or, if you have Git 1.6.3 or later, you can use the <code>%(upstream)</code> format of <em>git for-each-ref</em>:</p> <pre><code>{ echo 'show_ref_desc() { case "$1" in refs/heads/*) t='' test -n "$2" &amp;&amp; t=" (tracks $2)" echo "local: $1$t" ;; refs/remotes/*) echo "remote tracking: $1" ;; *) echo "other: $1" ;; esac }'; git for-each-ref --shell --format='show_ref_desc %(refname) %(upstream)'; } | sh </code></pre> <p>The output looks like this:</p> <pre><code>local: refs/heads/test2 (tracks refs/remotes/test2/test2) remote tracking: refs/remotes/test2/HEAD remote tracking: refs/remotes/test2/test2 </code></pre>
    singulars
    1. This table or related slice is empty.
    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