How can I make git do the "did you mean" suggestion?

According to git-config(1), you want to set help.autocorrect appropriately. For example, git config --global help.autocorrect 5 will make it wait half a second before running the command so you can see the message first.


The autocorrect is nice, but my OCD-self needs a little more control over what's going on. So, I wrote a straightforward script that just chooses the first suggestion provided by git. You run the script after the failed command and use the built in bash history substitution "bang bang" syntax. Also, if you are typing something that could possibly have more than one command, this command lets you choose one other than the first option.

It would look something like this,

kristian@office:~/myrepo$ git puhs
git: 'puhs' is not a git command. See 'git --help'

Did you mean this?
      push

kristian@office:~/myrepo$ idid !!
Counting objects: 18, done.
Delta compression using up to 32 threads.
Compressing objects: 100% (10/10), done.
Writing objects: 100% (10/10), 1.17 KiB, done.
Total 10 (delta 6), reused 0 (delta 0)

Plus, it's fun to type anything with two exclamation points. So bonus for that.

Here's a gist with my script

Tags:

Git