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 aliascommand but we can simply overcome that byaliascommand 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.
- Add
.bash_aliasesin~(/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.
-
Run git bash in administrator mode.
-
Navigate to
C:\Program Files\Git\etc\profile.d.
cd ../../Program\ Files/Git/etc/profile.d/
- Open
aliases.shusing 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.
Some of the aliases i use are
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'