An alias is an ordinary config entry: it exists only in the scope where created (git log --graph --oneline → git graph), shell commands included.
| Scope | Applies to | Config file |
|---|---|---|
local | the current repository | .git/config (Windows: .git\config) |
global | the current user | ~/.gitconfig (Windows: %USERPROFILE%\.gitconfig) |
system | every user on the machine | /etc/gitconfig (Windows: %PROGRAMDATA%\Git\config) |
Creating one
git config --global alias.c "checkout"
git config --global alias.ec "commit --allow-empty -m 'Empty commit'" # single quotes when the command has double quotes
Or under [alias] in the config file:
| |
Shell aliases
An alias starting with ! runs the rest as a shell command (so && and | work), and must spell git out itself — a shell, not a git subcommand:
git config --global alias.search "!f() { git rev-list --all | xargs git grep $1; }; f"
⚠️ Inside a
!alias, always writegitexplicitly — the shell has no idea it was invoked by git.
My aliases
| Alias | Command | Usage |
|---|---|---|
c | checkout | git c develop |
f | fetch --prune | git f |
ec | commit --allow-empty -m 'Empty commit' | git ec |
graph | log --graph --oneline | git graph |
wp | worktree prune | git wp |
wa | !f() { git worktree prune && git worktree add $1 $2; }; f | git wa ../folder branch-name |
search | !f() { git rev-list --all | xargs git grep $1; }; f | git search keyword |
mb | !f() { git branch --show-current | xargs git merge-base $1; }; f | git mb origin/main |
reset-to-base | !f() { git mb $1 | xargs git reset; }; f | git reset-to-base origin/main |
mb and reset-to-base exist for one workflow: rebasing a messy branch without resolving one conflict per commit.