DEV Community

Cover image for How to Create Aliases on macOS with Terminal
Zahra Khan
Zahra Khan

Posted on • Originally published at blog.zahrakhadijha.com

How to Create Aliases on macOS with Terminal

Aliases are those badass secret identities and mysteries that developers type into their terminal to perform a task faster and make their workflow simpler. For the longest time, I procrastinated creating aliases because the thought of learning how to do it seemed really hard. But actually, it's extremely easy. And its made my life SO MUCH better, so I wanted to share how to do it.

Creating Aliases for Zsh Shell

  • Go to your terminal
  • Type in the command
cd ~
Enter fullscreen mode Exit fullscreen mode

To make sure you are at your root directory,

  • Then type in
open .zshrc
Enter fullscreen mode Exit fullscreen mode

to open up your .zshrc folder. You should see a screen like this:

Screen Shot 2021-12-27 at 1.56.33 AM.png

  • Scroll down to where it says something like # alias ohmyzsh="mate ~/.oh-my-zsh"
  • After the hashes, type in your own alias, i.e.:
alias cmsg="git commit -m"
Enter fullscreen mode Exit fullscreen mode

Every time I want to run git commit -m, I can now use cmsg to do that task.

  • Next Cmd + S to Save. Close the window.
  • THEN for the changes to take affect, you will have to enter the following in your terminal:
source .zshrc
Enter fullscreen mode Exit fullscreen mode

Example Aliases

Alias names can often be hard to come up with for beginners—I know it was for me until I saw a senior engineer using some of them—so some examples would be:

alias project:start="yarn"
alias project:build="yarn project build"
alias project:test="yarn test"

alias project:start="yarn && yarn project build"
alias project="/application/documents/project/project-file"
Enter fullscreen mode Exit fullscreen mode

Voilà You can now use your alias to perform the task you want faster.

If you have any questions, feel free to DM me on Twitter !

Top comments (0)