git添加远程仓库后不能push

 徐天凝_669 发布于 2022-10-26 04:26

自己有一个阿里云的ECS(CentOS7),需要把项目放到上面去,但不想通过github,想直接在本地git仓库中添加远程仓库,直接push到ECS上。
在ECS中先创建了项目目录,并且初始化了仓库:$ git init
在本地仓库中添加远程仓库:

$ git remote add ECSmaster ssh://username@IP/~/path/.git

添加好之后却不能push,错误信息如下:

$ git push -u ECSmaster master
username@IP's password:
Counting objects: 180, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (75/75), done.
Writing objects: 100% (180/180), 32.15 KiB | 0 bytes/s, done.
Total 180 (delta 104), reused 180 (delta 104)
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 ssh://username@IP/~/cloudNote/.git
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'ssh://username@IP/~/cloudNote/.git'


$ git remote show ECSmaster
username@IP's password:
* remote ECSmaster
  Fetch URL: ssh://username@IP/~/cloudNote/.git
  Push  URL: ssh://username@IP/~/cloudNote/.git
  HEAD branch: (unknown)

以上操作参考的是这篇文章:http://www.cnblogs.com/xiaoya901109/archive/2012/08/03/2620664.html

2 个回答
  • 远程服务器输入以下:
    git config 'receive.denyCurrentBranch' warn

    这种错误是出于git的一种保护措施 master->master 怕误操作

    2022-10-27 00:41 回答
  • 服务器上初始化仓库时应该加上--bare参数
    git init --bare

    2022-10-27 00:41 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有