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?

  • Proper git procedure for changed files that shouldn't be committed?
  • How do I turn a git clone into a fork and then push to heroku from the fork?
  • git pull - merge remote changes before pushing again
  • How to import an existing bare git repository into Gitlab?
  • Git - How to find all “unpushed” commits for all projects in a directory?
  • 'origin' does not apear to be a git repository
  • Use git rev-list to exclude a branch, but keep common ancestors with the included branches
  • Git not able to recognise addition of .xcscheme files in xcode project
  • Compiler error - msgfmt command not found when compiling git on a shared hosting
  • Getting started with Version Control
  • How to update pull-requesting site after pull request has been merged?
  • How to suspend a git branch?
  • 3 Solutions collect form web for “How do I remove deleted branch names from autocomplete?”

    One possible reason for this is that, if a remote branch (e.g. origin/myBranch) still exists, then git checkout myBranch will succeed as an alternative to git checkout -b myBranch origin/myBranch. This is intended as a convenience for the common case of checkout out a remote branch for the first time, creating an identically named local tracking branch.

    There are other possibilities, too, depending on what exactly you are using for completion, but that’s one of the first things I’d check. If you run git branch -a, and there is an origin/myBranch listed (or one for a remote other than origin, if you have such), then that’s a likely culprit.

    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 above.

    @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.

    That’s probably not git doing that, that’s your shell finishing the command since you used it once before.

    You can take a look at your history by typing history or editing ~/.bash_history. You can edit your history from from the ~/.bash_history file, or you can type history then get the line number with git checkout myBranch in it, then use history -d {line number here}. As a last resort, you can use the history -c command to completely nuke the history.

    Git Baby is a git and github fan, let's start git clone.