Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Setting a local branch to track another local branch isn't generally useful, but I can think of a couple of cases where it could be handy:</p> <ul> <li><p>You may have some aliases or scripts that do stuff with upstream branches (e.g., via the <code>@{u}</code> shorthand; see <code>git help revisions</code>). If so, configuring a local branch to track another local branch would allow you to test your aliases or scripts without affecting the remote repository or creating a temporary dummy repository.</p></li> <li><p>Suppose you are working on a new local branch named <code>foo</code> off of your local <code>master</code> branch (which tracks <code>origin/master</code>) but you aren't ready to publish <code>foo</code> to <code>origin</code> yet. Or maybe you don't ever want to push to <code>origin</code> -- perhaps the commits added a bunch of obnoxious <code>printf()</code> calls you sprinkled in to help with debugging. Anyway, whenever <code>master</code> is updated, you want to rebase <code>foo</code> onto <code>master</code>. Normally you would just type <code>git rebase master</code>, but if you're like me you may find yourself frequently typing just <code>git rebase</code> out of habit. If you do, you'll get this error message:</p> <pre><code>$ git rebase There is no tracking information for the current branch. Please specify which branch you want to rebase against. See git-rebase(1) for details git rebase &lt;branch&gt; If you wish to set tracking information for this branch you can do so with: git branch --set-upstream-to=origin/&lt;branch&gt; foo </code></pre> <p>You may be tempted to do this:</p> <pre><code>git branch --set-upstream-to=origin/master foo </code></pre> <p>but that can have devastating effects if you're in the habit of typing <code>git push</code> every few commits (you'll end up pushing your work-in-progress commits on your local <code>foo</code> branch to <code>origin</code>'s <code>master</code> branch, assuming you have <code>push.default</code> set to <code>upstream</code> like I do).</p> <p>Instead, you can configure the local <code>foo</code> branch to track your local <code>master</code> branch. Now your habit of typing <code>git rebase</code> does what you want, and an absent-minded <code>git push</code> will only mess up your local <code>master</code> branch, not <code>origin</code>'s <code>master</code> branch.</p> <p>But it's usually not worthwhile to configure a local branch to track another local branch just for <code>git rebase</code>. I think it's easier to live with remembering to type <code>git rebase master</code> instead of <code>git rebase</code>. If I forget, I get an error message that jogs my memory and I try again. No big deal.</p></li> </ul>
 

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