DEV Community

Nathan
Nathan

Posted on • Originally published at natclark.com

Autocorrecting Typos in Git Commands

Git offers extensive configuration.

There are several "gold nugget" options buried within the available configuration, and help.autocorrect is no exception.

By enabling it, whenever a typo in a Git command is detected, Git will automatically run the correct command after a custom period of time:

git config --global help.autocorrect 10
Enter fullscreen mode Exit fullscreen mode

That 10 at the end of this example command is equivalent to one second. Each integer is 0.1 seconds, so 5 is 0.5 seconds, 20 is 2 seconds, and so on.

1 is the minimum, but as far as I am aware, there is no maximum (within reasonable limits of course). You could prolong the delay a bit, giving you a chance to cancel the command if needed.

Anyway, once it has been enabled, let's suppose you typed the following command, which is intentionally misspelled:

git comit -am "example commit"
Enter fullscreen mode Exit fullscreen mode

You'd then get the following output:

WARNING: You called a Git command named 'comit', which does not exist.
Continuing under the assumption that you meant 'commit'
in 1.0 seconds automatically...
Enter fullscreen mode Exit fullscreen mode

Pretty neat, right?

Disabling autocorrect

To disable autocorrect, you can run the following command:

 git config --global help.autocorrect 0 
Enter fullscreen mode Exit fullscreen mode

Conclusion

I have many more Git tricks in my collection that I look forward to sharing on this site, and I hope you found this one useful!

Thanks for reading.

Discussion (0)