git git拒绝获取到当前分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2236743/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git refusing to fetch into current branch
提问by Olivier Verdier
I set up a remote repository and I can push new changes to it, but I cannot fetch from it, I always get the (rather cryptic) error message:
我设置了一个远程存储库,我可以向它推送新的更改,但我无法从中获取,我总是收到(相当神秘的)错误消息:
fatal: Refusing to fetch into current branch refs/heads/master of non-bare repository
fatal: The remote end hung up unexpectedly
What does it mean? What should I do to enable fetching?
这是什么意思?我应该怎么做才能启用提取?
(Note that this remote repo is only used as a backup repo, so it should be pretty much an exact copy of my local repository. I really can't understand why I can push to it but not fetch from it...)
(请注意,此远程存储库仅用作备份存储库,因此它应该几乎是我本地存储库的精确副本。我真的不明白为什么我可以推送到它但不能从中获取...)
My config looks like:
我的配置看起来像:
[remote "origin"]
url = ssh://blablablah
fetch = +refs/*:refs/*
mirror = true
采纳答案by Michael Krelin - hacker
What you're trying to do is to fetch the branch you're workin on. That is, you areon the master branch and you try to update it. That's not possible. It's more common to update the remotes/*
branches and then pull it into your local ones. What you want is, perhaps,
您要做的是获取您正在处理的分支。也就是说,你是在主分支,并尝试对其进行更新。那是不可能的。更新remotes/*
分支然后将其拉入本地分支更为常见。你想要的是,也许,
git remote add otherrepo thehost:/the/path.git
That will setup repository to be fetched into remotes/otherrepo/*
. git fetch otherrepo
should do the trick. Alternativeley, you can manually edit your .git/config
and set fetch
for the remote to something like refs/heads/*:refs/remotes/otherrepo/*
.
这将设置存储库以获取到remotes/otherrepo/*
. git fetch otherrepo
应该做的伎俩。或者,您可以手动编辑您的遥控器.git/config
并将其设置fetch
为refs/heads/*:refs/remotes/otherrepo/*
.
回答by RobW
In case anyone finds this because they specifically want to fetch into the current branch, you can use the --update-head-ok
flag. From the docs:
如果有人因为他们特别想要获取到当前分支而发现这一点,则可以使用该--update-head-ok
标志。从文档:
-u
--update-head-ok
By default git fetch refuses to update the head which corresponds to the current branch. This flag disables the check. This is purely for the internal use for git pull to communicate with git fetch, and unless you are implementing your own Porcelain you are not supposed to use it.
-u
--update-head-ok
默认情况下 git fetch 拒绝更新与当前分支对应的头部。此标志禁用检查。这纯粹是为了 git pull 与 git fetch 通信的内部使用,除非您正在实现自己的 Porcelain,否则您不应该使用它。
In some cases we do want to implement our own porcelain commands, e.g., automation and tooling.
在某些情况下,我们确实希望实现我们自己的瓷器命令,例如自动化和工具。
回答by Sai
Also this this should work if you are in masterbranch and wants to get latest try this
如果您在master分支并且想要获得最新的尝试,这也应该有效
git pull origin master
git pull 原点大师
回答by Charles Stewart
I've had this problem when I thoughtlessly cloned a repository instead of fetching it, so that both repositories were masters. If you have done no work on the remote repository, you can fix things with the basic git commands as follows: (1) delete the remote repository, (2) copy the local repository to where the remote one was, (3) delete the local one, and then (4) set up the local repository using
当我不假思索地克隆存储库而不是获取它时,我遇到了这个问题,因此两个存储库都是主存储库。如果你没有在远程仓库上做任何工作,你可以使用基本的 git 命令修复问题,如下所示:(1)删除远程仓库,(2)将本地仓库复制到远程仓库所在的位置,(3)删除远程仓库本地一个,然后(4)使用设置本地存储库
git init; git fetch $REMOTE_GIT_REPOSITORY_URL
Then git pull
and git push
will do the right things. The advantage of avoiding git remote
, per Michael's more efficient and principled answer, is that you don't need to think about the semantics of tracking branches.
然后git pull
并且git push
会做正确的事情。根据git remote
迈克尔更有效和更有原则的回答,避免 的优点是您不需要考虑跟踪分支的语义。
回答by Hafiz Shehbaz Ali
I have the same problem. First I try to fetch using this
我也有同样的问题。首先我尝试使用这个来获取
git fetch [remote_name] [branch_name]
I had the same problem you mention. After that I tried this simple command.
我遇到了你提到的同样问题。之后我尝试了这个简单的命令。
git pull [remote_name] [branch_name]
Note will fetch and merge the changes. If you using terminal then file open, requiring to commit message. With this message you will push the latest commit. Try this command and finally you will be able to push the request.
Note 将获取并合并更改。如果您使用终端,则打开文件,需要提交消息。通过此消息,您将推送最新的提交。试试这个命令,最后你就可以推送请求了。
git push [remote_name] [branch_name_local]
回答by Christian Specht
Are you actually typing Git commands into the command line, or are you running the Git executable from your own code?
If you're running it from code, are you sure that Git is trying to fetch into the correct local directory?
您实际上是在命令行中输入 Git 命令,还是从您自己的代码运行 Git 可执行文件?
如果您从代码运行它,您确定 Git 正在尝试获取正确的本地目录吗?
There are two possible ways to do this:
有两种可能的方法来做到这一点:
Use the options provided by your programming language to set the correct working directory before executing Git
(C# example, because that's what I'm using)Always pass the
-C
parameterto Git to specify the directory with the local repo.
I have a project where I'm calling the Git executable from C# code, and I got the same error message like in the question when I accidentally forgot to set the -C parameter
.
我有一个项目,我从 C# 代码调用 Git 可执行文件,当我不小心忘记设置-C parameter
.
回答by Adit choudhary
fatal: Refusing to fetch into current branch refs/heads/BRANCHNAME of non-bare repository
致命:拒绝获取非裸存储库的当前分支 refs/heads/BRANCHNAME
I have Created a branch BRANCHNAME locally then executed command "git fetch upstream pull/ID/head:BRANCHNAME" and got fatal: Refusing to fetch into current branch refs/heads/BRANCHNAME of non-bare repository
我在本地创建了一个分支 BRANCHNAME 然后执行命令“ git fetch upstream pull/ID/head:BRANCHNAME”并得到致命的:拒绝获取非裸存储库的当前分支 refs/heads/BRANCHNAME
then i deleted the branch and again call the same cmd it ways fine.
然后我删除了分支并再次调用相同的 cmd 就可以了。
Actually i was checking out pull request branch.
实际上我正在检查拉取请求分支。