Create alias

2 snippets across 2 stacks - Bash & Linux, Git

SHBash & Linux

Create Command Aliases

SH · Shortcuts & Productivity
Syntax
alias name='command'
unalias name
Example
alias ll='ls -lah'
alias gs='git status'
alias dc='docker compose'
alias k='kubectl'
alias myip='curl -s ifconfig.me'

Note Aliases defined in the terminal are lost when the shell exits. Add them to ~/.bashrc or ~/.zshrc to make them permanent. Run alias with no arguments to list all current aliases. Use unalias to remove one.

GitGit

Create Aliases

Git · Setup & Config
Syntax
git config --global alias.<shortcut> '<command>'
Example
git config --global alias.co 'checkout'
git config --global alias.br 'branch'
git config --global alias.lg 'log --oneline --graph --all'

# Now use:
git co main
git lg

Note Aliases are stored in ~/.gitconfig. You can also edit that file directly under the [alias] section for complex aliases.

Frequently asked questions

How do you create alias?
This task is covered in 2 stacks on this page: Bash & Linux, Git. The "Create Command Aliases" snippet in Bash & Linux uses `alias name='command'`.
Which command does the Bash & Linux example use?
The "Create Command Aliases" snippet uses `alias name='command'`, from the Shortcuts & Productivity section of the Bash & Linux cheat sheet.
Which stacks cover "create alias" on this page?
Bash & Linux, Git. Together they hold 2 copy-ready snippets for this task.
Is there anything to watch out for?
Yes. For "Create Command Aliases": Aliases defined in the terminal are lost when the shell exits. Add them to ~/.bashrc or ~/.zshrc to make them permanent. Run alias with no arguments to list all current aliases. Use unalias to remove one.