问题
I've deleted some local branches via git branch -d branchname, but they are still exist in autocomplete (when I put git checkout, then press tab key, I see all deleted branches in list).
I've tried to make git gc and git prune, but nothing changes.
回答1:
If you are sure that you do not want the branch, you can remove it from your local and the remote like this:
$ git branch -D branchname
$ git push origin :branchname
Then it will stop appearing in autocomplete results.
回答2:
TL;DR - the real answer:
$ git remote prune origin
Slightly more details:
git branch -d foo-branch will fail to delete if foo-branch is not merged into your current branch.
It's also a good idea to clean up old branches on a remote if they've already been merged. You can do this from the commandline by git push origin :foo-branch.
However, the old "phantom" branch foo-branch will linger for autocompleting git checkout. Apparently git is caching the branches available on the remote. By calling:
$ git remote prune origin
You can clear the local cache of what branches are available on the git remote.
I can reproduce the OP's issue for git 2.2.1 (and probably earlier versions) on OSX.
回答3:
You've probably tried to delete an unmerged branch, so git branch -d branchname has not deleted it.
You can check if the branch still exists with:
git branch -a
If you're really sure to delete the ~brancheven if is notmerged` you can force the deletion with:
git branch -D branchname
回答4:
I had this problem and the previous solutions didn't work for me. It turned out that I had a tag in the repo with the same name as the old deleted branch. You can delete the tag with:
git tag -d [tagname]
To delete it remotely:
git push origin :refs/tags/[tagname]
Thanks to https://nathanhoad.net/how-to-delete-a-remote-git-tag
回答5:
Note that pushing the branch deletion (git push origin :branchname) is easier in Git 2.13 (Q2 2017), since the completion script learned to complete "git push --delete b<TAB>" (to complete branch name to be deleted).
See commit 723c1d5 (22 Apr 2017) by Ævar Arnfjörð Bjarmason (avar).
(Merged by Junio C Hamano -- gitster -- in commit f70b541, 26 Apr 2017)
来源:https://stackoverflow.com/questions/22147734/git-how-to-remove-branch-from-checkout-autocomplete