Git推送接收“错误:拒绝更新签出分支” [英] Git push receiving "error: refusing to update checked out branch"

查看:604
本文介绍了Git推送接收“错误:拒绝更新签出分支”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我迄今为止所做的:

我成功将我的远程回购克隆到本地计算机上的新目录。



然后我编辑了一个工作副本中的文件,提交了它,并试图将它推送到远程回购站。这是我得到的错误:

  $ git push origin master 
root@gohyperspace.com的密码:
计数对象:9,完成。
使用多达4个线程的增量压缩。
压缩对象:100%(5/5),完成。
写入对象:100%(5/5),456字节| 0字节/秒,完成。
总计5(增量4),重用0(增量0)
远程:错误:拒绝更新检出分支:refs / heads / master
remote:错误:默认情况下,更新当前分支在非裸仓库中
remote:error:被拒绝,因为它会使索引和工作树不一致
ent
remote:error:与你推送的内容相同,并且需要'git reset --hard'to matc
h
remote:error:work tree to HEAD。
remote:error:
remote:error:您可以将'receive.denyCurrentBranch'配置变量设置为

remote:error:'ignore'或'warn'in the remote repository允许推入

remote:error:当前分支;然而,除非您
remote:error:安排更新其工作树以匹配您在某些

remote:error:其他方式中推送的内容,否则不建议这样做。
remote:error:
remote:error:要压制此消息并保持默认行为,请设置

remote:error:'receive.denyCurrentBranch'配置变量为'拒绝。
到root@gohyperspace.com:/ var / www / html
! [remote rejected] master - > master(分支目前被检出)
错误:未能将一些文件推送到'root@gohyperspace.com:/ var / www / html'

您对如何解决此问题有任何想法吗?

这是我的本地Git配置:

  $ git config -l 
core.symlinks = false
core.autocrlf = true
color.diff = auto
color.status = auto
color.branch = auto
color.interactive = true
pack.packsizelimit = 2g
help.format = html
http.sslcainfo = / bin / curl-ca-bundle.crt
sendemail.smtpserver = /bin/msmtp.exe
diff.astextplain.textconv = astextplain
rebase.autosquash = true
merge.tool = tortoisemerge
gui.recentrepo = C:/ Users / Chris / Dev / Projects / html
user.email=JazzcatCB@gmail.com
user.name = CBarnhill
core.repositoryformatversion = 0
core.filemode = false
core .bare = false
core.logallrefupdates = true
core.symlinks = false
core.ignorecase = true
core.hidedotfiles = dotGitOnly
remote.origin.url = root@gohyperspace.com:var / www / html
remote.origin.fetch = + refs / heads / *:refs / remotes / origin / *
branch.master.remote = origin
branch.master.merge = refs / heads / master
使用r.name = Chris Barnhill
user.email=JazzcatCB@gmail.com
gui.wmstate =正常
gui.geometry = 887x427 + 26 + 26 171 192

解决方案

远程主分支显然处于非裸状态,也就是说,任何推入该分支的人都会覆盖签出的工作副本的现有状态(对HEAD的引用)。这不是一件好事。为了解决这个问题,你可以使用一个裸仓库作为一个公共仓库(用'git init --bare'来做到这一点) ,或者与分支机构合作:



git checkout -b myBranch



在分支上工作并提交。然后用'git push origin myBranch'推动你的分支,而不必破坏任何东西。之后,您在远程仓库中的分支可以合并或重新分配给主仓库。


Here's what I've done so far:

I successfully cloned my remote repo to a new directory on my local machine.

Then I edited a file in working copy, committed it, and tried to push it to the remote repo. Here's the error I got:

$ git push origin master
root@gohyperspace.com's password:
Counting objects: 9, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 456 bytes | 0 bytes/s, done.
Total 5 (delta 4), reused 0 (delta 0)
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 inconsist
ent
remote: error: with what you pushed, and will require 'git reset --hard' to matc
h
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 root@gohyperspace.com:/var/www/html
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'root@gohyperspace.com:/var/www/html'

Do you have any ideas on how I can resolve this? Thanks.

Here's my local Git cofiguration:

$ git config -l
core.symlinks=false
core.autocrlf=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
pack.packsizelimit=2g
help.format=html
http.sslcainfo=/bin/curl-ca-bundle.crt
sendemail.smtpserver=/bin/msmtp.exe
diff.astextplain.textconv=astextplain
rebase.autosquash=true
merge.tool=tortoisemerge
gui.recentrepo=C:/Users/Chris/Dev/Projects/html
user.email=JazzcatCB@gmail.com
user.name=CBarnhill
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
core.hidedotfiles=dotGitOnly
remote.origin.url=root@gohyperspace.com:var/www/html
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
user.name=Chris Barnhill
user.email=JazzcatCB@gmail.com
gui.wmstate=normal
gui.geometry=887x427+26+26 171 192

解决方案

The remote master-branch is obviously in a non-bare state, which means, that anyone pushing into this branch would overwrite the existing status of the checked out working copy (the reference to HEAD). This is not a good thing.

To solve this, you either use a bare repository as a "communal" repo (do this with 'git init --bare'), or work with branches:

git checkout -b myBranch

Do your work on this branch and commit. Then push your branch with 'git push origin myBranch' without having to destroy anything. After that, your branch in the remote repo can be merged or rebased into master.

这篇关于Git推送接收“错误:拒绝更新签出分支”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆