推进一个非裸露的回购 - 在我当地的两个回购,Git

时间:2013-06-19 13:13:24

标签: git repository git-push

我的本​​地计算机上有两个回购,说local1local2。所以我从local1

跑了
git push local2 sombranch

我得到了这个

remote: error: refusing to update checked out branch: refs/heads/5-0-stable
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 to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
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 some
remote: error: other way.

这两个回购的历史几乎完全相同,而且不同之处也不会产生冲突。我被迫改变receive.denyCurrentBranch吗?我真的不想通过这个命令git config --bool core.bare true

将远程仓库变成一个裸仓库

1 个答案:

答案 0 :(得分:1)

如果你不想让local2成为一个简单的回购,你有几个选择:

1)设置receive.denyCurrentBranch。但我认为git错误消息很清楚地解释了这可能会在以后引起问题,所以也许最好避免使用。

2)在local2中检查一个不同的分支,然后从local1进行推送。只有当您尝试推送到远程存储库中检出的分支时才会发生错误,因此可以通过检出其他分支来避免错误(这也消除了错误中描述的工作树/ HEAD同步问题) 。)

3)也许最直接的,来自local2,就这样做:

git pull local1

由于git pull更新了HEAD,索引和工作树中的所有三个,因此没有像git push那样的同步问题,只会改变HEAD。