How to Set Up Auto-Complete for Git Commands on Windows cmd.exe
Git Command autofill & autocorrect for Windows via cmd.exe
I’ve recently learned that on Linux and Mac OS, Git commands can be set up to autocomplete. However, I’m usually working with Git via cmd.exe and set up autocomplete is a bit tricky and very complex process on Windows OS.
So I googled: how to set up git autofill commands on Windows command prompt and I couldn’t find anything specific or very clear steps that actually worked.
I had to mixed resources and steps from different blogs and answers on StackOverflow to make it work.
So, in this article, I’m going to share a simplified few steps you need to complete to set auto-complete for git commands on Windows cmd.exe.
1. Install Cygwin
Install Cygwin by running setup-x86_64.exe (64-bit installation) or setup-x86.exe (32-bit installation)
Cygwin a large collection of GNU and Open Source tools which provide functionality similar to a Linux distribution on Windows.
2. msysgit
.bashrc
, .bash_profile
are used in Unix based operating systems for the terminal. In Windows, you set environment variables differently. In Windows 10, search for environment variables in the start menu, and select Edit the system environment variables
and set them from there.
PS: You can have
.bashrc
if you have installed something like git bash, Cygwin bash or bash for windows 10 or something else. And all 3 handle.bashrc
differently.
Download and place git-flow-completion.bash
in home directory
- create a file named
git-flow-completion.bash
, in your home directory.
- open that file in an editor like Atom or VS code or whatever you are using.
- navigate to the following git-flow-completion.bash file; copy and paste the content to the file you created and save it.
Add a .bashrc
file to your home directory
You should have
.bashrc
if you have installed something like git bash, Cygwin bash or bash for windows 10. Which was the first thing we did.
- Open cmd.exe; make sure you are in your home directory. Then open
.bashrc
by typing the following command:atom .bashrc
I’m using Atom in this case. You can use any editor or IDE to do so. if you are using VS Code for example; you’ll type:code .bashrc
- add the following line to your existing
.bashrc
file:source ~/git-flow-completion.bash
Note: The steps above have been tested to work with msysgit version 1.7.3.1 and newer, while completion does not function when tested with msysgit version 1.7.0.2. For best results, download and install the latest version of msysgit.
3. Install Click
Install Clink . This is the final touch that makes this work by magic!
Clink combines the native Windows shell cmd.exe with the powerful command line editing features of the GNU Readline library, which provides rich completion, history, and line-editing capabilities. Readline is best known for its use in the well-known Unix shell Bash, the standard shell for Mac OS X and many Linux distributions.
Restart your computer and you should be good to go!
Extra!
help.autocorrect
If you mistype a command, it shows you something like this:
$ git chekcout master
git: 'chekcout' is not a git command. See 'git --help'.Did you mean this?
checkout
Git helpfully tries to figure out what you meant, but it still refuses to do it. If you set help.autocorrect
to 1:
$ git config --global help.autocorrect 1
Git will actually run this command for you:
$ git chekcout master
WARNING: You called a Git command named 'chekcout', which does not exist.
Continuing under the assumption that you meant 'checkout'
in 0.1 seconds automatically...
Note that “0.1 seconds” business. help.autocorrect
is actually an integer which represents tenths of a second. So if you set it to 50, Git will give you 5 seconds to change your mind before executing the autocorrected command.
If you enjoyed this story, you might also like “How to Set Up the Development Environment”
Please give it a few claps for support!
Cheers!!!