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:
co
forcheckout
ci
forcommit
br
forbranch
st
forstatus
df
fordiff
lg
forlog --oneline --decorate --all --graph
pul
forpull
ps
forpush
-
Custom Commands:
unstage
to unstage changes:git config --global alias.unstage 'reset HEAD --'
last
to show the last commit:git config --global alias.last 'log -1 HEAD'
amend
to amend the last commit:git config --global alias.amend 'commit --amend'
undo
to undo the last commit:git config --global alias.undo 'reset HEAD~1 --mixed'
-
Listing Aliases:
aliases
to list all aliases:git config --get-regexp alias
-
Shortcuts for Branching:
b
to create and checkout a new branch:git config --global alias.b 'checkout -b'
bd
to delete a branch:git config --global alias.bd 'branch -d'
-
Clean Up:
prune
to remove remote branches that no longer exist on the remote:git config --global alias.prune 'fetch --prune'
clean
to remove untracked files and directories:git config --global alias.clean 'clean -df'
-
Commit History:
graph
to display a pretty Git history graph:git config --global alias.graph 'log --oneline --graph --all --decorate'
-
Interactive Rebase:
ir
for interactive rebase:git config --global alias.ir 'rebase -i'
-
Show Diffs:
wdiff
to see word-based diffs:git config --global alias.wdiff 'diff --color-words'
-
Show Branches with Last Commit Date:
branches
to 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/'