Creating Aliases to Shorten Up Long Commands

Typing same long commands can be a lot of hastle while performing various actions in terminal like

1
2
3
4
5
git pull origin master
git push origin master

git pull origin production
git pull origin master

Rather than doing all this again and again we can create short commands for these commonly used commands. For this we need to create a file named .bash_aliases in our home directory.

After creating file open with your favourite editor and start adding your shortcuts. Here are a few that I use commonly :

~/.bash_aliases
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# rails
alias s='rails s'
alias c='rails s'
alias create='rake db:create'
alias migrate='rake db:migrate'
alias reset='rake db:reset'

#git
alias gpullm='git pull origin master'
alias gpushm='git push origin master'
alias gpullp='git pull origin production'
alias gpushp='git push origin production'
alias gmm='git merge master'
alias gmm='git merge production'


#projects
alias abc='cd && cd ~/projects/abc'
alias xyz='cd && cd ~/projects/xyz'

Add this file as a reference for aliases in your .bashrc or .bash_profile or .zshrc as per need

bashrc/zshrc
1
source $HOME/.bash_aliases

Open a new terminal and everything should work like a chram :)

Comments