Yos Riady optimize for learning

Aliases with .gitconfig and .bash_profile

Let’s explore how you can set up aliases on your terminal to save you some keystrokes.

We’ll also briefly mention Git. If you are new to git, check out my other post: Git Going with Git

Tired of typing git status every single time? Using aliases, you can make it such that typing git st results in git status being executed. This works for longer commands as well, for example, in my .gitconfig I have this command:

log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate

set to lg. And by calling this abbreviated command git lg, we can get a nice color-coded git log with minimal effort.

Git Log

Okay! Time to try adding our own git aliases! Using this command from our home directory, we can view and edit or .gitconfig file:

vim .gitconfig

The first time you open up your .gitconfig, it may look something like this:

        name = Yos Riady
        email = yosriady@gmail.com

We can add the following convenience git aliases by adding the code below under your existing user information:

    st = status
    ci = commit
    br = branch
    co = checkout
    df = diff

Another git alias I recommend is git pull –rebase:

Note that you can also set git pull --rebase as a default behaviour with git config --global pull.rebase true

pull = pull --rebase

Having pull by default use the –rebase flag eliminates unnecessary merge commits which provides no helpful information and pollutes the git commit history.

Likewise, for terminal aliases, we can edit our .bashrc from our home directory:

vim .bash_profile
# syntax: alias name=value
alias ls='ls -p'
alias ll='ls -la'
alias c='clear'
alias v='vim'
alias x="exit"
alias ..='cd ..'
alias ...='cd ../../../'
alias ....='cd ../../../../'
alias .....='cd ../../../../'

Now, instead of typing the original commands, you save yourself a few keystrokes and do it better with aliases! Especially for common commands such as git status and git commit, it’s a good idea to have abbreviations for them.

Note: On OS X, you should set up .bash_profile to source .bashrc:

source ~/.bashrc

The aliases I have used in this post are by no means definitive must-have aliases, and there are plenty of other useful aliases outside of the above examples. For more on aliases, I recommend the two sources below.

Additional reading:


You should follow him on Twitter.

📬 Get updates straight to your inbox!

Subscribe to my newsletter to make sure you don't miss anything.

Here's something you might be interested in...

Going Serverless book

Have you heard about the Serverless programming model? The Going Serverless book teaches you how to build scalable applications with the Serverless framework and AWS Lambda. You'll learn how to design, develop, test, deploy, and secure Serverless applications from planning to production.

Learn more →