Did you ever fat finger a git command? Did git actually ask you if you meant the command which you intended to type anyway? Were you mildly irritated that git didn’t go ahead and executed the command it deduced? Something like the interaction below:
Well, you can turn your irritation into admiration for git. git has a autocorrect feature that you can enable if needed.
The feature can be enabled by setting the help.autocorrect
config appropriately. Here’s what the man pages have to say about the setting:
Automatically correct and execute mistyped commands after waiting for the given number of deciseconds (0.1 sec). If more than one command can be deduced from the entered text, nothing will be executed. If the value of this option is negative, the corrected command will be executed immediately. If the value is 0 - the command will be just shown but not executed. This is the default.
By default, the help.autocorrect
value is 0, which means that you get the Did you mean this?
question, but no correction happens. Setting it to a positive value will make git correct to deduced command after that much time (in deciseconds - so setting a value of 10 will make git autocorrect in a second.) Setting a negative value will make git autocorrect immediately, and this is probably something you don’t want.
So go ahead and set help.autocorrect
to a sane value, and stop worrying about your typos:
Now, you interaction with git can be irritation-free:
Related: While the above is only for git, you might want to look at thefuck if you want similar autocorrect for any command you type. The appropriately named utility goes beyond just correcting typos, however. It can also do suggested commands (like git push
when no upstream is set.)