I would like to be able to type
git checkout <start-of-branch-name>
...and then hit tab and have the branch name autocomplete for me. How can I enable this?
Using autocomplete is as simple as pressing the [TAB] and the active command line options will fill-in. If more than one option is available, you can hit [TAB] twice to display all possible choices and continue typing until there is only one matching choice left.
To do that, press “Win + R,” type cmd and press the Enter button to open the command prompt. Once opened, enter the below command and press the Enter button. From this point onward, you can use the auto-complete feature by pressing the control characters “Ctrl + D” for folder and “Ctrl + F” for files.
What auto-complete does, it'll help you to type commands, file paths, branch names, other things like that in Git. Essentially, you start typing a word, then you hit the tab key and Git then tries to guess based on the context what the rest of the command, the file path, or the branch name ought to be.
First of all, the problem could be as simple as not being in a git-controlled path. Check by issuing the git status
command and see if you get an error.
If you are in a git path, try to source the /etc/bash_completion.d/git
file and try the tab completion again. If this works, do the following:
~/.bashrc
file:. /etc/bash_completion.d/git
Log out.
Open a new mintty session (you are using mintty, right? Tab completion might not work from "cmd" prompt or Powershell.)
Type git
followed by a space, then hit the Tab key twice to test. You should get a list of the git subcommands.
Tab completion on the branch name should now work for you. Eg. git branch ma <TAB>
should complete as git branch master
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With