'How do I remove deleted branch names from autocomplete?

I used git branch -d myBranch to delete a branch. However, when I am on master and try to checkout a new branch with git checkout, myBranch still appears in the tab-autocomplete.

How do I remove the name myBranch from tab-autocomplete for git checkout?

git


Solution 1:[1]

git fetch --prune --all

Posting this as its own answer since it's a one-line fix, but if you vote be sure to vote for twalberg's answer.

twalberg's suggestion to git branch -a led me on the right track; my coworker suggested git fetch --prune --all to prune all the dead branches from all the remotes, which is useful when working with lots of devs with lots of forks.

Solution 2:[2]

Depending on your setup, there is another source of what might look like old or deleted branches - your git-completion may also be suggesting tags along with branches.

I was fooled by this recently - our CI/CD pipeline tags all our builds, and even though certain branches would be released and/or deleted years ago, the tags persisted. Cleaning up old tags on the remote was the solution here (there is a guide here).

(I answered this here as well - not sure if it counts as a duplicate as it's on StackExchange...?)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 yoozer8
Solution 2 rocksteady