Amsterdam, Netherlands info@code2bits.com On Request

Essential Alias Commands For Developers

This post provides a quick reference to the alias commands that I use on macOS. This is not a complete set of alias commands with detailed explanations on what each command does. If you want to read detailed documentation on the different options and arguments of the alias command, please refer to the online documentation of the alias and associated commmands.

What is the Alias Command?

The alias is a command in various command-line interpreters which enables a replacement of a word by another string. It is mainly used for abbreviating a system command, or for adding default arguments to a regularly used command. ~ Wikipedia

List Defined Aliases

To list all the defined aliases, you can type the following in the terminal console.

# List Defined Aliases
$ alias

Create a Temporary Alias

The alias command can be used to replace an command with another word. The lifetime of the alias command is bounded by the current terminal session. Once you open a new terminal session, the alias command will not be available.

$ alias name=string_value
$ alias name='command'
$ alias name='command arg1 arg2'
$ alias name='/path/to/script'
$ alias name='/path/to/script.pl arg1'

Create a Permanent Alias

Aliases are not permanent across sessions, unless you save them within your user’s shell configuration profile file.

  • Bash – ~/.bashrc
  • ZSH – ~/.zshrc
  • Fish – ~/.config/fish/config.fish

On macOS, your configuration will be in the following file.

  • macOS - ~/.bash_profile

To edit the file, run the following commands:

$ vi ~/.bash_profile

You can now add any of the alias commands to the file, to create a permanent alias configuration. Add the following permanent alias to the .bash_profile file:

alias c='clear'

Save and close the file. After you have made changes to your bash configuration file, you need to run the following command to apply the new configuration to your current session.

$ source ~/.bash_profile

Remove an Alias

To remove a temporary alias, an alias added via the command line, use the unalias command.

# Remove a specific alias
$ unalias [alias_name]

# Remove all aliases
$ unalias -a 

Essential GIT Aliases

Git is a version control system for tracking changes in computer files and coordinating work on those files among multiple people. A large number of commands in git makes for an ideal place to set aliases specific for git commands.

# Git Status Alias
$ alias gs='git status -sb'

# Git Add/Remove Aliases
$ alias ga='git add'
$ alias gr='git rm'

# Git Branch Alias
$ alias gb='git branch -v'

# Git Commit Aliases
$ alias gc='git commit'
$ alias gca='git commit --amend'
$ alias gcm='git commit -m'

# Git Checkout Aliases
$ alias gcod='git checkout develop'
$ alias gcos='git checkout staging'
$ alias gcom='git checkout master'

# Git Fetch Aliases
$ alias gf='git fetch'
$ alias gfa='git fetch --all'

# Git Pull Alias
$ alias gp='git pull --rebase'

# Git Pull (Origin) Aliases
$ alias gprod='git pull --rebase origin develop'
$ alias gpros='git pull --rebase origin staging'
$ alias gprom='git pull --rebase origin master'

# Git Pull (Upstream) Aliases
$ alias gprud='git pull --rebase upstream develop'
$ alias gprus='git pull --rebase upstream staging'
$ alias gprum='git pull --rebase upstream master'

# Git Push (Origin) Aliases
$ alias gpod='git push origin develop'
$ alias gpos='git push origin staging'
$ alias gpom='git push origin master'

# Git Push (Upstream) Aliases
$ alias gpud='git push upstream develop'
$ alias gpus='git push upstream staging'
$ alias gpum='git push upstream master'

# Git Rebase Aliases
$ alias gra='git rebase --abort'
$ alias grc='git rebase --continue'
$ alias grd='git rebase develop'
$ alias gri='git rebase -i'
$ alias grs='git rebase staging'
$ alias grm='git rebase master'

# Git Stash Aliases
$ alias gsl='git stash list'
$ alias gsp='git stash pop'
$ alias gss='git stash save'

# Git Diff/Log Aliases
$ alias gd='git diff --color-words'
$ alias gl='git log --oneline --decorate'
$ alias gslog="git log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all"

Summary

The alias commands listed in this article is by no means a complete set of alias command and only serve as a quick reference to be used by developers.

Follow me on any of the different social media platforms and feel free to leave comments.