Disclaimer: ChatGPT generated document.
Git aliases can save you time by allowing you to create shortcuts for commonly used commands. Here are some useful and commonly used Git aliases, along with instructions on how to add them to your Git configuration:
- Alias:
st
- Command:
git status
- Add it:
git config --global alias.st status
- Alias:
lg
- Command:
git log --oneline --graph --decorate --all
- Add it:
git config --global alias.lg "log --oneline --graph --decorate --all"
- Alias:
last
- Command:
git log -1 HEAD
- Add it:
git config --global alias.last "log -1 HEAD"
- Alias:
cm
- Command:
git commit -am "message"
- Add it:
git config --global alias.cm "commit -am"
- Alias:
up
- Command:
git pull --rebase
- Add it:
git config --global alias.up "pull --rebase"
- Alias:
unstaged
- Command:
git diff
- Add it:
git config --global alias.unstaged diff
- Alias:
staged
- Command:
git diff --cached
- Add it:
git config --global alias.staged "diff --cached"
- Alias:
amend
- Command:
git commit --amend
- Add it:
git config --global alias.amend "commit --amend"
- Alias:
compare
- Command:
git diff --stat
- Add it:
git config --global alias.compare "diff --stat"
- Alias:
alias
- Command:
git config --get-regexp ^alias\.
- Add it:
git config --global alias.alias "config --get-regexp ^alias\."
To add these aliases, you can either use the git config
command as shown above, or you can manually add them to your Git configuration file. Here's how:
- Open your global Git configuration file (
~/.gitconfig
) in a text editor. - Add the following under the
[alias]
section:[alias] st = status lg = log --oneline --graph --decorate --all last = log -1 HEAD cm = commit -am up = pull --rebase unstaged = diff staged = diff --cached amend = commit --amend compare = diff --stat alias = config --get-regexp ^alias\.
By adding these aliases, you'll be able to type shorter commands and boost your productivity when using Git.