Useful Git Aliases

Aliases are short names for long commands. They save a lot of typing. You can add them to your global Git config with git config --global alias.name "command".

Terminal output

$ git config –global alias.st "status -sb"
$ git config –global alias.co checkout
$ git config –global alias.br branch
$ git config –global alias.lg "log –oneline –graph –decorate"
$ git config –global alias.last "log -1 HEAD –stat"
$ git config –global alias.undo "reset –soft HEAD~1"
$ git st
## main
$ git lg
* ab2fc5b (HEAD -> main) Second commit
* 910ce77 First commit
$ git undo
$ git st
## main
A b.txt

Alias list

AliasReal commandUse
git stgit status -sbShort status with branch
git cogit checkoutSwitch or restore
git brgit branchList branches
git lggit log --oneline --graph --decorateCompact graph history
git lastgit log -1 HEAD --statShow the last commit
git undogit reset --soft HEAD~1Undo the last commit, keep the changes

How it works

  • Aliases are saved in the file ~/.gitconfig under the [alias] section.
  • You can also edit that file by hand with git config --global --edit.
  • Remove an alias with git config --global --unset alias.name.
Note: Create only the aliases you will really use. Also see Git Configuration.

Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.