简体   繁体   中英

Git - how to remove branch from checkout autocomplete

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.

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.

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.

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 ~branch even if is not merged` you can force the deletion with:

git branch -D branchname

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

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)

I realize this is really, really old, but I just ran into this issue, and in my case, I had pruned the branches in origin , but not the ones in origin-http .

I don't normally use http for cloning, so this is not typically an issue, but...welp.

Once I did git remote prune origin-http , it fixed the problem for me.

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