What I Wanted to Do

Typing git status or docker-compose up -d in full every time got tedious fast. Adding aliases to .bashrc or .zshrc lets you register short custom commands without installing anything.

Basic Alias Syntax

Add alias definitions to ~/.bashrc (for bash) or ~/.zshrc (for zsh):

# Add to ~/.bashrc or ~/.zshrc
alias gs='git status'
alias gp='git push'
alias ll='ls -la'
alias dc='docker-compose'

Apply the changes without restarting the terminal:

source ~/.bashrc
# or
source ~/.zshrc

Useful Alias Examples

Git Shortcuts

alias gs='git status'
alias ga='git add .'
alias gc='git commit -m'
alias gp='git push'
alias gl='git log --oneline --graph'
alias gd='git diff'

Docker Shortcuts

alias dc='docker-compose'
alias dcu='docker-compose up -d'
alias dcd='docker-compose down'
alias dps='docker ps -a'
alias drm='docker rm $(docker ps -aq)'

General Linux Shortcuts

alias ll='ls -la'
alias la='ls -A'
alias ..='cd ..'
alias ...='cd ../..'
alias grep='grep --color=auto'
alias mkdir='mkdir -pv'

Using Shell Functions for Multi-Step Commands

When a single alias is not enough, define a function instead:

# Create a directory and immediately cd into it
mkcd() {
  mkdir -p "$1" && cd "$1"
}

# Git add + commit + push in one command
gacp() {
  git add .
  git commit -m "$1"
  git push
}

Functions go in the same .bashrc / .zshrc file as aliases.

Check What Aliases Are Defined

# List all current aliases
alias

# Check a specific alias
alias gs

Common Pitfalls

  • Forgetting to run source ~/.bashrc — changes won’t take effect until you reload or open a new terminal
  • Editing .zshrc when your shell is actually bash (check with echo $SHELL)
  • Naming an alias after an existing command silently overrides it (use which dc to check first)
  • alias gc='git commit -m' needs the message as an argument: use it as gc "your message"
  • On some servers the login shell is /bin/sh, so .bashrc may not be loaded automatically

Looking for reliable cloud infrastructure? Check out these developer-friendly services.