DEV Community

Cover image for A guide to Git Aliases
Sarah Lean 🏴󠁧󠁢
Sarah Lean 🏴󠁧󠁢

Posted on • Edited on • Originally published at techielass.com

5

A guide to Git Aliases

Typing long commands can get tiresome, this is where aliases can come in handy!

In this blog post I’ll share how you can set up aliases for your Git commands. Using aliases allows you to set up shortcuts that will make your life easier. There are two ways in which you can set up your aliases.

Set up aliases using the Git config command

You can set up your aliases using a command within your command line tool.

The format for the command is:

git config --global alias.<alias-name> '<git-command>'
Enter fullscreen mode Exit fullscreen mode

In practice that means if you want to type git c instead of typing git checkout the alias you would configure is:

git config --global alias.c checkout
Enter fullscreen mode Exit fullscreen mode

Setting up a Git alias

Set up aliases using the .gitconfig file

Another approach is to make modifications to the .gitconfig file. This is usually stored within your home directory, on my Windows machine it was stored under _C:\users\sarah\ _

Within this file create an alias section like below:

[alias]

# Shortcut for status
st = status

# Shortcut for checkout
co = checkout

# Shortcut for branch
b = branch

# Shortcut for help
h = help

# Shortcut for last commit
last = log -1 HEAD

# Shortcut to query log for altered files
l = log --stat

# Shortcut to query log and make it pretty
ld = log --graph --decorate --date=short
Enter fullscreen mode Exit fullscreen mode

Deleting a Git alias

If you want to remove an alias you can delete the configuration from the .gitconfig file or you can use the following command:

git config --global --unset alias.<alias-name>
Enter fullscreen mode Exit fullscreen mode

Deleting a Git alias

Check all aliases in Git

If you want to check which aliases are currently set within your configuration you can use the command:

git config --get-regexp '^alias\.'
Enter fullscreen mode Exit fullscreen mode

Using Git aliases

Now that the aliases are set up you can now use them when you are within your command line tool. I can now use git l in lieu of git log –stat.

💡 It’s important to remember, these aliases are only applicable to your local machine.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay