【问题标题】:git config default push does not work for remote with name other than origingit config default push 不适用于名称不是 origin 的远程
【发布时间】:2019-03-12 01:08:45
【问题描述】:

如果我以这种方式添加远程存储库地址并将其设置为默认值:

git init .

remoteName="origin"
dstUrl='location-of-initialized-bare-repository'
git remote add "$remoteName" "$dstUrl"

git config push.default current

touch masterfile
git add masterfile
git commit -m 'first'
git push


git checkout -b feature
touch feautrefile
git add feautrefile
git commit -m 'second'
git push

一切正常。 但是当我以不同的方式设置远程名称时,即:

remoteName="something"

致命:未配置推送目标。

我认为遥控器的名称是任意的,可以设置为任何值而没有任何区别,但似乎对于git push 使用的默认遥控器没有任何参数,它必须是origin 或 I'我错过了什么?也许 git 默认会查找origin,但如果名称不同,我需要告诉它不同的名称是默认名称?

如何设置与origin不同的默认远程名称?

该解决方案应该适用于将来创建的新分支。

【问题讨论】:

    标签: git key push config default


    【解决方案1】:

    仅添加新的远程 URL/名称不会使本地分支能够推送到它。

    您需要使用该新遥控器至少一次:

    git push -u newRemoteName myBranch 
    

    见“Understanding .git/config's 'remote' and 'branch' sections

    这确实将branch.myBranch.remote 设置为newRemoteName,然后使简单的git push 能够工作。

    第一次推送有效,因为它默认为一个名为(按照约定)“origin”的远程。
    git push

    当命令行未使用 <repository> 参数指定推送位置时,会参考当前分支的 branch.*.remote 配置以确定推送位置。
    如果缺少配置,则默认为origin

    【讨论】:

      猜你喜欢
      • 2014-10-17
      • 1970-01-01
      • 2017-04-25
      • 2021-07-14
      • 2021-09-09
      • 2018-10-31
      • 2011-10-10
      • 2012-06-09
      • 2012-04-21
      相关资源
      最近更新 更多