Reputation: 64925
When I create a new branch and do git push
for the first time, it fails and gives me a suggestion like so:
fatal: The current branch new-branch has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin new-branch
How can I change the default remote origin
that it suggests pushing to? I want it to suggest a different origin that I have added: git push --set-upstream different-origin new-branch
.
Upvotes: 0
Views: 76
Reputation: 488203
The name printed here is obtained by the function pushremote_for_branch
, which reads:
if (branch && branch->pushremote_name) {
if (explicit)
*explicit = 1;
return branch->pushremote_name;
}
if (pushremote_name) {
if (explicit)
*explicit = 1;
return pushremote_name;
}
return remote_for_branch(branch, explicit);
Here, branch->pushremote_name
comes from the configuration item branch.name.pushRemote
if that's set. Meanwhile, remote.pushDefault
fills in the answer in remote_for_branch
. If neither of those supply the answer, the fallback is to use branch.name.remote
.
Hence:
git branch newbranch
git config branch.newbranch.pushremote newremote
will guarantee that the default is newremote
. But if you don't want to have to run git config branch.newbranch.pushremote
—and of course it won't already be configured if you just created it—then:
git config remote.pushdefault newremote
will set a recommendation—and a default—for every branch that doesn't already have an explicit pushremote setting. If that's too global, you'll need an explicit git config branch.newbranch.something
, whether the something
is pushremote
or remote
, so that the setting is just for that one branch.
(You can spell it pushRemote
, as the documentation does, or even PUSHREMOTE
or PUshreMOte
or whatever, if you like. Git internally translates everything to lowercase, and then compares the lowercase names.)
Upvotes: 1