在使用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

无法查看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

git使用经验(一)的更多相关文章

  1. Git使用经验小结

    2012春,开始正式使用SVN,2014年9月加入一起好后,开始使用Git.  有了一些使用经验,也看了下网上关于"Git全胜SVN"的言论. 结合自己的实际情况,简要写几句: 1 ...

  2. git使用经验

    一直想写一点关于git的文章,但是平时太懒了,没有写,现在写些经验这里,方便以后自己忘记了.

  3. [Tips] Git使用经验

    brach 查看目前branch git branch 显示结果: * master *表示这是当前的branch. 建立分支 git branch 分支名 删除分支 git branch -d 分支 ...

  4. git使用经验for windows

    一.本地同步fork的最新版本 二.git命令 一.本地同步fork的最新版本 ①打开Git CMD工具,进入git的主目录 ②使用 git remote -v 查看fork的远程仓库地址 origi ...

  5. git 使用经验与技巧总结 (不断更新中)

    git 使用技巧总结   说明: 本地repo已经有啦,对应的远程repo 为tiger, 本地分支为master.    问题一: 当拉取代码的remote repo仓库为tiger, 而现在要将修 ...

  6. Git详解之三 Git分支

    相关文档 — 更多 Git 基础培训.ppt GIT 使用经验.ppt GIT 介绍.pptx GIT 分支管理是一门艺术.docx Eclipse上GIT插件EGIT使用手册.docx git/gi ...

  7. GIT 这么好用,为什么还是有人不知道怎么用它提交代码?

    客户端代码管理工具的变迁: 从 SVN 到 GIT 截止目前,新版的 APICloud Studio 2 仍然处于公测期.APICloud Studio 2 的代码管理客户端,由 SVN 改为了 GI ...

  8. git summary

    Git 使用经验 缘起 一直想写一篇博文,记录我在使用git时遇到的问题以及解决办法.由于项目忙,偶尔的记录不连续,不成系统.今天有时间记录下来,方便自己以后查看. git 简介及其优势 简单来说,g ...

  9. git安装使用详解

    Git是分布式版本控制系统,那么它就没有中央服务器的,每个人的电脑就是一个完整的版本库,这样,工作的时候就不 需要联网了,因为版本都是在自己的电脑上.既然每个人的电脑都有一个完整的版本库,那多个人如何 ...

随机推荐

  1. Ubuntu常用shell命令

    目录 ls cd mkdir mv cp scp rm df du chmod chown chgrp head tail screen apt-get Ubuntu常用shell命令 Ubuntu作 ...

  2. NO.05--谈一谈Angular 和 Vue.js 的对比。

    几天的vue之后,给需要的盆友们带来一篇对比,也算是我近期之内业余时间的大工程,现在开始: Vue.js 是开源的 JavaScript 框架,能够帮助开发者构建出美观的 Web 界面.当和其它网络工 ...

  3. HDU-6315:Naive Operations(线段树+思维)

    链接:HDU-6315:Naive Operations 题意: In a galaxy far, far away, there are two integer sequence a and b o ...

  4. flask_sqlalchemy介绍

    快速入门 Flask-SQLAlchemy 使用起来非常有趣,对于基本应用十分容易使用,并且对于大型项目易于扩展.有关完整的指南,请参阅 SQLAlchemy 的 API 文档. 一个最小应用 常见情 ...

  5. 袋鼠云旗下新公司云掣科技启航,深耕云MSP业务助推企业数字化转型

    1983年3月15日,国际消费者联盟组织将3月15日确立为国际消费者权益日. 2019年3月15日,袋鼠云举办三周年年会. 一生二,二生三,三生万物.植树节后,万物生长. 年会现场,袋鼠云宣布成立新公 ...

  6. 【RL系列】On-Policy与Off-Policy

    强化学习大致上可分为两类,一类是Markov Decision Learning,另一类是与之相对的Model Free Learning 分为这两类是站在问题描述的角度上考虑的.同样在解决方案上存在 ...

  7. Python坑系列:可变对象与不可变对象

    在之前的文章 http://www.cnblogs.com/bitpeng/p/4748148.html 中,大家看到了ret.append(path) 和ret.append(path[:])的巨大 ...

  8. 移动端rem用法总结

    先介绍一下这个近年来突起的黑马 CSS3中新增的属性,从IE9开始兼容,手机端都兼容.参考的是<html>这个标签的font-size.rem中的r就是root根的意思.所以rem要比em ...

  9. 如何理解IPD+CMMI+Scrum一体化研发管理解决方案之CMMI篇

    如何快速响应市场的变化,如何推出更有竞争力的产品,如何在竞争中脱颖而出,是国内研发企业普遍面临的核心问题,为了解决这些问题,越来越多的企业开始重视创新与研发管理,加强研发过程的规范化,集成产品开发(I ...

  10. 第八,九周web制作代码

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or ...