删除远程 git 分支"error: unable to push to unqualified destination"时



我正在尝试删除一个远程 git 分支

git push origin :my_remote_branch

并获得:

error: unable to push to unqualified destination: my_remote_branch
The destination refspec neither matches an existing ref on the remote nor
begins with refs/, and we are unable to guess a prefix based on the source ref.
error: failed to push some refs to 'git@example.com:/myrepo'

这些是我目前的分支

git branch -a
* develop
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/develop
  remotes/origin/my_remote_branch
git branch -r --merged
  origin/HEAD -> origin/master
  origin/develop
  origin/master

关于如何摆脱这个分支的任何想法将不胜感激。

本地仓库中存在refs/remotes/origin/my_remote_branch并不意味着refs/heads/my_remote_branch存在于origin远程仓库中。

如果refs/remotes/origin/my_remote_branch已在原点中删除,请git fetch -p origin使其消失。-p选项告诉 fetch 删除相应远程中不再存在的任何跟踪分支;默认情况下,它们被保留在周围。

发现清理旧的远程 git 分支的问题,这起到了作用

git branch -r -d origin/my_remote_branch

我在尝试删除已删除的远程分支时遇到了这个问题。所需要的只是一个修剪:

git remote prune origin

尝试以下两个选项强制删除远程分支

选项 1

get push origin --delete <branchName>

选项 2

git fetch -p origin
git branch -r -d origin/<branchName>
git branch -r -d origin/my_remote_branch

对我来说还不够。在我不得不去服务器并直接使用 git 目录(这既危险又丑陋)来删除分支之前:

ssh mygitserver
su - git
cd /home/git/repositories/my_remote_branch.git/
git  --git-dir=. --work-tree=/tmp/ branch -D my_remote_branch
对我来说

,问题是,这是我在github上的默认分支。我更改了默认分支,然后删除操作成功。

希望对某人有帮助

我也有类似的问题。首先进行了讨论,但是直到我看到 https://stackoverflow.com/a/32147743/4209849 我才解决问题。

这只是增加了一个关于区分origin/my-branch-namemy-branch-name的提示.

具体来说,我应该使用:

git push origin :my_remote_branch

而不是

git push origin :origin/my_remote_branch

这至少解决了我的问题,希望它也能帮助其他人。

遇到同样的问题,我手动编辑了我的./.git/config文件以包括:

[branch "branchName"]
remote = origin
merge = refs/heads/branchName

这导致:error: src refspec branchName matches more than one.我通过运行$git tag -d branchName修复了这个问题。之后,我能够将新分支推向上游。

这对

我有用:我在 github UI 上创建了远程分支,然后将具有相同名称的本地分支推送到它。 尝试一下,以防其他方法不起作用。另一种方法是在本地创建一个新分支并推送一个空分支,然后挑选您的提交并再次推送到您的远程。

最新更新