Date Published: 12 February 2020
I don’t know how I didn’t know about this before now, but apparently you can turn on autocorrect for your git command line, and it will accept (after a short delay in which you can cancel) commands that are close to but not exactly correct.
git chckout master
You probably meant:
git checkout master
And it will go ahead and do that for you.
Setting it up
You can set this up in your git config, either globally or per repo. I don’t know why you’d only want it for some repos so here’s how to do it globally:
git config --global help.autocorrect 20
Ok, so what’s the 20 at the end? This sounded like a true/false kinda thing, right? Well that’s how long it will wait before reissuing what it thinks is the right command, in tenths of seconds (weird choice, I know). So 20 is 2 seconds. Let’s give it a try:
Turn on and use git autocorrect (animated gif).
(for some reason this isn’t animating for me in Chrome but it works everywhere else)
Here’s a still capture of the end result. Note that 2 seconds passed before it issued the corrected pull command:
Using git autocorrect
That’s it! Turn it on and enjoy! I don’t know how I’m just learning about this since it’s been around for some time according to this Twitter search. Andy Carter also had a nice write-up. If you found this useful or have a related tip please leave a comment!
Steve is an experienced software architect and trainer, focusing on code quality and Domain-Driven Design with .NET.