Streamlining Your Workflow with Aliases

So far we have learned quite a few commands. Some, like the log commands, can be long and tedious to type. In this section, you will learn how to create custom shortcuts for Git commands.

Creating Custom Aliases

An alias allows you to type a shortened command to represent a long string on the command line.

For example, let's create an alias for the log command we learned earlier.

Original Command

$ git log --oneline --graph --decorate --all

Creating the Alias

$ git config --global alias.lol "log --oneline --graph --decorate --all"

Using the Alias

$ git lol

Explore Other Helpful Aliases

Check out these resources for a list of common aliases:

We also encourage you to read through these three blog posts by GitHub developer Phil Hack. His tips are referenced throughout the manual.

Pro Tip # 1: To edit aliases by hand, you can open the gitconfig file with your default editor.

git config --global alias.ec "config --global -e"

Pro Tip # 2: To checkout to another branch, you can make a quick shortcut.

git config --global alias.ch "checkout"

Pro Tip # 3: To checkout to a brand new branch, you can easily extend your existing shortcut.

git config --global alias.cob "checkout -b"

Pro Tip # 4: You can create aliases that only call one command.

git config --global alias.s "status -s"

Pro Tip # 5: Clean up branches quickly and easily.

$ git config alias.dlb '!git checkout <DEFAULT-BRANCH> && git pull --prune && git branch --merged | grep -v "\*" | xargs -n 1 git branch -d'

results matching ""

    No results matching ""