Alias
Git aliases are shortcuts or custom commands that you can create to make your Git workflow more efficient. While there are no universally "popular" Git aliases since they can vary depending on individual preferences and workflows, I can provide you with some commonly used Git aliases that are generally helpful:
-
Basic Aliases:
coforcheckoutciforcommitbrforbranchstforstatusdffordifflgforlog --oneline --decorate --all --graphpulforpullpsforpush
-
Custom Commands:
unstageto unstage changes:git config --global alias.unstage 'reset HEAD --'lastto show the last commit:git config --global alias.last 'log -1 HEAD'amendto amend the last commit:git config --global alias.amend 'commit --amend'undoto undo the last commit:git config --global alias.undo 'reset HEAD~1 --mixed'
-
Listing Aliases:
aliasesto list all aliases:git config --get-regexp alias
-
Shortcuts for Branching:
bto create and checkout a new branch:git config --global alias.b 'checkout -b'bdto delete a branch:git config --global alias.bd 'branch -d'
-
Clean Up:
pruneto remove remote branches that no longer exist on the remote:git config --global alias.prune 'fetch --prune'cleanto remove untracked files and directories:git config --global alias.clean 'clean -df'
-
Commit History:
graphto display a pretty Git history graph:git config --global alias.graph 'log --oneline --graph --all --decorate'
-
Interactive Rebase:
irfor interactive rebase:git config --global alias.ir 'rebase -i'
-
Show Diffs:
wdiffto see word-based diffs:git config --global alias.wdiff 'diff --color-words'
-
Show Branches with Last Commit Date:
branchesto list branches with their last commit date:git config --global alias.branches 'for-each-ref --sort=-committerdate --format='"'"'%(committerdate:short) %04h %d %s'"'"' refs/heads/'
To add these aliases globally, you can use the git config --global alias.alias-name 'command' syntax as shown above.
# Basic Aliases
git config --global alias.co 'checkout'
git config --global alias.ci 'commit'
git config --global alias.br 'branch'
git config --global alias.st 'status'
git config --global alias.df 'diff'
git config --global alias.lg 'log --oneline --decorate --all --graph'
git config --global alias.pul 'pull'
git config --global alias.ps 'push'
# Custom Commands
git config --global alias.unstage 'reset HEAD --'
git config --global alias.last 'log -1 HEAD'
git config --global alias.amend 'commit --amend'
git config --global alias.undo 'reset HEAD~1 --mixed'
# Listing Aliases
git config --get-regexp alias
# Shortcuts for Branching
git config --global alias.b 'checkout -b'
git config --global alias.bd 'branch -d'
# Clean Up
git config --global alias.prune 'fetch --prune'
git config --global alias.clean 'clean -df'
# Commit History
git config --global alias.graph 'log --oneline --graph --all --decorate'
# Interactive Rebase
git config --global alias.ir 'rebase -i'
# Show Diffs
git config --global alias.wdiff 'diff --color-words'
# Show Branches with Last Commit Date
git config --global alias.branches 'for-each-ref --sort=-committerdate --format="%(committerdate:short) %04h %d %s" refs/heads/'