Day 26/30 - Git Config --Global Alias: Create Custom Git Shortcuts
Ruqaiya Beguwala

Ruqaiya Beguwala @ruqaiya_beguwala

About: 👨‍💻 | Software Developer | Open-Source Enthusiast | JavaScript & NodeJS | Think and write about code every single minute

Location:
India
Joined:
Apr 26, 2025

Day 26/30 - Git Config --Global Alias: Create Custom Git Shortcuts

Publish Date: Jun 16
1 0

Introduction

Git is a powerful version control system, but typing long commands repeatedly can slow you down. Fortunately, Git allows you to create custom shortcuts (aliases) using git config --global alias. These aliases help streamline your workflow, reduce typing errors, and boost productivity.

In this guide, we'll explore how to create Git aliases, common use cases, and some pro tips to make the most of them.


How to Use Git Aliases

Git aliases are configured using the git config command. You can set them globally (for all repositories) or locally (for a single repository).

Basic Syntax

git config --global alias.<shortcut> "<full-command>"
Enter fullscreen mode Exit fullscreen mode

Example: Shortening git status

git config --global alias.st "status"
Enter fullscreen mode Exit fullscreen mode

Now, instead of git status, you can simply run:

git st
Enter fullscreen mode Exit fullscreen mode

Common Use Cases for Git Aliases

1. Shortening Frequently Used Commands

Instead of typing long commands, create short aliases:

git config --global alias.co "checkout"
git config --global alias.br "branch"
git config --global alias.ci "commit"
Enter fullscreen mode Exit fullscreen mode

Now, you can use:

  • git co instead of git checkout
  • git br instead of git branch
  • git ci instead of git commit

2. Creating Advanced Aliases

You can combine multiple Git commands into a single alias:

git config --global alias.ac "!git add -A && git commit -m"
Enter fullscreen mode Exit fullscreen mode

Usage:

git ac "Your commit message"
Enter fullscreen mode Exit fullscreen mode

This adds all changes and commits them in one step.

3. Log Formatting

The default git log can be verbose. Simplify it with:

git config --global alias.lg "log --oneline --graph --decorate --all"
Enter fullscreen mode Exit fullscreen mode

Now, git lg gives a clean, condensed history.

4. Undoing Changes

Create shortcuts for common undo operations:

git config --global alias.unstage "reset HEAD --"
git config --global alias.undo-commit "reset --soft HEAD~1"
Enter fullscreen mode Exit fullscreen mode

Usage:

  • git unstage file.txt (unstages a file)
  • git undo-commit (undoes the last commit while keeping changes)

Tips and Tricks

1. Using External Commands in Aliases

Prefix with ! to run shell commands:

git config --global alias.hello "!echo 'Hello, Git!'"
Enter fullscreen mode Exit fullscreen mode

Running git hello prints:

Hello, Git!
Enter fullscreen mode Exit fullscreen mode

2. Listing All Aliases

To see all configured aliases, run:

git config --global --list | grep alias
Enter fullscreen mode Exit fullscreen mode

3. Editing Aliases Directly in .gitconfig

Open your global Git config file:

git config --global --edit
Enter fullscreen mode Exit fullscreen mode

Then add aliases under the [alias] section:

[alias]
    st = status
    co = checkout
    lg = log --oneline --graph --decorate --all
Enter fullscreen mode Exit fullscreen mode

4. Overriding Existing Commands

You can even override default Git commands (use with caution!):

git config --global alias.log "log --pretty=format:'%h - %an, %ar : %s'"
Enter fullscreen mode Exit fullscreen mode

Now, git log uses your custom format.


Conclusion

Git aliases (git config --global alias) are a game-changer for developers. They save time, reduce repetitive typing, and make complex commands easier to remember. Whether you're shortening basic commands or creating advanced workflow shortcuts, aliases help you work more efficiently.


Want to know some cool aliases I created for automating my workflow? Checkout here


Up Next in the Series: git grep – Search for text across commits/branches


Daily advance GIT tips in your inbox---worth starting? Respond to my poll here🚀

For more useful and innovative tips and tricks, Let's connect on Medium

Comments 0 total

    Add comment