Alias command

Alias command

Writing long commands is boring. Essentially shortening the commands or chaining of commands helps. This can be achieved using alias command. Alias command is mainly used for abbreviating a system command, or for adding default arguments to a regularly used command.

Example, instead of writing:

git add .  
git commit -m "COMMIT MESSAGE"
git push

we can write following to achieve the same goals.

gc "COMMIT MESSAGE"  
gp  

In the example, chaining of git commands has been done. Git doesn’t allow chaining using git alias command but we can simply overcome that by alias command shown. Do visit git-scm.com to evaluate what’s best for your use case.

Implementation of alias command can be found in usage section. Some use cases can be found in use case section.

Usage

For GNU/Linux (bash)

$ touch ~/.bash_aliases
alias gc='git add . && git commit -m '
alias gp='git push'

Bear in mind, no spaces between the alias target and alias input commands and single quotes only.

$ source ~/.bash_aliases

For Windows (Git Bash)

 cd ../../Program\ Files/Git/etc/profile.d/
nano aliases.sh
# CUSTOM ALIASES

alias gc='git add . && git commit -m'
alias gp='git push'

Bear in mind, no spaces between the alias target and alias input commands and single quotes only.

CTRL+O 
# PRESS ENTER
CTRL+X 

Use Cases

Some useful aliases can be:

alias update='sudo apt update && sudo apt upgrade'
alias rm='rm -i'
alias gc='git add . && git commit - '
alias gp='git push'
alias gr='git restore --staged'

My bash aliases can be found here.