侧边栏壁纸
博主头像
★街角晚灯★博主等级

博观而约取 厚积而薄发

  • 累计撰写 446 篇文章
  • 累计创建 182 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

error: failed to push some refs to ‘git@202.205.161.49:/home/git/gitolite-admin

WinJay
2013-09-03 / 0 评论 / 0 点赞 / 108 阅读 / 5422 字 / 正在检测是否收录...
温馨提示:
文章发布较早,内容可能过时,阅读注意甄别。。。。

title: error: failed to push some refs to ‘git@202.205.161.49:/home/git/gitolite-admin date: '2013-09-03T15:30:22+08:00'


此错误,在Ubuntu Server 13.04下进行测试进出现过,但在CentOS 6.4下进行此操作时未出现报错。

[git@localhost A]$ git push origin master
git@202.205.161.49’s password:
Counting objects: 3, done.
Writing objects: 100% (3/3), 231 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
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 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.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: ‘receive.denyCurrentBranch’ configuration variable to ‘refuse’.
To git@202.205.161.49:/home/git/gitolite-admin

! [remote rejected] master -> master (branch is currently checked out) error: failed to push some refs to ‘git@202.205.161.49:/home/git/gitolite-admin’ ★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
当用git push origin master把本地的修改推到服务器上时,出现了下面的错误:

Counting objects: 8, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (6/6), 515 bytes, done.
Total 6 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (6/6), done.
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 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.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: ‘receive.denyCurrentBranch’ configuration variable to ‘refuse’.
To /data/test/
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to ‘/data/test/’

对于问题和答案就在这段文字里。

红色的是原因,蓝色的是解答。

如果使用了git init初始化,则远程仓库的目录下,也包含work tree,当本地仓库向远程仓库push时, 如果远程仓库正在push的分支上(如果当时不在push的分支,就没有问题), 那么push后的结果不会反应在work tree上, 也即在远程仓库的目录下对应的文件还是之前的内容,必须得使用git reset –hard才能看到push后的内容.

解决办法:
一,在服务器上初始化仓库的时候用git –bare init;

用”git init”初始化的版本库(暂且称之为working repository)将会生成2类文件:“.git“版本库目录(记录版本历史)和实际项目文件的拷贝。你可以把这类版本库叫做“工作目录”。工作目录是一个包含有版本历史目录“.git”和源文件的目录。你可以在工作目录修改你的源文件并使用”git add”和”git commit”命令进行版本管理。

用“git init –bare”初始化的版本库(暂且称之为bare repository)仅包含”.git”目录(记录版本历史),不含项目源文件拷贝。如果你进入版本目录,你会发现仅有”.git”目录,没有其他文件。版本库仅包含记录着版本历史的文件。

二,如果用的是git init的话,就要修改下服务器上的配置(.git/config),添加:
[receive]
denyCurrentBranch = ignore

0
  1. qrcode alipay
  2. qrcode weixin

评论区