Mastering Git Shortcuts: A Guide to Git Aliases

Pradumna Saraf - Jul 28 '23 - - Dev Community

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.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player