代码之家  ›  专栏  ›  技术社区  ›  Jimmix

git config default push不适用于名称不是origin的远程服务器

  •  1
  • Jimmix  · 技术社区  · 6 年前

    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 或者我错过了什么?也许git在找 默认情况下,但在不同的名称,我需要告诉它,不同的名称是默认的?

    如何设置不同于 起源

    解决方案应该与将来创建的新分支一起工作。

    1 回复  |  直到 6 年前
        1
  •  0
  •   VonC    6 年前

    仅仅添加一个新的远程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 查询当前分支的配置以确定推送位置。
    如果缺少配置,则默认为 起源 .