DEV Community

Cover image for Mastering Git Shortcuts: A Guide to Git Aliases
Pradumna Saraf
Pradumna Saraf

Posted on

Mastering Git Shortcuts: A Guide to Git Aliases

Are you tired of typing lengthy Git commands? Git aliases are here to save the day! They let you establish shortcuts for common commands, thus enhancing your productivity.

Let's explore two ways to set them up.

Method 1: Git Config Command

Before starting, make sure you have Git installed.

Initially, you can utilize your terminal:

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

In this command, substitute <alias-name> with your preferred alias, and <git-command> with the actual Git command. For example:

git config --global alias.co 'checkout'
git config --global alias.st 'status'
Enter fullscreen mode Exit fullscreen mode

Method 2: Editing the .gitconfig File

Another approach involves making adjustments directly in your .gitconfig file, which is usually found in your home directory and add the following:

[alias]
  st = status
  co = checkout
  hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
Enter fullscreen mode Exit fullscreen mode

The first method also adds to the .gitconfig file, but directly editing the file tends to be a simpler process.

With these set up, you can now use git co in lieu of git checkout, and git st instead of git status. It's important to remember, these aliases are only applicable to your local machine.

Some users also prefer creating aliases in .bashrc or .zshrc files to abbreviate them even further, such as using gs for git status and gc for git checkout.

Top comments (17)

Collapse
 
bullbiased profile image
Bull

TIL about Git Alias 🔥

Collapse
 
pradumnasaraf profile image
Pradumna Saraf

Thank you.

Collapse
 
anushka_saxena profile image
ANUSHKA SAXENA

Helpful! Thanks for sharing this💯

Collapse
 
pradumnasaraf profile image
Pradumna Saraf

Thank you, ANUSHKA for reading.

Collapse
 
smminstagram profile image
Master Mind

SMM Instagram involves using strategic social media marketing techniques to enhance brand visibility, engage with the target audience, and promote products or services on the platform.

Collapse
 
smminstagram profile image
Master Mind

An SMM reseller is a third-party service provider that offers social media marketing services to clients by purchasing and reselling them from wholesale sources, helping businesses and individuals enhance their online presence and engagement.

Collapse
 
smminstagram profile image
Master Mind

A Facebook SMM Panel is a social media marketing tool that provides a centralized platform for managing and optimizing various aspects of a Facebook marketing campaign, including content scheduling, analytics, and audience engagement.

Collapse
 
vlasales profile image
Vlastimil Pospichal

I like
alias.make !make
to run make from project root

Collapse
 
suckup_de profile image
Lars Moelleken

Maybe someone find some helpful git aliases here. 👍

github.com/voku/dotfiles/blob/mast...

Collapse
 
jamesanu profile image
jamesanu

An SMM panel is an online platform that provides social media marketing services, allowing users to buy likes, followers, and other engagement metrics to enhance their social media presence.

Collapse
 
martinratinaud profile image
Martin Ratinaud

Here are some alias of mine if you wish :-)

gist.github.com/martinratinaud/f10...

Very handy to display a nice history for example

Collapse
 
eclecticcoding profile image
Chuck

Great job!

Also, if you use ZSH shell with ohmyzsh, there are several handy git plugins