Boost productivity with custom Git shortcuts that save keystrokes and streamline your daily development workflow
Typing git pull origin feature/user-authentication-with-oauth2-integration repeatedly wastes time. With aliases, type git pullcurrent instead - saving 51 keystrokes per command.
Git aliases are custom shortcuts for frequently used commands, making your workflow faster and more efficient.
Platform Note: I'm a Windows developer who lives in Git Bash - it's my primary CLI for everything. These aliases assume a POSIX shell (Git Bash, zsh, bash) and use commands like grep, xargs, and $(...) syntax. All commands work perfectly on Linux, macOS, and Windows via Git Bash. PowerShell users will need to adapt shell function aliases.
Direct command replacements:
git config --global alias.st status
# Usage: git stComplex commands with logic:
git config --global alias.pullcurrent '!f() { git pull origin $(git rev-parse --abbrev-ref HEAD); }; f'The ! prefix tells Git to execute as a shell command.
alias.pullcurrent = "!f() { git pull origin $(git rev-parse --abbrev-ref HEAD) \"${@}\"; }; f"Components:
! - Execute as shell scriptf() { ... }; f - Define and execute function$(git rev-parse --abbrev-ref HEAD) - Get current branch name\"${@}\" - Accept unlimited parametersgit config --global alias.pullcurrent '!f() { git pull origin $(git rev-parse --abbrev-ref HEAD) "${@}"; }; f'Usage:
git pullcurrent
git pullcurrent --rebaseWhy this over plain git pull? If you've set upstream tracking with
git config --global push.autoSetupRemote truethen plain git pull works fine. This alias is useful when:
git config --global alias.pd '!f() { git pull origin "$1" "${@:2}"; }; f'Usage:
git pd main
git pd develop --rebaseManual workflow:
git stash push -m "WIP"
git pull origin develop --rebase
git stash applyAlias solution:
git config --global alias.stashpullapply '!f() { git stash push --staged -m "$1"; git stash push -u -m "leftOver $1"; git pull origin "${2:-$(git rev-parse --abbrev-ref HEAD)}" "${@:3}"; git stash apply stash@{1}; git stash apply stash@{0}; }; f'Usage:
git stashpullapply "WIP: user profile"
git stashpullapply "WIP: fixes" develop --rebaseWhat it does:
⚠️ Note: If conflicts occur during stash apply, resolve them before continuing work.
git config --global alias.configsearch 'config --get-regexp'Usage:
git configsearch credential
git configsearch aliasgit config --global alias.last 'log -1 HEAD --stat'Quick verification of recent commit with file changes.
git config --global alias.undo 'reset HEAD~1 --soft'Removes last commit but keeps changes staged.
git config --global alias.amend 'commit --amend --no-edit'Adds staged changes to last commit without opening editor.
git config --global alias.addcommit '!f() { git add -A && git commit -m "$1"; }; f'Usage:
git addcommit "Fix login bug"git config --global alias.prettylog 'log --graph --pretty=format:"%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset" --abbrev-commit'Colorful commit history with visual branch graph.
git config --global alias.cleanup '!f() { git branch --merged ${1:-main} | grep -v "^\\*\\|main\\|develop" | xargs -r git branch -d; }; f'Preview before deletion:
git branch --merged mainUsage:
git cleanup
git cleanup develop⚠️ Warning: Review output before running. Squash-merged and rebased branches may not show as "merged" and could be deleted incorrectly. Always verify branch list first with git branch --merged.
git config --global alias.findcommit '!f() { git log --all --grep="$1" --oneline --color; }; f'Usage:
git findcommit authentication
git findcommit "bug fix"git config --global alias.filehistory '!f() { git log --follow -p --stat -- "$1"; }; f'Usage:
git filehistory src/components/Login.jsTrack commands you type frequently:
git config --global alias.changed 'diff --name-only'git config --global alias.filelog '!f() { git log --follow -p -- "$1"; }; f'git config --global alias.quick-commit '!f() { git add -A && git commit -m "$1"; }; f'git config --global alias.pullcurrent '!f() { git pull origin $(git rev-parse --abbrev-ref HEAD) "${@}"; }; f'| Syntax | Description |
|---|---|
$1, $2, $3 | Individual parameters |
"$1" | First parameter (quoted) |
"${@}" | All parameters |
"${@:2}" | Parameters from 2nd onward |
${1:-default} | First parameter or default |
git config --get-regexp aliasgit config --global --editgit config --global --unset alias.aliasnamegit config --get-regexp alias > my-aliases.txtTo import aliases from a file:
# Read each line and add to git config
while IFS= read -r line; do
if [[ $line =~ ^alias\. ]]; then
key=$(echo "$line" | cut -d' ' -f1 | sed 's/alias\.//')
value=$(echo "$line" | cut -d' ' -f2-)
git config --global "alias.$key" "$value"
fi
done < my-aliases.txtOr manually copy aliases to your .gitconfig file.
Not all aliases are good ideas. Here's what I deliberately don't alias:
Destructive Commands
git reset --hard - Too dangerous to abbreviategit push --force - Should always be explicitgit clean -fd - Needs conscious decisionCommands That Hide Behavior
Overlapping Functionality
filehistory over filelog - pick one pattern and stick with itaddcommit is my choice over separate add/commit aliasesIf an alias makes you think "what did that just do?", it's too clever.
pullcurrent over pc.gitconfigalias.commit# Wrong
git config --global alias.test !f() { echo test; }; f
# Correct
git config --global alias.test '!f() { echo test; }; f'# Wrong (in .gitconfig)
alias.test = "!f() { echo "hello"; }; f"
# Correct
alias.test = "!f() { echo \"hello\"; }; f"# Wrong
alias.test = !git pull origin $1
# Correct
alias.test = '!f() { git pull origin "$1"; }; f'[user]
name = John Doe
email = john@example.com
[push]
autoSetupRemote = true
[alias]
pullcurrent = "!f() { git pull origin $(git rev-parse --abbrev-ref HEAD) \"${@}\"; }; f"
pd = "!f() { git pull origin \"$1\" \"${@:2}\"; }; f"
stashpullapply = "!f() { git stash push --staged -m \"$1\"; git stash push -u -m \"leftOver $1\"; git pull origin \"${2:-$(git rev-parse --abbrev-ref HEAD)}\" \"${@:3}\"; git stash apply stash@{1}; git stash apply stash@{0}; }; f"
configsearch = config --get-regexp
last = log -1 HEAD --stat
undo = reset HEAD~1 --soft
amend = commit --amend --no-editInstall essential aliases in one go:
# Essential aliases
git config --global alias.pullcurrent '!f() { git pull origin $(git rev-parse --abbrev-ref HEAD) "${@}"; }; f'
git config --global alias.pd '!f() { git pull origin "$1" "${@:2}"; }; f'
git config --global alias.last 'log -1 HEAD --stat'
git config --global alias.undo 'reset HEAD~1 --soft'
git config --global alias.amend 'commit --amend --no-edit'
git config --global alias.configsearch 'config --get-regexp'
# Bonus: Auto setup remote tracking for easier push
git config --global push.autoSetupRemote trueAction Steps:
pullcurrent for one weekGit aliases transform repetitive tasks into single commands. Start with a few essential aliases, then build custom solutions as patterns emerge in your workflow.
The best alias is one you'll actually use. Start small, iterate, and share what works.
What's your most-used Git command? That's your first alias candidate.