在使用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. 抓包工具Charles学习总结

    最近由于工作需要对App进行测试,功能方面还好说,但是在网络测试方面遇到了一些问题.由于公司App是使用https进行通信,直接在路由器上抓包下来,数据包都是加密的,没法看到接口返回的内容,给测试的B ...

  2. Hyperledger Fabric 1.0 从零开始(十三)——orderer分布式方案

    简述 在搭建HyperLedger Fabric环境的过程中,我们会用到一个configtx.yaml文件(可参考Hyperledger Fabric 1.0 从零开始(八)——Fabric多节点集群 ...

  3. 【python 3.6】python读取json数据存入MySQL(二)

    在网上找到一个包含全国各省市经纬度的json文件,也可以通过上次的办法,解析json关键字,构造SQL语句,插入数据库. JSON文件格式如下: [ { "name": " ...

  4. python—退出ipython3的help()

    退出ipython3的help() 组合键:ctrl+z

  5. scikit-learn 0.18中的cross_validation模块被移除

    环境:scikit-learn 0.18 , python3 from sklearn.cross_validation import train_test_split from sklearn.gr ...

  6. 【RL系列】蒙特卡罗方法——Soap Bubble

    “肥皂泡”问题来源于Reinforcement Learning: An Introduction(2017). Exercise 5.2,大致的描述如下: 用一个铁丝首尾相连组成闭合曲线,浸入肥皂泡 ...

  7. hashlib模块使用详情

    python常用模块目录 一:hashlib简介 1.什么叫hash:hash是一种算法(不同的hash算法只是复杂度不一样)(3.x里代替了md5模块和sha模块,主要提供 SHA1, SHA224 ...

  8. 基于 Agent 的模型入门:Python 实现隔离仿真

    2005 年诺贝尔经济学奖得主托马斯·谢林(Thomas Schelling)在上世纪 70 年代就纽约的人种居住分布得出了著名的 Schelling segregation model,这是一个 A ...

  9. 今目标登录时报网络错误E110

    今目标登录的时候报错了,错误代码:E110不论怎么修改都修复不了,百度相关资料也没有,只能联系客服. 经过好久终于联系上了客服,客服给出的解决方案是修改:Enternet选项: 第一步:打开,控制面板 ...

  10. DEBUG_NEW和THIS_FILE

    C++ 的一个 比较晦涩难懂的特点是你可以重载 new 操作符,并且你甚至可以给它附加参数.通常,操作符 new 只接受拟分配对象的大小:        void* operator new(size ...