Last Updated: May 31, 2021
·
8.724K
· avnerner

Git - Autocorrect spelling

You might sometimes do:

git pusj  ## instead of push

Git will reply with:

git: 'pusj' is not a git command. See 'git --help'.

Did you mean this?
push

But wouldn't do anything..

To make it fall back to the closest action (which is what you really wanted it to do), add:
git config --global help.autocorrect 1

And now you'll get:

WARNING: You called a Git command named 'pusj', which does not exist.
Continuing under the assumption that you meant 'push'
in 0.1 seconds automatically...

And command will execute as hoped !

Credit and do not miss on Zach Holman's:
http://www.youtube.com/watch?v=Foz9yvMkvlA

9 Responses
Add your response

Couldn't make it work using: git config --global help.autocorrect 1
Had to edit my .gitconfig and add it manually.
Great tip, thanks!

over 1 year ago ·

This seems dangerous...which makes it AWESOME ;)

over 1 year ago ·

Great tip! I'm glad that I won't need to fight with my crazy fingers anymore. Thanks!

over 1 year ago ·

For my slowness 1 sec is a little bit short, but I asume that changing help.autocomplete 1 to something higher will solve that.
thanks

over 1 year ago ·

Note that the 1 does not equate to one second, rather 0.1 seconds. Use 10 for one second.

over 1 year ago ·

How tight, or accurate, are the autocorrects? Are there any obvious scenarios that would result in an autocorrect executing that isn't the actual command you intended to run? I don't have a great example, but clearly typing "pusj" = "push".

over 1 year ago ·

Never had a problem with that. git docs are saying: "If more than one command can be deduced from the entered text, nothing will be executed.".
I don't know for sure but I believe a basic algorithm such as levenshtein distance is used. also, there is pretty much nothing that can not be undone in Git using the reflog, so I see no risk here whatsoever.

over 1 year ago ·

Cool. Thanks for the quick response, avnerner.

over 1 year ago ·

Dangerous case found by a friend, "git resert" ^^ . Very likely with Azerty layout.

over 1 year ago ·