Did you know that if you mistype a Git command you can automatically run the suggested fix? I’ve been using Git for many years now and only just come across this feature today. To enable it you need to assign a value to the config setting
If you enable auto-correct the suggested command will run after a short delay to give you the chance to cancel the command if it is not what you intended. The length of the delay is defined by the value of
help.autocorrect which accepts integer values that represent a tenth of a second. For example:
git config --global help.autocorrect 20
This will enable auto-correct and suggested commands will run after 2 seconds. The
--global flag enables it for all your local Git repositories. If you only want it enabled on a specific repository just emit this flag.
So if I was to mistype the Git
commit command as say
cmmit Git would usually respond with a message like:
git: 'cmmit' is not a git command. See 'git --help'. Did you mean this? commit
Git is suggesting I meant to use the
commit command. With help.autocorrect set to 20 I would see the following instead:
WARNING: You called a Git command named 'cmmit', which does not exist. Continuing under the assumption that you meant 'commit' in 2.0 seconds automatically...
After 2 seconds the correct command would run.
This is really useful. You can find full details in the Git docs.
Comments are now closed.