git push导致权限被拒绝或(分支当前已签出)

时间:2011-06-21 03:25:34

标签: git unix

我克隆了一个远程存储库并进行了一些提交。我试图将我的提交推回到存储库,以便其他开发人员可以获取它们。首先我尝试了:git push "other_serv" my_branch:master但我得到了

remote: error: refusing to update checked out branch: refs/heads/master[K
remote: error: By default, updating the current branch in a non-bare repository[K
remote: error: is denied, because it will make the index and work tree inconsistent[K
remote: error: with what you pushed, and will require 'git reset --hard' to match[K
remote: error: the work tree to HEAD.[K
remote: error: [K
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to[K
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into[K
remote: error: its current branch; however, this is not recommended unless you[K
remote: error: arranged to update its work tree to match what you pushed in some[K
remote: error: other way.[K
remote: error: [K
remote: error: To squelch this message and still keep the default behaviour, set[K  
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.[K
To user@server:/path/to/git
! [remote rejected] my_branch -> master (branch is currently checked out)

所以我用Google搜索了问题并在远程服务器上尝试了:

git checkout -b dummy

然后尝试再次推,但得到了同样的错误。因此,我没有向主人推进,而是试图推向假人。然后我收到了这个错误:

error: Unable to append to ./logs/refs/heads/dummy: Permission denied
To user@server:/path/to/git
 ! [remote rejected] my_branch -> dummy (failed to write)
error: failed to push some refs to 'user@server:/path/to/git'

所以我搜索了更多,发现有些人对他们的许可有问题。所以我chmod'd并且chown'd所有文件:

-rw-rw-r-- 1 user git   41 2011-06-20 20:07 dummy
-rw-rw-r-- 1 user git   41 2011-06-19 19:47 master

我可以写入dummy和master,但我仍然得到上面的错误。有人有任何解决方案?我一直在试着这个简单的问题。

修改: 似乎找到了根本原因。出于某种原因,我的repo位于/path/to/repo.git,即使我使用的所有命令都指向/ path / to / repo。这是git的一部分吗?

编辑2: 原来有一个名为./repo.git的第二个文件夹。由于./repo文件夹是裸的,git正在搜索./repo.git来查找./repo文件而不是./repo文件。在搜索./.git时,当git配置文件在./repo中时,git更喜欢./repo.git/.git ./repo

1 个答案:

答案 0 :(得分:1)

设置远程存储库时,最好使用裸存储库...

git clone --bare YourRepo/ YourRepo.git
rsync -azv YourRepo.git you@your.server.com:

现在通过ssh克隆它:

git clone ssh://you@your.server.com/~/YourRepo.git
... edit ...
git commit ...
git push origin HEAD

正如错误消息所述,使用非裸存储库存在一些权限问题。裸存储库没有关联的工作目录,因此没有这种复杂性。