使用裸 Git 回购推送失败

Failed push with bare Git repo

我有一个远程裸仓库 master 和一个本地分支 cloud 我已设置为跟踪它

git branch cloud -u amazon/master

但是

git push

结果

fatal: The upstream branch of your current branch does not match the name of your current branch.

我已经尝试了 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

运行

git config push.default upstream

会给你想要的行为。

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

  • simple - in centralized workflow, work like upstream with an added safety to refuse to push if the upstream branch’s name is different from the local one.

    When pushing to a remote that is different from the remote you normally pull from, work as current. This is the safest option and is suited for beginners.

相比之下,upstream模式操作如下。

  • upstream - push the current branch back to the branch whose changes are usually integrated into the current branch (which is called @{upstream}). This mode only makes sense if you are pushing to the same repository you would normally pull from (i.e., central workflow).

使用类似于您的存储库

$ 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