Skip to content
Tutorials Center
My learning

Topics

Git Reference ยท Configuration Options

help.autocorrect setting

Reference for help.autocorrect: how Git reacts to a mistyped command, with the values show, prompt, immediate, never and a delay, plus aliases and limits.

help.autocorrect decides what Git does when you type a command that does not exist, such as git statsu. By default Git only prints an error and, if one command is clearly the closest match, a suggestion. With this setting you can have Git show the suggestion in a fixed form, ask whether to run it, or run it straight away.

The matching is a simple edit-distance comparison against the names of Git commands and your aliases. It is meant for typos, not for guessing what you mean, so it only acts when the best candidate is much better than the others.

Terminal
git config --global help.autocorrect prompt
git config --global help.autocorrect 20      # wait 2 seconds, then run it
git config --global help.autocorrect never   # no suggestions at all

Try it

Bash Each autocorrect mode on a typo

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash No close match, and aliases as shortcuts

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
git config help.autocorrect <value>
Value Behavior
0, false, no, off, never (or unset) Print the error and, when there is a close match, The most similar command is .... Nothing is run. never also removes the suggestion.
show Print the suggestion and run nothing (the same result as the default in current versions, spelled out explicitly).
prompt Print the corrected command and ask Run 'git status' instead [y/N]?. Needs a terminal.
1, immediate, true, yes, on Run the corrected command at once.
number n greater than 1 Wait n tenths of a second, so you can press Ctrl+C, then run it. 20 waits two seconds.

The corrections apply only when exactly one command is clearly closest. If several are about equally close, Git lists them as candidates and exits with status 1 without running anything.

Exit status: an unknown command that is not corrected exits with status 1 (the library usage error), so scripts can detect it. When autocorrection runs a command, its exit status is that command's.

Usage notes

  • Be careful with immediate. A wrong guess runs a command you did not type, and the risk is greatest for commands that rewrite state. That is the reason the default only suggests. prompt is the safer way to get the convenience.
  • It only fixes the command name, not options, branch names or file paths. For those, shell completion is the better tool.
  • Aliases take part. If you define alias.co and mistype something close to it, Git can offer the alias. A common typo that you make every day is better solved with its own alias (see alias.*), which also works in scripts.
  • Non-interactive use. In scripts, CI jobs and editor integrations a prompt cannot be answered, and a delayed run slows things down. Keep the default in those environments or set never.
  • Version notes: the word values (show, never, immediate, prompt) were added in recent releases; older versions understand only numbers. The numeric 1 for "run at once" works everywhere.
  • Related help settings are separate keys: help.format (man, info, web, html), help.browser and help.htmlPath choose how git help shows documentation. See git help.
  • Typos in subcommands (git remote ad) are not handled by this feature; only the first word after git is.