解决办法:

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.

answered Jul 14 '10 at 22:45
John

9,865185
 
4  
Thanks. I also needed this. I was following the submodules tutorial from the Git Community Book and hit this roadblock. – Shiki Sep 14 '10 at 15:20
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? – Brian Vandenberg Jul 22 '11 at 4:19
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. – Sebastián Grignoli Jul 16 '12 at 14:56
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? – Nowhere man Mar 18 '13 at 10:38
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: stackoverflow.com/a/2933656/402949. – Dan Solovay Oct 7 '13 at 1:16

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

在使用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后的内容.

git push origin master 报错 remote rejected] master -> master (branch is currently checked out)的更多相关文章

  1. git推送代码报错:fatal: The current branch master has no upstream branch. To push the current branch and set the remote as upstream

    情景再现 远程新建仓库,然后本地 git bash执行以下代码 git init git add . git commit -m 'xxx' git remote add origin https:/ ...

  2. Git Push大文件报错后如何撤回

    昨晚在提交一个项目代码时,不小心把数据库备份文件也一起Commit了:到最后Push的时候报错了.最后弄了半天解决了,在此记录下. 如下图,文件有108M. 项目放在第三方托管平台上,根据提示查看了原 ...

  3. git 新建本地分支后将本地分支推送到远程库, 使用git pull 或者 git push 的时候报错

    是因为本地分支和远程分支没有建立联系  (使用git branch -vv  可以查看本地分支和远程分支的关联关系)  .根据命令行提示只需要执行以下命令即可git branch --set-upst ...

  4. [GitHub] git push的时候报错 fatal: unable to access 'http://github.com/xxx/xxx.git/': Recv failure: Connection reset by peer

    参考了两种方法: 1. 解决fatal: unable to connect to github.com问题 http://blog.csdn.net/greenqingqingws/article/ ...

  5. git push的时候报错: Out of memory, malloc failed (tried to allocate 82037333 bytes)

    原因:上传的文件过大,这里我上传的文件有10G+所以报了上面的错误 解决方法:依次运行:git config --global pack.threads 1 git,git config --glob ...

  6. git 解决push报错:[rejected] master -> master (fetch first) error: failed to push some refs to

    今天对代码进行了修改优化,然后往往远程push,但push后报错了 git操作 git add . git commit -m"fix" git push origin maste ...

  7. Git push时报错 ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to......

    今天在使用Git回退到之前某个版本的代码时,进行push时出现如下错误: ! [remote rejected] master -> master (pre-receive hook decli ...

  8. git push远程仓库时报错:fatal: remote origin already exists. (已解决)

    在做远程仓库调试阶段,突然发现修改后的项目无法push了: 如果输入$ git remote add origin git@github.com:djqiang(github帐号名)/gitdemo( ...

  9. git push origin master、git pull出现如下错误

    git push origin master出现如下错误: Counting objects: , done. Writing objects: % (/), bytes, done. Total ( ...

随机推荐

  1. 第九十四节,html5+css3移动手机端流体布局,旅游部分,媒体查询

    html5+css3移动手机端流体布局,旅游部分,媒体查询 媒体查询 媒体查询是手机网站和自适应网站的重要部分,媒体查询可以根据不同的屏幕大小,做响应的处理,如文字的大小,区块隐藏等等 媒体查询,这里 ...

  2. 在 Sublime Text 3 中快捷打开 git-gui

    在文件夹右键菜单上可以方便的打开 git-gui,在 st 里面也可以添加这个右键菜单. 步骤如下: 安装 SideBarEnhancements 插件. 在 SideBarEnhancements ...

  3. Amazon EC2 的名词解释

    Amazon EC2   Amazon Elastic Compute Cloud (Amazon EC2) Amazon EC2 提供以下功能: 实例:虚拟计算环境 实例预配置模板/Amazon 系 ...

  4. 屏幕坐标和世界坐标的转换+对象池技术(3D打地鼠小游戏)

    游戏中可能经常会遇到需要某个物体跟着鼠标移动,然后又需要把物体放在某个鼠标指定的位置 实现方式 Camera.main.WorldToScreenPoint Camera.main.ScreenToW ...

  5. 触动精灵远程Log模块

    一.功能 lua log方法能够自动发现同一网段下面的log服务器 lua log方法能够主动将log发给服务器 lua 客户端进程重启服务端不存在影响 二.实现 服务器使用python编写: 启动一 ...

  6. 如何自定义JSR-303标准的validator

    在web应用中为了保证数据的有效性而对用户提交的表单数据是必需的,而前台客户端的验证例如javascript并不总是那么安全和可靠,这样我们就需要一个健壮的后台验证框架来处理这个问题.好在java发布 ...

  7. [ An Ac a Day ^_^ ] CodeForces 677B Vanya and Food Processor 模拟

    题意: 你有一个榨汁机 还有n个土豆 榨汁机可以容纳h高的土豆 每秒可以榨k高的东西 问按顺序榨完土豆要多久 思路: 直接模拟 一开始以为是最短时间排了个序 后来发现多余了…… #include< ...

  8. NOIP2014-普及组复赛-第一题-珠心算测验

    题目描述 Description 珠心算是一种通过在脑中模拟算盘变化来完成快速运算的一种计算技术.珠心算训练,既能够开发智力,又能够为日常生活带来很多便利,因而在很多学校得到普及. 某学校的珠心算老师 ...

  9. UISlider 滑竿控件

    UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake:(100, 100, 200, 25);  //创建一个滑竿对象 slide ...

  10. OpenStack回顾随笔(第一章)

    1. OpenStack历史    OpenStack前身是NASA和Rackspace合作的项目,2010年开源,与其他主流开源云管理系统:Citrix的Cloudstack和桉树的OpenNebu ...