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)
- Add
.bash_aliases
in~
(/home/USER_NAME
)
$ touch ~/.bash_aliases
- Open the file using editor and add
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.
- In terminal
$ source ~/.bash_aliases
- Restart terminal.
For Windows (Git Bash)
-
Run git bash in administrator mode.
-
Navigate to
C:\Program Files\Git\etc\profile.d
.
cd ../../Program\ Files/Git/etc/profile.d/
- Open
aliases.sh
using nano
nano aliases.sh
- Add following in the end:
# 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.
- For saving and exiting nano
CTRL+O
# PRESS ENTER
CTRL+X
- Restart terminal.
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.