git远程共享库push代码出错

今天在服务器端搭建完git远程共享库,在本地clone后,按照常规套路执行git add, git commit都没有问题,但执行git push origin master命令后,文件死活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 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 [email protected]:/home/git/another
! [remote rejected] master -> master (branch is currently checked out)

一顿查资料,发现是建共享库时参数不对,应该是git init --bare,我建库时没有加--bare参数。

在查资料的过程中,发现一个网址不错,www.gitguys.com,其中有如下解释:

Shared Repositories Should Be Bare Repositories

When creating a central repository that will be shared by other users, the repositories should be created with the –bare option:
gitadmin$ git init --bare project1.git
Initialized empty Git repository in /home/gitadmin/project1.git/

When you create a git repository with the –bare option:
There is no working directory created.
There is no .git directory created. Instead, the files normally in the .git directory are placed in the top-level directory where the working directory would normally be.
gitadmin$ cd project1.git
gitadmin$ ls
branches/ config description HEAD hooks/ info/ objects/ refs/

这下就豁然开朗了。



你可能感兴趣的:(git,版本管理)