简体   繁体   中英

Removing Branches from GitHub

About 3 weeks ago I deleted some branches from my local repository, but never deleted them from my repository on GitHub. I need to clean up some of these branches, but have been unsuccessful.

As an example, I deleted this branch from my local 3 weeks ago: 1234e-proj

Now I am trying to run:

git push origin :1234e-proj

and I get this error:

error: unable to push to unqualified destination: 1234e-proj
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

Any idea what I am doing wrong? This is happening with several branches I have deleted on my local already.

Did you try to use

git push --delete origin '1234e-proj'

or

git push --mirror origin # warning: pushes all refs and deletes all others!

Otherwise, it should work. Perhaps you can share the output of a

git branch -a

First of all, a wild guess: are those branches actually still in the GitHub repo, visible on the web, or are you just seeing them as remote branches in your repo? (Run git remote update --prune to update things; that'll prune them if they're in your local repo only.)

Use git ls-remote origin to print the refs on the remote, as the remote sees them, eg:

406da7803217998ff6bf5dc69c55b1613556c2f4    HEAD
1e501a7c47ad5ada53d3b1acfb9f131f76e969ec    refs/heads/maint
406da7803217998ff6bf5dc69c55b1613556c2f4    refs/heads/master
56e79320f3d9b044c380dfebf136584aaa17ac5b    refs/heads/next
...

Find the ones you want to delete, then use git push :<ref> to delete, eg git push :refs/heads/branch-foo .

I'm not entirely sure what's going on for you, but assuming the refs really do exist on the remote, this should be a foolproof way to see and delete them. My best guess is that the refs that you're seeing on GitHub aren't actually in refs/heads , so using the unqualified refname doesn't work. (I'm not sure how you'd have ended up in that situation, though!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM