Guides · terminal
How to make a shell alias that lasts
By Lalla Asmaa Alaoui, founder of Mel · Updated
Add a line such as alias gs="git status" to ~/.zshrc (zsh, the Mac default) or ~/.bashrc (bash, common on Linux), then open a new tab or run source on the file. An alias typed only at the prompt disappears when you close the window, so the startup file is what makes it last.
Aliases save typing on commands you run many times a day. When you need arguments in the middle of a command, use a small shell function instead. Windows works differently, so it has its own section below.
Mac and Linux (zsh and bash)
- Find out which shell you use.
echo $SHELLIf it ends in zsh, your file is ~/.zshrc. If it ends in bash, use ~/.bashrc on Linux. On a Mac with bash, login windows read ~/.bash_profile, so put your aliases in ~/.bashrc and add source ~/.bashrc to ~/.bash_profile.
- Try the alias in the current window first.
alias gs="git status"
gsThere are no spaces around =. If it works, make it permanent.
- Add it to your startup file. Open the file in any editor, for example
nano ~/.zshrc, and add lines at the end:
alias gs="git status"
alias gl="git log --oneline -20"
alias ll="ls -lah"Or append one line from the terminal. Use >>, never >, which would replace the whole file:
echo 'alias gs="git status"' >> ~/.zshrc- Load the change.
source ~/.zshrcNew tabs and windows load it on their own.
- Check what an alias does.
alias
type gsalias lists all of them. type gs shows what gs runs, which is useful when a name clashes with a real program.
- Use a function when you need arguments. An alias only adds text at the start of a command. For anything more, write a function in the same file:
mkcd() {
mkdir -p "$1" && cd "$1"
}Now mkcd new-project creates the folder and moves into it.
- Remove an alias. Delete its line from the file and open a new tab. For the current window only, run
unalias gs.
- Need it in scripts too? Make a tiny script instead. Aliases and functions only exist in interactive shell windows. Scripts, cron jobs and many tools start a non-interactive shell that never reads
~/.zshrc. A small script in a folder on yourPATHworks everywhere:
mkdir -p ~/bin
printf '#!/bin/sh\nexec git status "$@"\n' > ~/bin/gs
chmod +x ~/bin/gsThen add export PATH="$HOME/bin:$PATH" to your startup file if ~/bin is not on your PATH yet.
fish
fish uses a different format. This creates the alias and saves it:
alias --save gs "git status"fish also has abbreviations, abbr -a gs git status, which expand as you type so you can see the full command.
Windows
- PowerShell. Aliases in PowerShell cannot take arguments, so use a function. Open your profile file:
if (!(Test-Path $PROFILE)) { New-Item -Path $PROFILE -ItemType File -Force }
notepad $PROFILEAdd a line, save, and open a new PowerShell window:
function gs { git status @args }If scripts are blocked on your machine, PowerShell may refuse to load the profile until you allow it with Set-ExecutionPolicy -Scope CurrentUser RemoteSigned.
- Command Prompt. The most reliable way is a tiny script on your
PATH. Create a folder such asC:\Users\you\bin, add it to your userPATHin Windows settings, and save a file namedgs.cmdin it:
@git status %*Now gs works in every new Command Prompt window, and in scripts too. doskey gs=git status $* also works, but only for the window where you type it, and only for commands typed at the prompt.
Doing it with Mel
Mel does not replace your shell; it runs it. On Mac and Linux, each command goes through your own $SHELL. When Mel starts, it loads the environment your login shell sets up, so PATH entries, version managers and variables exported in ~/.zshrc or ~/.bashrc are there even if you opened Mel from the dock or a desktop icon. After you edit your startup file, restart Mel to pick up the change.
Aliases and functions are part of an interactive shell window, not of the environment. If an alias you rely on does not work in a Mel block, turn it into a script on your PATH (step 8).
On Windows, Mel uses cmd.exe, so the .cmd script in step 10 is the one to use there. Restart Mel after you change your PATH.
You can also ask the agent to set one up. Press ctrl+enter (cmd+enter on macOS) and write "make gs a shortcut for git status that works everywhere". With Mel's approvals, each file it wants to write shows on an approval card first, so you can check the exact lines.
FAQ
Why does my alias disappear when I close the terminal? An alias typed at the prompt lasts only for that window. Add it to ~/.zshrc or ~/.bashrc to keep it.
Where do I put aliases on a Mac? Since macOS Catalina the default shell is zsh, so use ~/.zshrc.
How do I make an alias with arguments? Use a shell function instead, for example mkcd() { mkdir -p "$1" && cd "$1"; }.
Why does my alias not work in scripts? Scripts run in a non-interactive shell that does not load ~/.zshrc or ~/.bashrc, so aliases are not there. Use the full command, or turn the alias into a script on your PATH.
How do I make an alias in Windows Command Prompt? Save a small .cmd file such as gs.cmd containing @git status %* in a folder on your PATH.
Mel – the agentic terminal · openmel.dev. A multi-agent, multi-model AI terminal for Mac, Windows, Linux and VS Code. Free with your own API key.

Lalla is a hands-on tech founder, agentic infrastructure architect and the vision behind Mel.
Follow on LinkedIn