git推子模块
我使用git clone将存储库A克隆到存储库B/somedirectory/b.git。后来,我决定在Bgit推子模块,git,Git,我使用git clone将存储库A克隆到存储库B/somedirectory/b.git。后来,我决定在Bgit子模块add/path/to/C.git C_中添加子模块C。那么,我如何将子模块的添加推回到A中呢 尝试使用git push,但出现以下错误 remote: error: refusing to update checked out branch: refs/heads/master remote: error: By default, updating the current br
git子模块add/path/to/C.git C_中添加子模块C。那么,我如何将子模块的添加推回到A中呢
尝试使用git push,但出现以下错误
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable t
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing int
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in som
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, se
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
这是因为您正试图推送到一个非裸存储库。首先创建要推送到的裸存储库。只需将--bare添加到clone命令中
发生这种情况的原因是为了防止工作损失。拥有一个工作目录意味着,如果要从外部更新分支,您可能会丢失工作 这是git的一般行为,即使子模块不在图中。您正在推送到一个repo(a),它是一个“工作存储库”或“非裸存储库”,git默认不允许您这样做,您看到的错误消息显示了原因和解决方法
在您的情况下,我认为您可以根据错误建议更新A中的配置(设置receive.denyCurrentBranch
为warn
或ignore
),或者只签出A上的另一个分支,然后从B推送。长期使用时,使用裸回购进行推送。如其他答案所示,在作为工作副本的存储库和作为裸存储库(~服务器)的存储库之间似乎存在一些混淆
你最好的办法是在心理上区分这两个。工作副本是实现更改、提交更改并将其推送到“服务器存储库”的地方。服务器存储库通常是空存储库,这正是您在尝试推送时可以看到的原因。工作副本可能包含更改,这些更改将通过修改工作副本中的基础.git目录而被删除
解决此问题的最简单方法是将远程存储库指向“服务器存储库”,即保留更改的裸存储库。如果您还没有服务器repo,您可能需要为模块创建它们。在这之后你可以做什么
git remote rm origin
git remote add origin ssh://username@remote_repository
对于子模块和顶部回购 您不能像那样推入非裸存储库。