Photo of Joakim Hedlund

Joakim Hedlund

Web enthusiast

Enabling the built-in autocorrect in Git

Last updated

You know I meant checkout even if I wrote chekcout, so just do that!

This is exactly what I muttered to myself for years before I discovered the help.autocorrectsetting.

Git is capable of guessing what you meant, but by default it will only return an error and let you know there is a similarly spelled command:

$ git chekcout main
git: 'chekcout' is not a git command. See 'git --help'.

The most similar command is
    checkout

So let's change that by telling git to always assume I meant the most similar command, but give me 1 second to abort if it turns out that it's not what I wanted:

$ git config --global --add help.autocorrect 10

The number is an integer which represents tenths of a second. So if you set it to 50, Git will give you 5 seconds to change your mind before executing the autocorrected command.

Now when we do misspell commands if will give us a brief moment to CTRL+C, and then proceed automatically:

$ git chekcout main
WARNING: You called a Git command named 'chekcout', which does not exist.
Continuing in 0.5 seconds, assuming that you meant 'checkout'.
Switched to branch 'main'