博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
git push origin master 报错 remote rejected] master -> master (branch is currently checked out)
阅读量:7037 次
发布时间:2019-06-28

本文共 3198 字,大约阅读时间需要 10 分钟。

解决办法:

 

977

You can simply convert your remote repository to bare repository (there is no working copy in the bare repository - the folder contains only the actual repository data).

Execute the following command in your remote repository folder:

git config --bool core.bare true

Then delete all the files except .git in that folder. And then you will be able to perform git push to the remote repository without any errors.

 
4  
Thanks. I also needed this. I was following the submodules tutorial from the  and hit this roadblock. –  
5  
I wasn't sure whether you meant to delete files on the server, or the client ... so I didn't delete anything, and the problem goes away after just doing git config --bool core.bare true. Is there any particular reason some files need to be deleted? If so, can you be more precise about what needs to be deleted? –  
18  
It's the best possible answer and nobody else have provided it in the hole Interwebs. I think that we all googled the same error message and we all were extremely happy to read this. –  
24  
Although it got a whole lot of votes, I don't think this is a really adequate answer to that specific question. Instructing the user how to cleanly create a bare repo would be half as bad, but what if the files need to stay checked out, for example when it's the repository the user is working with on two computers? –  
4  
Changing the source repo to bare is overkill. All you need to do is push to a new branch in the source repo, as @Robert points out: . –  

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

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

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

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@192.168.1.X:/var/git.server/.../web
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'git@192.168.1.X:/var/git.server/.../web'

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

    [receive]

    denyCurrentBranch = ignore

 

在初始化远程仓库时最好使用 git --bare init   而不要使用:git init

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

转载地址:http://rpnal.baihongyu.com/

你可能感兴趣的文章
nginx自定义header头内容丢失
查看>>
配置路由器/交换机的Telnet登录
查看>>
重装eclipse遇到的一些问题整理
查看>>
短信验证码接收app必须注意的那些事
查看>>
HTTP通俗介绍
查看>>
HttpClient以及Json传递的一些坑
查看>>
loadrunner11压力测试自学成才!嘎嘎
查看>>
Ext.Net系列:二Event之DirectEvent 示例1-调用事件顺序
查看>>
基于搜狗搜索的微信公众号爬虫实现(C#版本)
查看>>
朋友们谁知道哪里培训PHP比较靠谱的?
查看>>
cnetos6上实现nfs共享
查看>>
若是在做销售源码生意的,还是用 VS2008 省事一些,今天有一个客户没 VS2010 只好再把程序倒退回来...
查看>>
.NET大型C/S系统可动态设置登录窗口的实现参考
查看>>
磁盘的读写原理
查看>>
转-快速编辑Shell命令行
查看>>
【中医养生门户网】注意!春分在于“生、升”,保肝促阳为重
查看>>
SQL 语句技巧--聚合函数的灵活使用
查看>>
Java调用SQL Server的存储过程详解
查看>>
springmvc - SqlSession
查看>>
Json 简介
查看>>