Applying Git Auto-Correction
Now that you've enabled and configured Git auto-correction, let's explore how to apply it in your daily Git workflow.
Correcting Common Git Typos
With Git auto-correction enabled, you can easily correct common typos as you work with Git. For example, let's say you accidentally type git psuh
instead of git push
:
$ git psuh
Did you mean this?
git push
[y/n] y
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 274 bytes | 274.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), done.
To https://github.com/username/repository.git
abcd1234..efgh5678 main -> main
In this example, Git automatically detects the typo and suggests the correct command, git push
. You can then confirm the correction by typing y
and pressing Enter, and Git will execute the correct command.
Handling More Complex Typos
Git auto-correction can also handle more complex typos, such as mistakes in branch names or commit hashes. For instance, if you accidentally type git checkout masteer
instead of git checkout master
:
$ git checkout masteer
Did you mean one of these?
git checkout master
[y/n] y
Switched to branch 'master'
Git recognizes the typo and suggests the correct branch name, master
. You can then confirm the correction and Git will switch to the correct branch.
Customizing Auto-Correction Behavior
If you find that Git's auto-correction is not behaving as expected, you can further customize its behavior by modifying the help.autocorrect
configuration option. For example, you can increase the auto-correction delay to give you more time to review and confirm the suggested correction:
git config --global help.autocorrect 50
This sets the auto-correction delay to 5 seconds, giving you more time to review the suggested correction before it is automatically applied.
By applying Git auto-correction in your daily workflow, you can save time and reduce the risk of costly mistakes caused by common Git typos.