Published on

Git on steroids

  • avatar
    Talha Tahir
    linkedin @thetalhatahir
Hello Git!

Version control is one of the basic arsenal found in the toolset of a programmer. Git is one of the most popular version control systems. GitHub being the hub of all repositories including Google, Apple, and Facebook.

It's an essential skill that every programmer has to learn, but one should go a step ahead, Why not exceed in writing these daily commands?

Be honest, how many times a day do you have to do this?

npm run lint --fix
git add .
git commit -m "you commit message"
git push

And then this,

git checkout master
git pull

Oh and also this,

git checkout master
git pull
git checkout -b "new branch"

The list of commands that need to be written every time you pull or push from your remote repository can go on and on. Some companies have predefined checks, such as lint and format to maintain their code standards.

But there's a simple escape from all of this:

Git Alias : Your git scm on steroids

With aliases, you can add these commonly used commands to your terminal and execute them by typing just a few letters instead of the entire command.

There are two ways to set up aliases for Git.

Using git config

You can leverage git config command to set up aliases for your Git.


git config --global checkout

And then you use it like this:

git co

You can set up multiple aliases like this, making it easier to work with Git by typing only a few letters.

Using command line Alias

This is my recommended approach because it offers endless possibilities and saves you a lot of keystrokes.

You need to add aliases directly to your terminals rc file. For example, if you use zsh then its .zshrc, if you use bash then its .bashrc

Adding to .zshrc

alias gcm='git checkout master && git pull'
alias gs='git status'

And to use it, simply type in the terminal:

> gs

Using these directly on the terminal allows you to even shorten non-git commands, for example, if your project has a lint and format command which you manually have to run all the time, or if you have some test commands that you are required to run every other hour.

alias lint='npm run lint  --fix'
alias test='npm run jest'

With these powerful aliases, you can reduce typing and focus more on programming.

Here is a list of some of my frequently used aliases:

alias ga='git add . && git status'
alias gb='git branch'
alias gs='git status'
alias gc='git commit -m'
alias gpl='git pull'
alias gp='git push'
alias gpn='git push --no-verify'
alias gpnf='git push -f --no-verify'
alias gpnu='git push -u origin HEAD --no-verify'
alias glog='git log --graph'
alias gn='git checkout -b'
alias gcm='git checkout master && git pull'
alias gcp='git checkout - && git pull'
alias lint='./bin/lint fix'