Skip to content
Home
Git Aliases: Speed Up Your Git Workflow

Git Aliases: Speed Up Your Git Workflow

Git Git 8 min read 1560 words Beginner ExcellentWiki Editorial Team

Git aliases let you create shortcuts for commands you use every day. Instead of typing git log --oneline --graph --all --decorate, you can type git tree. Aliases reduce typing, prevent typos, and make Git faster to use. Over time, a well-tuned set of aliases can save dozens of keystrokes per day and dramatically speed up your workflow.

Setting Up Aliases

Aliases are configured in your Git config file:

# Global alias
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.st status
git config --global alias.ci commit
git config --global alias.df diff

# Now you can type
git co    # instead of git checkout
git st    # instead of git status
git ci -m "message"  # instead of git commit -m "message"

You can also edit ~/.gitconfig directly:

[alias]
    co = checkout
    br = branch
    st = status
    ci = commit
    df = diff
    dc = diff --cached
    lg = log --oneline --graph --decorate
    last = log -1 HEAD
    unstage = reset HEAD --
    amend = commit --amend
    undo = reset --soft HEAD~1

When you define aliases directly in the config file, it is easier to add comments, organize them by category, and copy them between machines. Many developers maintain a ~/.gitconfig file that is tracked in a dotfiles repository for portability across workstations.

Essential Aliases

Logging and History

# Compact, colorful log
lg = log --oneline --graph --decorate --all

# Detailed log with dates
ld = log --oneline --format='%C(yellow)%h %Cgreen%ad %Creset%s %Cblue[%an]' --date=short

# Show commits by author
contrib = shortlog --summary --numbered

# Show last commit
last = log -1 HEAD --stat

# Show what branch you're on and recent commits
recent = for-each-ref --sort=-committerdate refs/heads/ --format='%(refname:short) | %(committerdate:relative) | %(subject)'

The lg alias is arguably the most popular Git alias in existence. It turns the dense git log output into a visual graph that makes branch structure and commit relationships immediately clear. The ld alias adds dates, which is helpful when you are tracking down when a regression was introduced.

Diff and Changes

# Show staged changes
dc = diff --cached

# Show changes since last commit
what = diff --word-diff HEAD~

# Summary of changes
diffs = diff --stat

# Show files changed in a commit
files = diff-tree --no-commit-id --name-only -r

The --word-diff flag in the what alias shows changes at the word level rather than the line level, making it much easier to spot small changes inside long lines. This is especially useful when reviewing documentation or configuration file changes where only a single word differs.

Branch Management

# List branches with last commit
branches = branch -v

# Delete merged branches (cleanup)
cleanup = !git branch --merged | grep -v '\\*\\|main\\|develop' | xargs -r git branch -d

# Rename current branch
rename = branch -m

# Create and switch to a new branch
new = checkout -b

The cleanup alias is one of the most valuable maintenance commands. After a few weeks of active development, most repositories accumulate stale branches that were never deleted. Running this alias periodically keeps your branch list manageable and reduces cognitive overhead when switching between tasks.

Commit and Staging

# Amend without editing message
amend = commit --amend --no-edit

# Unstage all files
unstage = reset HEAD --

# Undo last commit (keep changes)
undo = reset --soft HEAD~1

# Interactive add
ia = add -i

# Add all and commit
ac = !git add -A && git commit

The undo alias is a safety net that every developer should have. When you commit too early or realize you missed something, git undo rewinds the last commit while keeping all your changes in the working directory. You can then fix the problem and recommit.

Advanced Aliases with Shell Commands

Aliases can run shell commands using !:

# Count lines of code in the repo
loc = !git ls-files | xargs wc -l | tail -1

# Show the current branch name (useful for prompts)
branch-name = rev-parse --abbrev-ref HEAD

# Find commits that changed a file
find = log --oneline --follow --

# Interactive rebase for last N commits
reword = !r() { git rebase -i HEAD~$1; }; r

# Show contributors sorted by commits
contributors = shortlog -sn --no-merges

# Count commits per author this month
monthly = shortlog -sn --since='1 month ago'

# Show TODO/FIXME comments
todos = !git grep -n 'TODO\\|FIXME\\|HACK' $(git rev-parse --show-toplevel)

# Prune remote tracking branches
prune-local = remote prune origin

# Show stash list with dates
stashes = stash list --format='%C(yellow)%gd %Cgreen%ci %Creset%s'

Shell aliases (prefixed with !) are incredibly powerful because they let you combine Git commands with arbitrary shell logic. The loc alias for counting lines of code is a team favorite — it gives an instant sense of project size. The todos alias scans the entire codebase for leftover markers, which is invaluable before releases.

Custom Shell Functions in Aliases

For more complex logic, define shell functions inside the alias:

# Search commits by pattern in diff
grep-changes = !f() { git log --all --oneline -G "$1"; }; f

# Show diff stats for a specific author
stats-by = !f() { git log --author="$1" --stat --since="1 year ago" | tail -20; }; f

# Find the merge base and compare branches
diff-with = !f() { git diff $(git merge-base HEAD "$1").."$1"; }; f

These function-based aliases accept parameters, making them as flexible as small custom scripts. The grep-changes alias is particularly useful when you need to find every commit that touched a specific function or variable name.

Git Config Aliases for Productivity

Aliases for Config Management

# Edit config
config-edit = config --global --edit

# List all aliases
aliases = config --global --get-regexp alias

# Unset an alias
unalias = config --global --unset alias.

Workflow Aliases

# WIP — create a temporary work-in-progress commit
wip = !git add -A && git commit -m 'WIP'

# Continue after merge conflict resolution
continue = !git add -A && git rebase --continue

# Sync fork with upstream
sync = !git fetch upstream && git rebase upstream/main

# Create a fixup commit for interactive rebase
fixup = !git add -A && git commit --fixup HEAD

The fixup alias pairs perfectly with interactive rebase. Run git fixup to create a fixup commit for your current changes, then git rebase -i --autosquash HEAD~N to automatically squash it into the correct commit. This pattern keeps your history clean without requiring manual commit message editing during rebase.

Shell Integration

Git Prompt in Bash/Zsh

Add the current branch to your shell prompt:

# In ~/.bashrc or ~/.zshrc
parse_git_branch() {
    git branch 2>/dev/null | sed -n '/\* /s///p'
---

export PS1='\u@\h \w $(parse_git_branch) \$ '

Git Completion

Enable tab completion for Git commands and branches:

# Download completion script
curl -o ~/.git-completion.bash \
    https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash

# In ~/.bashrc
source ~/.git-completion.bash

Global Ignore

Aliases are even better when combined with a global .gitignore:

git config --global core.excludesFile ~/.gitignore_global

Common global ignores: .DS_Store, *.log, .idea/, .vscode/, *.swp.

Example Daily Workflow

With aliases set up, a typical workflow becomes much shorter:

# Without aliases
git checkout -b feature/new-thing
git add -A
git commit -m "Add new feature"
git checkout main
git pull origin main
git checkout feature/new-thing
git rebase main
git push origin feature/new-thing

# With aliases
git new feature/new-thing
git ac -m "Add new feature"
git co main
git pull
git co feature/new-thing
git rebase main
git push -u origin feature/new-thing

Pro Tips

  1. Start with a few aliases — add more as you notice repetitive typing
  2. Use ! for complex shell commands — this lets you chain Git commands with other tools
  3. Share aliases with your team — create a .gitalias file and source it in .gitconfig
  4. Use Oh My Zsh Git plugin — if you use Zsh, it provides 100+ aliases out of the box
  5. Practice with gitalias files — the community maintains comprehensive alias collections on GitHub
  6. Version-control your aliases — store your ~/.gitconfig in a dotfiles repository so you can sync aliases across machines and recover them after a system reinstall

FAQ

Q: Where are Git aliases stored? A: They are stored in your Git configuration file — either ~/.gitconfig (global) or .git/config (repository-specific).

Q: Can I use arguments in Git aliases? A: Yes. For simple arguments, Git passes them automatically. For complex shell aliases, define a function with !f() { ... }; f and use $1, $2, etc.

Q: How do I list all my current aliases? A: Run git config --global --get-regexp alias or set up an alias: git config --global alias.aliases "config --global --get-regexp alias".

Q: What is the difference between an alias and a shell script? A: Aliases are defined in Git config and are always available when using Git. Shell scripts are separate files that must be in your PATH. Aliases are better for simple shortcuts; scripts are better for complex multi-step workflows.

Q: Can I alias Git subcommands with the same name as built-ins? A: Yes. For example, git config --global alias.commit "commit --verbose" overrides the default git commit behavior. Use this carefully — it may confuse other developers working on your machine.

Q: How do I remove a Git alias? A: Run git config --global --unset alias.<name> or delete the line from your ~/.gitconfig file.

For a comprehensive overview, read our article on Git Advanced Commands.

For a comprehensive overview, read our article on Git Bisect Guide.

Section: Git 1560 words 8 min read Beginner 756 articles in section Report inaccuracy Back to top