An alias is an ordinary config entry: it exists only in the scope where created (git log --graph --oneline → git graph), shell commands included.

ScopeApplies toConfig file
localthe current repository.git/config (Windows: .git\config)
globalthe current user~/.gitconfig (Windows: %USERPROFILE%\.gitconfig)
systemevery user on the machine/etc/gitconfig (Windows: %PROGRAMDATA%\Git\config)

Creating one Link to this section

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:

1
2
3
[alias]
    c = checkout
    ec = commit --allow-empty -m 'Empty commit'

Shell aliases Link to this section

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 write git explicitly — the shell has no idea it was invoked by git.

My aliases Link to this section

AliasCommandUsage
ccheckoutgit c develop
ffetch --prunegit f
eccommit --allow-empty -m 'Empty commit'git ec
graphlog --graph --onelinegit graph
wpworktree prunegit wp
wa!f() { git worktree prune && git worktree add $1 $2; }; fgit wa ../folder branch-name
search!f() { git rev-list --all | xargs git grep $1; }; fgit search keyword
mb!f() { git branch --show-current | xargs git merge-base $1; }; fgit mb origin/main
reset-to-base!f() { git mb $1 | xargs git reset; }; fgit reset-to-base origin/main

mb and reset-to-base exist for one workflow: rebasing a messy branch without resolving one conflict per commit.

References Link to this section