How to Enable Git Tab Autocomplete

Abdul Jabbar Feb 02, 2024
  1. Importance of Enabling Git Tab Autocomplete
  2. Enable Git Tab Autocomplete
How to Enable Git Tab Autocomplete

This tutorial demonstrates how we can enable the git tab to autocomplete.

Importance of Enabling Git Tab Autocomplete

When developers work with source code, they mostly prefer Git, as it is a very well-known and handy platform for developers, through which they work very efficiently with their codes within a team-based environment.

On every system, Git is installed by default when Windows is installed successfully on the personal computer.

But when it comes to the auto-completion feature, we have to manually get it started by enabling the git tab autocomplete, which will automatically complete commands and branch names as defined before.

This tutorial will demonstrate how to install a handy feature in Git called auto-completion. It will help us automatically type commands, their file paths and branch names, and tags in Git.

We can say that when we start typing a word, we will press the Tab key, and it will make Git guess the word contingent on our work done before. It also saves us from excess typing or writing the whole paragraph.

If the possibility of a word match is more than one, then it asks for more information to type the correct word accordingly. We will see how the autocomplete feature works in Git in the following section.

Enable Git Tab Autocomplete

First of all, we will open a shell and go to our home directory, where we will find the script with the famous cd command as below:

cd script/ folder

After reaching the destination folder, we will use one of the following methods to download the Git auto-completion script into that folder.

The first method is to download using the curl, and the other is to use the wget to download into the folder. We will see both commands below:

Use curl to Download Git Auto-completion:

curl -O https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash

Use wget to Download Git Auto-completion:

wget https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash

Source the Git Completion File

Bash Command:

source ~/git-completion.bash

Most probably, when we want to start a new shell, we need to source this file automatically. For this purpose, we will navigate to the ~/.bashrc file and attach the command from above.

When this file is saved, all new shells will source this file. The sign (~) indicates the home directory. Finish this by restarting the terminal using the administrative mode from the personal computer options.

Let’s check whether this method works properly or not by navigating to the Git-controlled directory.

Then type from the keyboard a few words and press the Tab key and check if the autocomplete works properly on your personal computer; the command is listed below:

git checkout <tab><tab>

In response to the above command, we will have a list of all possible branches that can be checked out after successfully hitting the Tab button.

Like this, we can execute any command of Git we have seen in other tutorials as this autocomplete feature, and it will run on all of the supported commands of Git without any issue.

Author: Abdul Jabbar
Abdul Jabbar avatar Abdul Jabbar avatar

Abdul is a software engineer with an architect background and a passion for full-stack web development with eight years of professional experience in analysis, design, development, implementation, performance tuning, and implementation of business applications.

LinkedIn