Easy workflow with Aliases
If you are tired of repeating commands on the terminal, this is a good place for you. When you work with the linux command line and especially with tools like git, repetitive commands can get tiring. Using aliases is a sleek way out.
Aliases are short defined commands that represent a string of valid bash commands. Instead of having to type commands like
$ pg_restore --verbose --clean --no-acl --no-owner -h localhost …
you can just replace it with any easy short command like
$ restore_db
.
This is how you do that;
If you are on windows, you might have to do this from your gitbash terminal or any other bash terminal available to you. For linux supported users, you can simply open your terminal and follow along.
- On your terminal, check the contents of your bash_profile file
$ cat ~/.bash_profile
to see if you have the file or contents in it already. You have to create the file if you do not have it.
- Open or create
~/.bash_profile
from any code editor of your choice. - Add the following lines of code, these will create git aliases:
alias ga=’git add’alias gp=’git push’alias gl=’git log’alias gs=’git status’alias gd=’git diff’alias gdc=’git diff — cached’alias gcm=’git commit -m’alias gma=’git commit -am’alias gb=’git branch’alias gco=’git checkout’alias gra=’git remote add’alias grr=’git remote rm’alias gpu=’git pull’alias gcl=’git clone’
- Save the file and come back to your terminal.
- You have to do
$ source ~/.bash_profile
. This will make the new changes available as commands in your current terminal. - Start using your fancy aliases. For example, type
$ gs
from a git repo, you will get your git status.
What this means is that instead of typing the full $ git add …
you can just do $ ga …
.You can add as many aliases as you require for commands you frequently run on the bash terminal. For example, I use ruby and have this set up for commands requiring $ bundle exec
;
alias be=‘bundle exec’
So I can do things like $ be rake db:migrate
.
Enjoy.
I hope this helps you and make your work easier. I will appreciate your feedback, and if you remember to give a thumbs up or a clap, that will be great also.