Git protip: autocorrect command typos
By Maxime Bréhin • Published on 12 December 2022
• 2 min
Do you suffer from the foam fingers syndrome™ or type on the keyboard with mittens 🥊 on cold winter days? Then you will love that configuration option that corrects your Git commands on the fly.
How does it work?
The initial behavior is to get a message with the suggestion in our console.
# Default mode
> git config --global help.autocorrect 0
# Typo whilst writing the command
> git cmmit
# The message we get
git: 'cmmit' is not a git command. See 'git --help'.
The most similar command is
commit
We can also ask Git to automatically apply that suggestion, without validation. This is quite interesting but it could lead to usses when the suggestion is not quite on point.
> git config --global help.autocorrect immediate
# We can also use a numeric value for the time to wait before
# the suggestion applies (3 seconds in the example below, the value
# is in tenths of seconds)
# > git config --global help.autocorrect 30
# Typo whilst writing the command
> git git add
# The message we get
WARNING: You called a Git command named 'git', which does not exist.
Continuing under the assumption that you meant 'init'.
Initialized empty Git repository in /path/to/your/project/add/.git/
# A new `add/` directory is then created and initialized as a Git project 🤦♀️
Git 2.34, published in November 2021, introduced a new option to let us confirm the suggested command:
> git config --global help.autocorrect prompt
# Typo whilst writing the command
> git git add
# The message we get
WARNING: You called a Git command named 'git', which does not exist.
Run 'init' instead [y/N]?
We are now confident we can avoid any misinterpretation 😌!
More tips and tricks?
We’ve got a whole bunch of existing articles and more to come. Also check out our 🔥 killer Git training course: 360° Git!