https://blog.csdn.net/jacolin/article/details/44014775

在使用Git Push代码到数据仓库时,提示如下错误:

[remote rejected] master -> master (branch is currently checked out)

错误原型:

  1.  
    remote: error: refusing to update checked out branch: refs/heads/master
  2.  
     
  3.  
    remote: error: By default, updating the current branch in a non-bare repository
  4.  
     
  5.  
    remote: error: is denied, because it will make the index and work tree inconsistent
  6.  
     
  7.  
    remote: error: with what you pushed, and will require 'git reset --hard' to match
  8.  
     
  9.  
    remote: error: the work tree to HEAD.
  10.  
     
  11.  
    remote: error:
  12.  
     
  13.  
    remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
  14.  
     
  15.  
    remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
  16.  
     
  17.  
    remote: error: its current branch; however, this is not recommended unless you
  18.  
     
  19.  
    remote: error: arranged to update its work tree to match what you pushed in some
  20.  
     
  21.  
    remote: error: other way.
  22.  
     
  23.  
    remote: error:
  24.  
     
  25.  
    remote: error: To squelch this message and still keep the default behaviour, set
  26.  
     
  27.  
    remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
  28.  
     
  29.  
    To git@192.168.1.X:/var/git.server/.../web
  30.  
     
  31.  
    ! [remote rejected] master -> master (branch is currently checked out)
  32.  
     
  33.  
    error: failed to push some refs to 'git@192.168.1.X:/var/git.server/.../web'

解决办法:

这是由于git默认拒绝了push操作,需要进行设置,修改.git/config文件后面添加如下代码:

  1.  
    [receive]
  2.  
    denyCurrentBranch = ignore

无法查看push后的git中文件的原因与解决方法

在初始化远程仓库时最好使用

git --bare init

而不要使用:git init

git init 和git --bare init 的具体区别:http://blog.haohtml.com/archives/12265

=================================================

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

解决方法:

必须得使用命令 git reset --hard 才能看到push后的内容.

研究了很久不得其解,然后找到一条命令凑合着能用了:

登录到远程的那个文件夹,使用
git config --bool core.bare true

就搞定了。

贴一段参考文章:

Create a bare GIT repository

A small rant: git is unable to create a normal bare repository by itself. Stupid git indeed.

To be precise, it is not possible to clone empty repositories. So an empty repository is a useless repository. Indeed, you normally create an empty repository and immediately fill it:

git init git add .

However, git add is not possible when you create a bare repository:

git --bare init git add .

gives an error "fatal: This operation must be run in a work tree".

You can't check it out either:

Initialized empty Git repository in /home/user/myrepos/.git/ fatal: http://repository.example.org/projects/myrepos.git/info/refs not found: did you run git update-server-info on the server? git --bare init git update-server-info # this creates the info/refs file chown -R <user>:<group> . # make sure others can update the repository

The solution is to create another repository elsewhere, add a file in that repository and, push it to the bare repository.

mkdir temp; cd temp git init touch .gitignore git add .gitignore git commit -m "Initial commit" git push <url or path of bare repository> master cd ..; rm -rf temp

转自:http://www.cnblogs.com/cosiray/archive/2012/06/01/2530967.html

"remote:error:refusing to update checked out branch:refs/heads/master"的解决办法(转)的更多相关文章

  1. remote:error:refusing to update checked out branc

    参考网上的GIt服务器配置流程(http://blog.csdn.net/ice520301/article/details/6142503) 遇到了 http://www.cnblogs.com/c ...

  2. git报错error: src refspec refs/heads/master does not match any.

    $ git pusherror: src refspec refs/heads/master does not match any.error: failed to push some refs 出错 ...

  3. git push 时发生 error: failed to push some refs to 错误 (解决办法)

    出现问题的原因:在github上更新了README.md,没有更新到本地仓库.而在本地git仓库又修改了文件,这时使用 git push origin master 推送到远程仓库后就出现了下面的问题 ...

  4. mysql 错误 ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number 解决办法

    MySQL创建用户(包括密码)时,会提示ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number: 问题原因: ...

  5. Error:The network adaptor could not establish the connection问题的解决办法

     最近在学习hibernate 5.0.4, 自然而然就需要使用数据库,由于本人工作中一直使用Oracle,于是在自己的电脑上安装了Oracle 12.1.0, 安装完成使用一直没有问题,突然有一天使 ...

  6. VC++编译错误error C2065: “HANDLE”: 未声明的标识符及添加winbase.h后提示winbase.h(243): error C2146: 语法错误: 缺少“;”(在标识符“Internal”的前面)的解决办法

    问题描述: VC++程序编译时提示错误:error C2065: “HANDLE”: 未声明的标识符等众多错误提示,如下所示: error C2065: “HANDLE”: 未声明的标识符 error ...

  7. 《OpenGL编程指南第七版》学习——编译时提示“error C2381: “exit” : 重定义;__declspec(noreturn) 不同”错误的解决办法

    解决办法一. #if defined(_WIN32) # ifndef GLUT_BUILDING_LIBextern _CRTIMP void __cdecl exit(int); 上面是glut. ...

  8. 【转】bootstrap模态框(modal)使用remote方法加载数据,只能加载一次的解决办法

    http://blog.csdn.net/coolcaosj/article/details/38369787 bootstrap的modal中,有一个remote选项,可以动态加载页面到modal- ...

  9. mysql远程访问 登录ERROR 1130: is not allowed to connect to this MySQL server解决办法

    LINUX6.3 里装了mysql5.0.18 版本运行服务器. 提示错误为: ERROR 1130: Host '192.168.0.102' is not allowed to connect t ...

随机推荐

  1. 20165326 java实验一

    <Java程序设计>Java开发环境的熟悉 实验报告 课程:Java程序设计 班级:1653班 姓名:陈卓 学号:20165326 指导教师:娄嘉鹏 实验日期:2018年4月2日 实验时间 ...

  2. [Spring]初识Spring-Spring的基础使用-如何通过Bean来实例化?

    Spring框架的基础使用 XML配置信息,Bean的不同实例化方式,注入 实例化 XML文件中的参数设置 1.通过构造器进行实例化(重点,常用方式) <bean name="aCls ...

  3. cc、gcc、g++、CC的区别概括

    gcc是C编译器:g++是C++编译器:linux下cc一般是一个符号连接,指向gcc:gcc和g++都是GUN(组织)的编译器.而CC则一般是makefile里面的一个名字,即宏定义,嘿,因为Lin ...

  4. debian镜像下载地址

     http://cdimage.debian.org/debian-cd/9.8.0-live/amd64/iso-hybrid/ 

  5. Day11作业及默写

    1.写函数,传入n个数,返回字典{'max':最大值,'min':最小值} 例如:min_max(2,5,7,8,4) 返回:{'max':8,'min':2}(此题用到max(),min()内置函数 ...

  6. OneinStack 安装

    安装步骤 注意 如果有单独数据盘,建议您先挂载数据盘,建议将网站内容.数据库放在数据盘中.如何挂载数据盘,请参考(支持阿里云.腾讯云):<如何利用脚本自动化挂载数据盘?> yum -y i ...

  7. python day14--内置函数二

    主要内容: 1.lamda匿名函数 2.sorted() 3.filter() 4.map() 5.递归函数 一.Lamda匿名函数 语法:lamda:参数:返回值 # 计算n的n次⽅方 def fu ...

  8. ORACLE中使用DBMS_RANDOM去产生随机数

    一.生成随机字符串:DBMS_RANDOM.STRING 用法:DBMS_RANDOM.STRING(选项, 返回字符串长度) 选项有如下几种可供选择:1)'u', 'U' - returning s ...

  9. SQL注入之Sqli-labs系列第十五关和第十六关(基于POST的时间盲注)

    开始挑战第十五关(Blind- Boolian Based- String)和 第十六关(Blind- Time Based- Double quotes- String) 访问地址,输入报错语句 ' ...

  10. 设计精美Power BI报告的五大秘诀

    众所周知,Power BI可以帮助您创建交互式且信息丰富的报告,但使用Power BI 制作精美而实用的报告对我们这群IT人员而言,却是一个巨大的痛苦:但个人觉得不能就此止步,通过不断实践练习,小悦采 ...