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 git@10.1.1.249:/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/

这下就豁然开朗了。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值