What is Git Bash completion?
Git Bash completion is a functionality that auto-completes Git commands and object names as you type them in the terminal. This feature speeds up your workflow by reducing the amount of typing needed and helps avoid typos and misspellings that can lead to errors.
This guide will provide an in-depth look at enabling and using Git Bash completion on Windows.
Enabling Git Bash completion
Windows
Setting up Git Bash autocomplete on Windows involves a few steps since it isn't enabled by default like on some Linux distributions.
Install Git for windows: If you haven't already, download and install Git for Windows from Git SCM. This package includes Git Bash, which is a bash emulation used to run Git from the command line.
Enable autocompletion:
- When installing Git for Windows, ensure that the option for "Git Bash Here" is selected, which typically includes bash completion scripts.
- After installation, Git completion scripts should be automatically sourced by the Git Bash shell. If autocomplete isn't working, you might need to manually source the completion script by adding the following line to your
.bashrcfile:This will make the file accessible from anywhere in your Git Bash terminal.Terminalsource /usr/share/git/completion/git-completion.bash - If the
.bashrcfile does not exist, you can create it by running:
Terminaltouch ~/.bashrcThe
~file prefix is usually theC:\Users\<your username>folder.- If the
git-completion.bashscript file does not exist in the directory, you can manually download thegit-completion.bashscript from the Git repository. Place this file in a directory (e.g.,/usr/share/git/completion/) follow the above steps to source it from your.bashrc.
Reload your Bash configuration:
Terminalsource ~/.bashrcAuto-completion should now be enabled from your terminal.
Using Git Bash completion
Once enabled, Git Bash completion allows you to start typing a Git command in the terminal and press the Tab key to auto-complete it. For example:
- Typing
git checand pressing Tab will complete togit checkout. - When typing
git checkout feaand pressing Tab, it will auto-complete to the nearest matching branch name that starts with "fea".
Benefits of Git Bash completion
- Speeds up workflow: Reduces the amount of typing, which speeds up your workflow.
- Reduces errors: Helps avoid typos in Git commands and branch names, reducing potential errors.
For further reading see the official Git documentation.