Sign in
Log inSign up

Autocorrecting Typos in Git Commands

Nathan's photo
Nathan
·Sep 24, 2021·

2 min read

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

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"

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...

Pretty neat, right?

Disabling autocorrect

To disable autocorrect, you can run the following command:

 git config --global help.autocorrect 0

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.

Hassle-free blogging platform that developers and teams love.
  • Docs by Hashnode
    New
  • Blogs
  • AI Markdown Editor
  • GraphQL APIs
  • Open source Starter-kit

© Hashnode 2024 — LinearBytes Inc.

Privacy PolicyTermsCode of Conduct