Skip to content

Autocorrect Git Commands

autocorrect git commands

If you accidentally type a command wrong, Git will try to figure out what you meant and list similar commands that you might have been trying to run.

For example, if you type git chek, Git will show you a list of commands similar to the one you are trying to run.

This is great but let’s take this further.

Let’s make Git autocorrect our typos so we can save time, avoid frustration, and make using Git a bit easier.

Immediate autocorrect

To enable autocorrect, you can run

git config help.autocorrect immediate

This will autocorrect the typos immediately.

What if there are multiple matches?

Git only autocorrects if there’s only one command that is a significantly close match.

If there are several potential matches, it lists them and stops.

🎥 Would you prefer a video version of this post? Check this out:


Globally or locally

The help.autocorrect mode will be applied only to the existing repository.

If you want the command to be applied globally, you can add the --global flag.

git config --global help.autocorrect immediate

The config will be added to your .gitconfig file.

If you choose to use it locally, you can find the .gitconfig file in your project’s .git folder.

If you choose to run it globally, you can find the .gitconfig in the home folder of your user (i.e. C:/Users/YourUser/.config for Windows)

You can also run the following command to see inside the file:

cat ~/.gitconfig

Prompt Yes/No

If you are not comfortable with Git immediately correcting your typos, you can use the prompt mode instead.

Git will then show you a Yes or No prompt.

git config --global help.autocorrect prompt

Type “y” or “n” then press Enter to accept or decline the correction.

Autocorrect with delay

There’s a third mode that’s a bit of a middle ground between immediate and prompt.

git config --global help.autocorrect 20

In this mode, Git will wait a short amount of time before autocorrecting.

This gives you a small window of time to stop the corrected command if you spot that it is not what you intended.

The amount of time that Git waits is determined by a numerical setting represented in deciseconds.

In my example, 20 means 2 seconds.

You can press CTRL + C (or Command + C if you’re on macOS) to cancel the command.

Turn off help.autocorrect

To disable or turn off the help.autocorrect mode, you can set its value to 0.

git config help.autocorrect 0

Or if you want to completely remove it, you can manually do so in the .gitconfig file.


Happy coding 😊

Let me know what you think about this article in the comments section below.

If you find this article helpful, please share it with others and subscribe to the blog to support me, and receive a bi-monthly-ish e-mail notification on my latest articles.