Skip to content

Git Aliases: Speed Up Your Daily Git Commands

DodaTech Updated 2026-06-22 5 min read

In this tutorial, you'll learn about Git Aliases: Speed Up Your Daily Git Commands. We cover key concepts, practical examples, and best practices.

Git aliases are custom shortcuts for Git commands defined in your config that work like command-line abbreviations, reducing typing and preventing mistakes.

In this tutorial, you'll learn how to create Git aliases that turn complex commands into simple shortcuts. Git aliases reduce typing, prevent mistakes, and make your daily workflow faster. By the end, you'll build a personal alias library and share configurations with your team.

flowchart LR
  A[git st] --> B[git status]
  A[git co] --> B
  C[git lg] --> D[git log --graph --oneline]
  C[git hist] --> D
  E[git undo] --> F[git reset --soft HEAD~1]

Basic Aliases

Set aliases using git config:

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

Now use them:

git st        # Same as git status
git co main   # Same as git checkout main
git br        # Same as git branch
git ci -m "msg"  # Same as git commit -m "msg"

Advanced Aliases

Create aliases for complex commands:

# Pretty log graph
git config --global alias.lg "log --graph --oneline --all --decorate"

# Show last commit
git config --global alias.last "log -1 HEAD"

# Unstage a file
git config --global alias.unstage "reset HEAD --"

# Amend last commit with staged changes
git config --global alias.amend "commit --amend --no-edit"

# Show summary of changes per day
git config --global alias.daily "log --since='1 day ago' --author='Your Name'"

Using them:

git lg

Expected output:

* a1b2c3d (HEAD -> main) Add payment feature
* b2c3d4e Fix login bug
* c3d4e5f Initial commit
git unstage file.txt
# Same as: git reset HEAD -- file.txt

External Command Aliases

Run shell commands from Git aliases with !:

# Open Git GUI
git config --global alias.gui "!sh -c 'gitk'"

# List branches with last commit date
git config --global alias.bra "!git for-each-ref --sort=-committerdate refs/heads/ --format='%(refname:short) %(committerdate:relative)'"

# Quick push with upstream branch
git config --global alias.pushup "!git push -u origin HEAD"

Sharing Aliases with Your Team

Store shared aliases in repository config (not global):

# Inside your repo
git config alias.lg "log --graph --oneline --decorate"

# Or edit .git/config directly
# This file is NOT pushed. Use a shared script instead.

Better approach: create a scripts/git-aliases.sh in your repo:

#!/bin/bash
# Team-wide Git aliases
git config alias.lg "log --graph --oneline --all --decorate"
git config alias.ci "commit -v"
git config alias.unstage "reset HEAD --"

Team members run: bash scripts/git-aliases.sh

Git Alias with Arguments

For aliases that need to accept arguments, use a shell function:

# Alias that takes a branch name argument
git config --global alias.search '!f() { git log --oneline --all --grep="$1"; }; f'

# Usage: git search "bugfix"
git search "login"

Expected output:

a1b2c3d fix(login): resolve null pointer exception
b2c3d4e feat(login): add OAuth2 support

Alias from Shell Profile

Define aliases in your shell config for even shorter commands:

# ~/.zshrc or ~/.bashrc
alias gst='git status'
alias gco='git checkout'
alias gcb='git checkout -b'
alias gd='git diff'
alias gl='git log --oneline --graph'
alias gps='git push'

These are shell-level shortcuts, not Git aliases. They work in your terminal but not inside Git commands.

Managing Aliases

View all aliases:

git config --global --get-regexp alias

Expected output:

alias.st status
alias.co checkout
alias.br branch
alias.ci commit
alias.df diff
alias.lg log --graph --oneline --all --decorate

Remove an alias:

git config --global --unset alias.st

Common Errors

Error Cause Fix
Expansion of alias failed Quoting issue Use proper quoting for the command
fatal: bad config Config syntax error Edit ~/.gitconfig directly
Alias doesn't accept arguments Missing -c or positional ref Use shell function with !f() { ... }; f
git st works but git st file.txt fails Alias doesn't pass args Add "$@" at end of alias command
Alias conflicts with built-in command Replaces Git default Git built-ins take precedence over aliases
Global alias overridden by local Local config takes priority Check local config in .git/config
Team members don't have aliases Not shared Use a script or dotfiles repository

Practice Questions

What is a Git alias?

A Git alias is a user-defined shortcut for a Git command. Defined in Git config, aliases can shorten common commands (git st for git status) or create complex command pipelines (git lg for pretty log output).

How do I create an alias that accepts arguments?

Use a shell function: git config --global alias.exec '!f() { git log --oneline "$@"; }; f'. The $@ passes all arguments through. Without this, aliases with arguments may fail.

Can I run shell commands from Git aliases?

Yes. Prefix the alias value with ! to run external commands. Example: git config --global alias.gui "!gitk". The command runs in the repository root directory. Use this for complex pipelines or GUI tools.

How do I share aliases with my team?

Create a shell script in your repository that runs git config alias.<name> <command> for each alias. Team members execute the script once. Alternatively, store aliases in a shared dotfiles repository that everyone clones.

Can I use Git aliases in scripts?

Yes, but it's not recommended. Scripts should use full Git commands for clarity and portability. If another developer runs your script without the aliases configured, it will fail. Reserve aliases for interactive use

Challenge

Create 10 Git aliases that cover: status, checkout, commit, log (pretty graph), diff, branch, push with upstream, undo last commit, unstage files, and list branches with dates. Test each alias and verify the output matches the full command. Export the aliases to a script file that can be shared.

Real-World Task

Design a set of Git aliases for your team and store them in a scripts/git-shortcuts.sh file in the repository. Include aliases for team-specific workflows: creating feature branches with the correct naming convention, running pre-push checks, and formatting commit messages to match the team's convention. Document each alias with comments in the script. This approach is used at DodaTech to standardize Git workflows across all development teams.


Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro