用裸Git仓库推动失败

时间:2016-05-18 13:56:06

标签: git git-push git-remote git-bare

我有一个远程裸仓库master和一个本地分支机构cloud,我已将其设置为跟踪

git branch cloud -u amazon/master

git push

结果

  

致命:您当前分支的上游分支不匹配   您当前分支的名称。

我已经尝试过在related question中建议的解决方案(就像我能说的那样,我上面做了什么),但它也会出现同样的错误。

如何进行配置跟踪,以便git push单独推送到遥控器?

config的相关部分:

[remote "amazon"]
        url = ssh://ubuntu@ecXXXXXXXX.us-west-2.compute.amazonaws.com/home/ubuntu/mlcode.git
        fetch = +refs/heads/*:refs/remotes/amazon/*
[branch "cloud"]
        remote = amazon
        merge = refs/heads/master

1 个答案:

答案 0 :(得分:1)

运行

git config push.default upstream

将为您提供所需的行为。

根据git config documentation,版本2.0中的默认行为是

  
      
  • simple - 在集中式工作流程中,如果上游分支的名称与本地分支的名称不同,就像上游一样增加安全性以拒绝推送。

         

    当推送到与您通常拉出的遥控器不同的遥控器时,请作为当前工作。这是最安全的选择,适合初学者。

  •   

相反,upstream模式的操作如下。

  
      
  • upstream - 将当前分支推回到其更改通常集成到当前分支(称为@{upstream})的分支。如果您要推送到通常从中提取的相同存储库(,中央工作流程),则此模式才有意义。
  •   

使用与您类似的存储库

$ git branch
* cloud
  master

并没有任何问题

$ git config --unset push.default

尝试推送会产生相同的错误。详细模式(-v)就在那里,你可以看到git正在做什么。

$ git push -v
fatal: The upstream branch of your current branch does not match
the name of your current branch.  To push to the upstream branch
on the remote, use

    git push amazon HEAD:master

To push to the branch of the same name on the remote, use

    git push amazon cloud

To choose either option permanently, see push.default in 'git help config'.

配置更改后

$ git config push.default upstream

你得到了问题中描述的行为。

$ git push -v
Pushing to .../amazon/
To .../amazon/
 = [up to date]      cloud -> master
updating local tracking ref 'refs/remotes/amazon/master'
Everything up-to-date