当我删除远程分支时,Git 说远程引用不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35941566/
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 says remote ref does not exist when I delete remote branch
提问by cyber8200
I ran git branch -a
我跑了 git branch -a
* master
remotes/origin/test
remotes/origin/master
I want to delete my remote branch
我想删除我的远程分支
I've tried
我试过了
git push origin --delete remotes/origin/test
I got
我有
error: unable to delete 'remotes/origin/test': remote ref does not exist
错误:无法删除“远程/原点/测试”:远程参考不存在
How is it not exist ?
怎么不存在?
I did a git branch -a
, and I saw it listed.
我做了一个git branch -a
,我看到它列出来了。
Did I miss anything ?
我错过了什么吗?
回答by poke
The command git branch -a
shows remote branches that exist in your local repository. This may sound a bit confusing but to understand it, you have to understand that there is a difference between a remote branch, and a branch that exists in a remote repository. Remote branches are localbranches that map to branches of the remote repository. So the set of remote branches represent the state of the remote repository.
该命令git branch -a
显示本地存储库中存在的远程分支。这听起来可能有点令人困惑,但要理解它,您必须了解远程分支与远程存储库中存在的分支之间存在差异。远程分支是映射到远程存储库分支的本地分支。所以远程分支集代表远程存储库的状态。
The usual way to update the list of remote branches is to use git fetch
. This automatically gets an updated list of branches from the remote and sets up remote branches in the local repository, also fetching any commit objects you may be missing.
更新远程分支列表的常用方法是使用git fetch
. 这会自动从远程获取更新的分支列表,并在本地存储库中设置远程分支,同时获取您可能丢失的任何提交对象。
However, by default, git fetch
does not remove remote branches that no longer have a counterpart branch on the remote. In order to do that, you explicitly need to prunethe list of remote branches:
但是,默认情况下,git fetch
不会删除远程分支上不再具有对应分支的远程分支。为此,您明确需要修剪远程分支列表:
git fetch --prune
This will automatically get rid of remote branches that no longer exist on the remote. Afterwards, git branch -r
will show you an updated list of branches that really exist on the remote: And those you can delete using git push
.
这将自动摆脱远程不再存在的远程分支。之后,git branch -r
将向您显示远程上确实存在的分支的更新列表:以及您可以使用git push
.
That being said, in order to use git push --delete
, you need to specify the name of the branch on the remote repository; not the name of your remote branch. So to delete the branch test
(represented by your remote branch origin/test
), you would use git push origin --delete test
.
也就是说,为了使用git push --delete
,您需要指定远程存储库上的分支名称;不是远程分支的名称。因此,要删除分支test
(由远程分支表示origin/test
),您可以使用git push origin --delete test
.
回答by drosam
The meaning of remotes/origin/test
is that you have a branch called test
in the remote server origin
. So the command would be
意思remotes/origin/test
是你有一个test
在远程服务器中调用的分支origin
。所以命令是
git push origin --delete test
回答by Ricardo Magalh?es
There's a shortcut to delete the branch in the origin:
有一个快捷方式可以删除原点中的分支:
git push origin :<branch_name>
git push origin :<branch_name>
Which is the same as doing git push origin --delete <branch_name>
这和做一样 git push origin --delete <branch_name>
回答by MovGP0
- get the list of remote branches
- 获取远程分支列表
git fetch # synchronize with the server
git branch --remote # list remote branches
- you should get a list of the remote branches:
- 你应该得到远程分支的列表:
origin/HEAD -> origin/master
origin/develop
origin/master
origin/deleteme
- now, we can delete the branch:
- 现在,我们可以删除分支:
git push origin --delete deleteme
回答by Matheus Marsiglio
git push origin --delete yourBranch
git push origin --delete yourBranch
回答by Symeon Mattes
Given that the remote branch is remotes/origin/test you can use two ways:
鉴于远程分支是 remotes/origin/test,您可以使用两种方式:
git push origin --delete test
and
和
git branch -D -r origin/test
回答by Yanqi Huang
I followed the solution by pokewith a minor adjustment in the end. My steps follow
- git fetch --prune
;
- git branch -a
printing the following
master
branch
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/branch
(remote branch to remove)
- git push origin --delete branch
.
Here, the branch to remove is not named as remotes/origin/branch
but simply branch
. And the branch is removed.
我通过戳戳并最终进行了小幅调整来遵循解决方案。我的步骤如下
- git fetch --prune
;
-git branch -a
打印以下内容
master
branch
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/branch
(要删除的远程分支)
- git push origin --delete branch
。
在这里,要删除的分支没有命名为 ,remotes/origin/branch
而是简单地命名为branch
。并且分支被移除。
回答by Buggy B
For me this worked $ ? git branch -D -r origin/mybranch
对我来说这有效 $ ? git branch -D -r origin/mybranch
Details
细节
$ ? git branch -a | grep mybranch remotes/origin/mybranch
$ ? git 分支 -a | grep mybranch 遥控器/起源/mybranch
$ ? git branch -r | grep mybranch origin/mybranch
$ ? git 分支 -r | grep mybranch 起源/mybranch
$ ? git branch develop * feature/pre-deployment
$ ? git branch develop * 功能/预部署
$ ? git push origin --delete mybranch error: unable to delete 'mybranch': remote ref does not exist error: failed to push some refs to '[email protected]:config/myrepo.git'
$ ? git push origin --delete mybranch 错误:无法删除“mybranch”:远程引用不存在错误:无法将某些引用推送到“[email protected]:config/myrepo.git”
$ ? git branch -D -r origin/mybranch Deleted remote branch origin/mybranch (was 62c7421).
$ ? git branch -D -r origin/mybranch 删除了远程分支 origin/mybranch (是 62c7421)。
$ ? git branch -a | grep mybranch
$ ? git 分支 -a | grep mybranch
$ ? git branch -r | grep mybranch
$ ? git 分支 -r | grep mybranch
回答by eddiewould
A handy one-liner to delete branches other than 'master' from origin:
从原点删除除“master”以外的分支的方便的单行:
git branch --remotes | grep -v 'origin/master' | sed "s/origin\///" | xargs -i{foo} git push origin --delete {foo}
Be sure you understand the implications of running this before doing so!
在执行此操作之前,请确保您了解运行此操作的含义!
回答by eddiewould
git branch -a
will list the branches in your local and not the branches in your remote.
git branch -a
将列出您本地的分支,而不是您远程的分支。
And the error error: unable to delete 'remotes/origin/test': remote ref does not exist
means you don't have a branch in that name in your remote but the branch exists in your local.
并且该错误error: unable to delete 'remotes/origin/test': remote ref does not exist
意味着您的远程中没有该名称的分支,但该分支存在于您的本地。