Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you want to push your local branch which you've called <code>file_upload_branch</code> (I added underscores here for readability—note that this affects every occurrence below), but call it <code>master</code> on the remote:</p> <pre><code>git push origin file_upload_branch:master # see below about -u </code></pre> <p>The last argument to <code>push</code> here is called a "refspec", and you spell it out with two parts: a local-side identifier (typically a branch name), and a remote-side identifier (another, possibly different, branch name). The colon character <code>:</code> serves to separate the two.</p> <p>If you use only one name, leaving out the colon, git assumes you want the same name on each side. (Which you just said is not what you wanted.)</p> <p>If you leave out the refspec entirely (and don't use options like <code>--all</code>), git chooses what to push based on various configuration variables. If you have not set any of them, all current versions of git use the method called <code>matching</code>:<sup>1</sup> your git, doing the <code>push</code> operation, asks the other side's git "what branches do you have now", takes the resulting list and sees which local branches you have that match, and pushes those.</p> <p>With <code>--all</code> as a (pseudo) refspec, your side just asks to push every branch name you have, to the same name on the remote (as you discovered).</p> <p>(The syntax <code>:branchname</code>, given as a refspec, asks the remote to <em>delete</em> the named branch. You will probably want to use this to delete <code>file_upload_branch</code> on the remote.)</p> <p>If you set the configuration variable <code>push.default</code> to <code>upstream</code>,<sup>2</sup> this changes the default action for <code>push</code> with no refspec to use the "upstream" name of the current branch. That is, if you're on <code>file_upload_branch</code> and its "upstream" name on the remote (<code>origin</code>) is <code>master</code>, a plain:</p> <pre><code>git push origin </code></pre> <p>will act as if you wrote:</p> <pre><code>git push origin file_upload_branch:master </code></pre> <p>This is where the <code>-u</code> argument comes in: after <code>file_upload_branch</code> is successfully pushed to <code>master</code> on remote <code>origin</code>, <code>git push</code> will <em>set</em> file_upload_branch's "upstream" to <code>origin/master</code>. You only need to do this once per branch; having set the upstream, and set <code>push.default</code> to <code>upstream</code>, future pushes will automatically "do what you wanted".</p> <hr> <p><sup>1</sup>In git version 2.0, the default value for <code>remote.pushdefault</code> is going to change to <code>simple</code>. If you set your <code>--global</code> <code>remote.pushdefault</code> to <code>simple</code> now, you will be prepared for (and thus unaffected by) this change. Or, if you prefer <code>upstream</code> as a personal default, you can set that and it should still work in 2.0.</p> <p><sup>2</sup>Note that <code>remote.pushdefault</code> can be set in both your per-user (i.e., <code>--global</code>) git configuration and also in a per-repo configuration. The per-repo configuration will override the global configuration whenever both are set. You can also set a rather dizzying array of additional configurations, though I wouldn't do any of that just yet :-) : <code>remote.origin.push</code>, <code>branch.file_upload_branch.remote</code>, and <code>branch.file_upload_branch.pushremote</code> can all affect the behavior of <code>git push</code>. See the <a href="https://www.kernel.org/pub/software/scm/git/docs/git-config.html" rel="nofollow">git config documentation</a> for full details.</p>
    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.
    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