Improving your workflow with aliases! 🚀
🤔 But what are aliases?
Aliases are a great way to shave off time spent when jumping around the file system via the terminal or working with git. At their core, aliases are custom strings/names (usually short in length) that are set to one or more commands (usually longer in length). You define these custom alias names in a .bash_alias file (more on this later) and then can enter them in the terminal.
You can get really creative when defining aliases to help cut down the amount of time you spend typing long chained commands out. This might seem like a minor improvement but it adds up over time!
🤯 Aliases sound awesome... how can I get started?
I use macOS so that will be the environment I center my steps around. Here are initial steps to get started:
- Open Terminal.
- In Terminal, navigate to your users root directory and create a new .bash_profile file by:
cd ~ touch .bash_profile
You now have the ability to add custom aliases (each on a new line) in the .bash_profile file. Be sure to restart your Terminal application after any updates made to this file. Also, if you're looking for the file in Finder, you need to show all hidden files (hit shift+command+. while in Finder).
💻 What are some useful aliases I can get started with?
alias home='cd $workspace; pwd;'
alias documents='cd $workspace; cd ../Documents/'
alias external='cd $workspace; cd /Volumes/name of external drive'
alias myrepo='cd $workspace; cd myrepo'
alias vs='code .'
alias gf='git fetch --all -p'
alias gpom='git pull origin master'
alias gb='git branch'
alias gl='git gl'
alias grh='git reset --hard'
alias gsl='git stash list'
alias gspop='git stash pop'
❓Alright, I'm convinced and ready to create some aliases for my Terminal workflow... but are there any negatives of using aliases?
This all sounds great and aliases are very convenient, but of course there is a potential negative with aliases and that is you may rely on them and forget what the original commands are. It's helpful to only use aliases on one of your computers if you have the luxury of multiple computers. If not, I personally recommend mixing in the actual commands from time to time so you don't end up in a bind if you need to work on a different machine!
Drop a comment below with any useful aliases that you can think of incorporating into your workflow! 😃
Top comments (2)
Here's my bash_profile, been using it for around 2 years now. :)
Thanks for sharing 😄 you gave me a few ideas of new ones I can mix in to my workflow!