这与 repo 作为子模块无关。
您正在使用工作副本(非裸仓库)推送到 git 存储库,并尝试推送到当前已签出的同一分支 - 默认情况下 git 不允许您这样做。
在继续之前,您应该问自己是否真的想这样做。这类似于,假设您直接克隆了一个同事 repo,然后尝试推送到它。如果您成功了,如果您的同事有未提交的更改,或者更新时将被跟踪文件覆盖的本地文件,您可能会导致他们失去工作。
简单的解决方案
最简单的解决方案是根本不推送,而是从您的其他仓库中提取。最终结果是相同的,但是由于您正在拉入更新(这很正常),git 不会对此发表任何评论。
稍微不太容易的解决方案
You can push into your other working copy, if you change the receiving repo's git config (read the rest of the error message) to allow it to be pushed into. To do that, in the receiving repo:
git config receive.denyCurrentBranch ignore
More details about that are in the help (git config --help
)
receive.denyCurrentBranch
If set to true or "refuse", git-receive-pack will deny a ref update to the
currently checked out branch of a non-bare repository. Such a push is potentially
dangerous because it brings the HEAD out of sync with the index and working tree.
If set to "warn", print a warning of such a push to stderr, but allow the push to
proceed. If set to false or "ignore", allow such pushes with no message. Defaults
to "refuse".