Speed Up Your Productivity With Alias
I bet after you read this post you will say “I wish I know this earlier!!”
I like to use alias in my terminal as mush as possible because it really speed up my development and increase your productivity. It could shorten your command from 20 characters to 3 characters. Pretty amazing right. Alias also make your terminal can understand your own command. so dont need to remember every command in your head especially the long one.
What is Alias
In layman terms, They’re what domain names are to IP. Nobody wants to remember IP address instead of domain name for example 172.217.0.227
to google.com
The structure of Alias
1alias YOUR_ALIAS_NAME='bash command'
How To Set Up
There are two ways to setup alias in your command. First is type straight away in the console and second is by editing your .bashrc
files.
Type in console
- Open up your console
- Type this command
1 alias glog='git log --oneline'
- Open your git repository and type
1gst
See it simple right. now you don’t need to type extra character git log –oneline every time you want to show logs. There are some problems with this method because it only persist when your console is open and you need to type the alias command every time you start your console which of course you don’t want to do that. Now we go to the second method.
Edit your .bashrc file
This method requires you to edit the bashrc files where the linux will read this files every time console is open.
- Go to your .bashrc files
1sudo nano ~/.bashrc
- Add your alias command at the bottom of the file
1
2# My custom alias
3alias gst='git status'
4alias gpoh='git push origin head'
- Run
source
command for linux to apply the file instantly
1source ~/.bashrc
Now you make your alias persist in your console. No need to worry your alias is missing. haha
My git alias 🛸
I think git was one of the reason why i use alias a lot. I dont want to write long command like changing branch. Can you imagine, the branch name is already long plus git checkout command. PHEW. Maybe you will question me why not use git client like Git Kraken or even vscode built in client. The answer is, for simple git command it might suitable. What if i want to git filter or cherry-pick the commit. I know some git client like Git Kraken offer this features but I still prefer command line over GUI and its faster. It just my personal preference.
Some of my git aliases
1alias gst='git status'
2alias glog='git log --oneline'
3alias gpoh='git push origin HEAD'
4alias ga='git add'
5alias gck='git checkout
These are just some example to give you some idea. You can create the most complicated command that you can think of and alias it with simple short command that you can remember. Its amazing right.
Wrapping Up
Thats all. I hope after you read this you will feel enjoy typing your command.