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 - how to remove branch from checkout autocomplete
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.
Disable auto-completion of remote branches in Git Bash?
With Git 2.13 (Q2 2017), you can disable (some of) the branch completion.
git checkout --no-guess ...
# or:
export GIT_COMPLETION_CHECKOUT_NO_GUESS=1
See commit 60e71bb (21 Apr 2017) by Jeff King (peff
).
(Merged by Junio C Hamano -- gitster
-- in commit b439747, 01 May 2017)
As documented in contrib/completion/git-completion.bash
now:
You can set the following environment variables to influence the behavior of the completion routines:
GIT_COMPLETION_CHECKOUT_NO_GUESS
When set to "1", do not include "DWIM" suggestions in
git-checkout
completion (e.g., completing "foo" when "origin/foo" exists).
Note: DWIM is short for Do What I Mean, where a system attempts to anticipate what users intend to do, correcting trivial errors automatically rather than blindly executing users' explicit but potentially incorrect inputs.
completion
: optionally disable checkout DWIM
When we complete branch names for "
git checkout
", we also complete remote branch names that could trigger the DWIM behavior. Depending on your workflow and project, this can be either convenient or annoying.For instance, my clone of
gitster.git
contains 74 local "jk/*
" branches, but origin contains another 147.
When I want to checkout a local branch but can't quite remember the name, tab completion shows me 251 entries. And worse, for a topic that has been picked up for pu, the upstream branch name is likely to be similar to mine, leading to a high probability that I pick the wrong one and accidentally create a new branch.
Note: "picked up for pu": see a What's cooking in git.git
: it starts with:
Commits prefixed with '
-
' are only in 'pu
' (proposed updates) while commits prefixed with '+
' are in 'next
'.
This is part of the Git Workflow Graduation process.
pu
(proposed updates) is an integration branch for things that are not quite ready for inclusion yet
This patch adds a way for the user to tell the completion
code not to include DWIM suggestions for checkout.
This can already be done by typing:git checkout --no-guess jk/<TAB>
but that's rather cumbersome.
The downside, of course, is that you no longer get completion support when you do want to invoke the DWIM behavior.
But depending on your workflow, that may not be a big loss (for instance, in git.git I am much more likely to want to detach, so I'd type "git checkout origin/jk/<TAB>
" anyway).
Git checkout autocomplete suggest a branch that doesn't exists
Run git branch -a
to see what local and remote branches your really have in the repository.
git shows old deleted branches in zsh TAB completion
Apparently, the autocomplete tab was showing all the names of remote branches I had not done housekeeping on.
Found clues reading this blog post.
I was fixated on local and did not even consider if the plugin was pulling from the remote branches.
What's frustrating is that as in the screenshot all the branches without origin/
were not local and not there. As soon as I started to delete the remote branches these ones disappeared as well.
clean git checkout autocompeletion
Make sure to use the latest Git 2.13, which improved on Git completion:
- for deleted branch
- for remote branch
In your case, check the git branch -avv
output to see if those "branches" are listed at all. If not, it could be a new bug to report to the mailing list.
Git Checkout [Tab] shows a lot of branches
Can you try the same completion after typinf first:
export GIT_COMPLETION_CHECKOUT_NO_GUESS=1
With Git 2.13 or more, that should avoid displaying all the remote branches.
See more at "Disable auto-completion of remote branches in Git Bash?".
Related Topics
How to Modify The Linux Kernel to Change The Version String That Uname Returns
Windows .Crl to .Pem for Nginx
Using Command Substitution Inside a Sed Script, with Arguments
Undefine Reference for Libraries, So How Could I Find The Right Path
Which Signal Was Delivered to Process Deadlocked in Signal Handler
How to Extract Text Which Matches Particular Fields in Text File Using Linux Commands
Using for Loop to Move Files from Subdirectories to Parent Directories
Linux Module to Hook Process Functions
How to Check If a UId Exists in an Acl in Linux
Find String and Replace Line in Linux
How to Convert a Text/Plain to Text/X.Shellscript
How to Test Your Own Linux Module
Echo 'The Character - (Dash) in The Unix Command Line
Difference Between Posix Reliable Signals and Posix Real-Time Signals in Linux
Interpreting Openssl Speed Output for Rsa with Multi Option