Git推送错误:拒绝更新签出分支 [英] Git Push error: refusing to update checked out branch

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

问题描述

我已经解决了一些合并冲突,然后尝试推送我的更改并收到以下错误:

  c:\\ \\ Program Files(x86)\Git\bin\git.exe push --recurse-submodules =检查originmaster:master 
完成
remote:error:拒绝更新签出分支:refs / heads / master
remote:error:默认情况下,更新非裸仓库中的当前分支
remote:error:被拒绝,因为它会使索引和工作树不一致
remote:error:用你推送的内容,并且需要'git reset --hard'来匹配
remote:error:工作树到HEAD。
remote:错误:
remote:错误:您可以在远程存储库中将'receive.denyCurrentBranch'配置变量设置为
remote:error:'ignore'或'warn',以允许推入
remote:错误:当前分支;然而,除非你
remote:error:安排它更新它的工作树来匹配你在
remote:error:other方面推送的内容,否则不建议这样做。
remote:error:
remote:error:为了压制此消息并保持默认行为,请将
remote:error:'receive.denyCurrentBranch'配置变量设置为'拒绝'。
到C:/ Development / GIT_Repo / Project
! [remote rejected] master - > master(分支目前被检出)
错误:未能将一些文件推送到'C:/ Development / GIT_Repo / Project'

有人知道什么可能导致这个错误吗?

解决方案

有两种类型的存储库:裸露和不裸露



裸仓库没有工作副本,您可以推送给他们。这些是你在Github中获得的仓库类型!如果你想创建一个裸仓库,你可以使用

  git init --bare 
不能将其推送到非裸仓库 。

(编辑:那么,你不能推送到存储库的当前签出分支,只有裸仓库,你可以推送到任何分支,因为没有签出。尽管可能,推送到非裸仓库并不常见) 。你可以做的是从另一个存储库获取并合并。这就是你可以在Github中看到的拉取请求的工作方式。你要求他们从你那里拉,而你不强迫他们进入他们。






更新:感谢VonC指出了这一点,在最新的git版本(目前为2.3.0)中,推送到已签出的分支的非裸仓库是可能的。尽管如此,您仍然无法推送到肮脏的工作树,无论如何这不是一个安全的操作。


I have solved some merge conflicts, committed then tried to Push my changes and received the following error:

c:\Program Files (x86)\Git\bin\git.exe push --recurse-submodules=check "origin" master:master
Done
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 C:/Development/GIT_Repo/Project
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'C:/Development/GIT_Repo/Project'

Does anyone know what could be causing this error?

解决方案

There are two types of repositories: bare and non-bare

Bare repositories do not have a working copy and you can push to them. Those are the types of repositories you get in Github! If you want to create a bare repository, you can use

git init --bare

So, in short, you can't push to a non-bare repository (Edit: Well, you can't push to the currently checked out branch of a repository. With a bare repository, you can push to any branch since none are checked out. Although possible, pushing to non-bare repositories is not common). What you can do, is to fetch and merge from the other repository. This is how the pull request that you can see in Github works. You ask them to pull from you, and you don't force-push into them.


Update: Thanks to VonC for pointing this out, in the latest git versions (currently 2.3.0), pushing to the checked out branch of a non-bare repositories is possible. Nevertheless, you still cannot push to a dirty working tree, which is not a safe operation anyway.

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

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