gpt4 book ai didi

Git推送接收 "error: refusing to update checked out branch"

转载 作者:太空狗 更新时间:2023-10-29 14:27:20 26 4
gpt4 key购买 nike

这是我到目前为止所做的:

我成功地将我的远程仓库克隆到我本地机器上的一个新目录。

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

$ 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'

您对我如何解决这个问题有什么想法吗?谢谢。

这是我的本地 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
user.name=Chris Barnhill
user.email=JazzcatCB@gmail.com
gui.wmstate=normal
gui.geometry=887x427+26+26 171 192

最佳答案

远程主分支显然处于非裸状态,这意味着任何 push 该分支的人都会覆盖已 check out 工作副本的现有状态(对 HEAD 的引用)。这可不是什么好事。

要解决这个问题,您要么使用裸存储库作为“公共(public)”存储库(使用“git init --bare”执行此操作),要么使用分支:

git checkout -b 我的分支

在这个分支上做你的工作并提交。然后用'git push origin myBranch'推送你的分支,而不必破坏任何东西。之后,您在远程仓库中的分支可以 merge 或 rebase 为 master。

关于Git推送接收 "error: refusing to update checked out branch",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17276907/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com