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
| Alias | Real command | Use |
|---|---|---|
git st | git status -sb | Short status with branch |
git co | git checkout | Switch or restore |
git br | git branch | List branches |
git lg | git log --oneline --graph --decorate | Compact graph history |
git last | git log -1 HEAD --stat | Show the last commit |
git undo | git reset --soft HEAD~1 | Undo the last commit, keep the changes |
How it works
- Aliases are saved in the file
~/.gitconfigunder 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. |