git - 更改推送建议的默认遥控器
问题描述
当我创建一个新分支并第一次执行git push
时,它失败并给了我这样的建议:
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
如何更改origin
它建议推送到的默认遥控器?我希望它表明我添加的不同来源:git push --set-upstream different-origin new-branch
.
解决方案
这里打印的名字是通过函数获取的pushremote_for_branch
,内容如下:
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);
此处,如果已设置,则branch->pushremote_name
来自配置项。同时,将答案填入。如果这些都没有提供答案,则回退是使用.branch.name.pushRemote
remote.pushDefault
remote_for_branch
branch.name.remote
因此:
git branch newbranch
git config branch.newbranch.pushremote newremote
将保证默认为newremote
. 但是,如果您不想运行git config branch.newbranch.pushremote
——当然,如果你刚刚创建它,它就不会被配置——那么:
git config remote.pushdefault newremote
将为每个还没有明确的 pushremote 设置的分支设置推荐和默认值。如果这太全局化,您将需要一个明确的,无论是还是,以便该设置仅适用于该一个分支。git config branch.newbranch.something
something
pushremote
remote
(你可以拼写它pushRemote
,就像文档一样,或者甚至PUSHREMOTE
或者PUshreMOte
其他,如果你喜欢的话。Git 在内部将所有内容都转换为小写,然后比较小写名称。)
推荐阅读
- angular - 在 Angular 4+ 应用程序中重定向后,滑块和轮播未加载
- mockito - 如何在 Mockito 中使用软断言?
- android - 将一些函数从 mainactivity 移动到另一个类
- php - 从另一个页面获取 ID 值
- c - 如何在 switch-case 中使用函数?
- python - 在 Python 中使用 Pandas 从 csv 生成简单图
- python - 怎么了?
- amp-html - 缓存的 AMP 页面内容与我网站上的 AMP 内容不一致
- java - java中BitSet的nextClearBit()实际上是如何工作的?
- awk - 使用 bash 从单行变量回显有效证书文件