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

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

问题描述

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

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

c:Program Files (x86)Gitingit.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?

推荐答案

原因:您正在推送到非裸存储库

Reason:You are pushing to a Non-Bare Repository

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

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

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

所以,简而言之,你不能推送到非裸仓库(嗯,你不能推送到当前检出的分支一个存储库.使用裸存储库,您可以推送到任何分支,因为没有检出任何分支.尽管可能,推送到非裸存储库并不常见).您可以做的是从另一个存储库中获取和合并.这就是您在 Github 中看到的 pull request 的工作原理.你要求他们从你身边拉开,而不是强行推入他们.

So, in short, you can't push to a non-bare repository ( 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.

更新:感谢 VonC 在最新的 git 版本(当前为 2.3.0)中指出这一点,推送到非裸存储库的检出分支是可能的.尽管如此,您仍然无法推送到工作树,这无论如何都不是安全操作.

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 repository is possible. Nevertheless, you still cannot push to a dirty working tree, which is not a safe operation anyway.

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

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