解决办法:

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. line-height:2、line-height:2em、line-height:200%的区别

    文章来源: http://www.zhihu.com/question/20394889 总结: 1.line-height:2em.line-height:200%  根据父元素的字体大小计算行高 ...

  2. js nextSibling属性和previousSibling属性概述及使用注意

    1:nextSibling属性 该属性表示当前节点的下一个节点(其后的节点与当前节点同属一个级别):如果其后没有与其同级的节点,则返回null. 需要特别注意的是:该属性在不同的浏览器中的执行结果并不 ...

  3. 高精度之+×÷

    以下是三种高精度算术的模版: 高精度加法: ",s1,s2; ],ss2[],len; void dashu(string s1,int ss1[]) { ;i>=;i--) { ;j ...

  4. SOJ 1210 二叉树

    1210. 二叉树 Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description 在众多的数据结构中,二叉树是一种特殊而重要的结构,有 ...

  5. SharePoint 2013 图文开发系列之列表定义高级篇

    转载自  http://www.cnblogs.com/jianyus/p/3484714.html SharePoint列表库,是我们使用过程中最常用的库,下面,我们简单介绍下代码定义自定义列表,主 ...

  6. 10.按要求编写Java应用程序。 (1)创建一个叫做People的类: 属性:姓名、年龄、性别、身高 行为:说话、计算加法、改名 编写能为所有属性赋值的构造方法; (2)创建主类: 创建一个对象:名叫“张三”,性别“男”,年龄18岁,身高1.80; 让该对象调用成员方法: 说出“你好!” 计算23+45的值 将名字改为“李四”

    package com.hanqi.test; public class People { private String name,sex; private int age; private doub ...

  7. qsort函数辅助函数compare函数的编写

    qsort的第四个参数,辅助函数compare的关于不同排序对象的不同写法: 一.对int类型数组排序 ]; int compare(const void *a, const void *b) { r ...

  8. mysql表备份及还原

    备份 导出数据库所有表结构 ? 1 mysqldump -uroot -ppassword -d dbname > db.sql 导出数据库某个表结构 ? 1 mysqldump -uroot ...

  9. tableIView 区头的一点问题

    要记得设置区头的高度 否则会出现第一行没区头问题

  10. div盒子水平垂直居中的方法

    这个问题比较老,方法比较多,各有优劣,着情使用. 一.盒子没有固定的宽和高 方案1.Transforms 变形 这是最简单的方法,不仅能实现绝对居中同样的效果,也支持联合可变高度方式使用.内容块定义t ...