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

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay