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?

  • jenkins Wipe out repository and force clone vs Clean before checkout
  • git push origin branchname always pushes to master
  • Referencing the child of a commit in Git
  • Git or Subversion for binary files
  • git cherry-pick and merge by ignoring EOL changes
  • How do I find calls to a function in Git from another file?
  • Failed to lock refs/heads/master
  • Old files are missing after git-svn clone with revision range control
  • git auto fetch before a diff
  • How to add all new folders and files to Git?
  • Git pull -The following untracked working tree files would be overwritten by merge
  • Git push synchronization between team members
  • 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.