Useful Git Aliases for Productivity

A recent addition to my Automatic Development Environment Setup script were several Git aliases that help to speed up development. Here is how and why I set them up.

Start the Day with git pom

The first step in most developer workflows is to run git pull origin main to ensure your local work is current with the main line of development. Shave a few seconds off this routine step by shortening the command to git pom:

$ git config --global alias.pom 'pull origin main'

$ git pom
remote: Counting objects: 5, done.
remote: Total 5 (delta 2), reused 2 (delta 2), pack-reused 3
Unpacking objects: 100% (5/5), done.

Get Caught Up with git ls

Once you've pulled the latest from main, it can be helpful to see what's changed in the repository. Configuring an alias for git ls can simplify common but verbose calls to git log ...:

$ git config --global "log --pretty=format:'%C(yellow)%h %ad%Cred%d %Creset%s%Cblue [%cn]' --decorate --date=short"

$ git ls
48f3317 2018-04-28 (HEAD -> main) Starts useful git aliases article [James Tharpe]
44b55a0 2018-04-01 (origin/main, origin/HEAD) Started CLI/TypeScript article [James Tharpe]
3748172 2017-12-22 Publishes serverless-aws-backend [James Tharpe]
5d51a2e 2017-12-22 Completes [James Tharpe]
cd058e2 2017-12-17 WIP: Form2Email [James Tharpe]

(just type q to quit)

Pick Up Where You Left Off With git last

If you're absent-minded like I am then an interruption can cause you to forget what you just committed. Rather than using git ls to check the logs, git last can be useful to quickly see only the most recent commit.

$ git config --global alias.last 'log -1 HEAD'

$ git last
commit 48f3317298e16046c4934b6ea6d37fa4bc0ca1c1 (HEAD -> main)
Author: James Tharpe <[email protected]>
Date:   Sat Apr 28 08:19:33 2018 -0400

    Starts useful git aliases article

Prepare for the Daily Standup with git standup

A quick way to remember what you were working on recently for your team's daily standup is to view the Git log since yesterday. A nice alias for this is git standup:

$ git config --global alias.standup "log --since yesterday --author $(git config --pretty=short"

$ git standup
commit 0d686aeef569e6762abab8e16cd2118a791be600 (HEAD -> main)
Author: James Tharpe <[email protected]>

    Outlines git aliases article

commit 6ded0e6b249b28984127f1221a713f69b74830e5
Author: James Tharpe <[email protected]>

    Starts useful git aliases article

Get Everything with git everything

Working with Git submodules can be prone to error, since submodules don't update like the rest of your codebase does when you run git pom or similar commands. To avoid forgetting to update or initialize submodules in your repository, configure git everything:

$ git config --global alias.everything "! git pull && git submodule update --init --recursive"

$ git everything
remote: Counting objects: 8, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 8 (delta 5), reused 8 (delta 5), pack-reused 0
Unpacking objects: 100% (8/8), done.
   44b55a0..0d686ae  main     -> origin/main
Updating 44b55a0..0d686ae
 content/ | 63 +++++++++++++++++++++++++++++++++++++++++++
 themes/minimal                |  2 +-
 2 files changed, 64 insertions(+), 1 deletion(-)
 create mode 100644 content/
Submodule 'themes/minimal' ([email protected]:calintat/minimal.git) registered for path 'themes/minimal'
Cloning into 'C:/Users/james/code/me/temp/'...
Submodule path 'themes/minimal': checked out '2ac9acc008de52f61cc79fe2f93e61ba62e17d3b'

Prune Branches Merged with main with git branch-clean

Branches help keep track of incomplete or undelivered work, but once the work is complete we sometimes forget to remove the branches we no longer need. To clean up branches that are already merged with main in one swoop, configure git branch-clean:

$ git config --global alias.branch-clean "! git branch --merged main | grep -v '^[ *]*main$' | xargs git branch -d"

$ git branch-clean
Deleted branch article/useful-git-aliases (was da41448).
Deleted branch article/hire-me (was 23841b8).

Remember Git Aliases with Yet Another Alias

So you've setup all these aliases but can't remember them. One more alias to help remember all your aliases:

$ git config --global alias.aliases "config --get-regexp alias"

$ git aliases
alias.pom pull origin main
alias.last log -1 HEAD log --pretty=format:'%C(yellow)%h %ad%Cred%d %Creset%s%Cblue [%cn]' --decorate --date=short
alias.amend commit -a --amend
alias.standup log --since yesterday --author [email protected] --pretty=short
alias.everything ! git pull && git submodule update --init --recursive
alias.aliases config --get-regexp alias

Learn More About Git Aliases

Check out the Git Basics - Git Aliases chapter of Pro Git to learn more about Git aliases.

Broader Topics Related to Git Aliases


A distributed version-control system to track changes, typically for software development projects


Shells process text based commands

Git Aliases Knowledge Graph