Git alias and Bash alias serve different purposes and function differently:
Git alias
- Defines shortcuts for Git commands.
- Configured in Git configuration (~/.gitconfig).
- Used exclusively within git commands.
Syntax:
git config --global alias.s status
Then you can use:
git s # instead of git status
Bash alias
- Defines shortcuts for any shell commands, not just Git.
- Configured in .bashrc or .bash_profile (or .zshrc for Zsh).
- Works in the entire shell, not just in Git.
Syntax:
alias gs='git status'
Then you can use:
gs # instead of git status
Main differences:
Feature | Git alias | Bash alias |
---|---|---|
Scope | Git commands only | Any shell command |
Configuration | ~/.gitconfig | .bashrc, .bash_profile, .zshrc |
Usage | Within git commands | Anywhere in the shell |
When to use which?
- Git alias is better if you want to create shortcuts only for Git commands and you use Git in multiple environments.
- Bash alias is more flexible, as it allows you to combine multiple commands, modify the output or use other tools besides Git.
If you want more advanced aliases with parameters, Git aliases also support ! to execute shell commands:
git config --global alias.last '!git log -1 --stat'
But then it may be more advantageous to use a Bash alias or a script.
My favorite aliases:
#git
git config --global alias.s = 'status -sb'
git config --global alias.c = !git add -A && git commit -m
git config --global alias.p = push
git config --global alias.change = commit --amend
git config --global alias.last = 'log -1 HEAD --stat'
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.unstage 'reset HEAD --'
#bash
alias ..='cd ..'
alias ...='cd ../..'
alias dt='date "+%F %T"'
alias df="df -Tha --total"
alias lf='ls -alF'
alias la='ls -A'
alias ls='ls -CF'
alias lu='du -sh * | sort -h'
alias lt='ls -t -1 -long'
alias lc='find . -type f | wc -l'
alias ld='ls -d */'
alias ll='ls -lAh --color=auto'
alias c="clear"
alias cls="clear;ls;pwd"
alias path='echo -e ${PATH//:/\\n}'
alias h='history'
alias hg='history | grep $1'
alias cron='crontab -l'
alias croned='crontab -e'
alias rm='rm -rfI'
alias bh="cat ~/.bash_history | grep"
alias meminfo='free -m -l -t'
alias psmem='ps auxf | sort -nr -k 4'
alias psmem10='ps auxf | sort -nr -k 4 | head -10'
alias pscpu='ps auxf | sort -nr -k 3'
alias pscpu10='ps auxf | sort -nr -k 3 | head -10'
alias cpuinfo='lscpu'
alias ports='netstat -tulanp'
alias ping='ping -c 5'
alias dfc='df -hPT | column -t'
alias mount='mount |column -t'
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias al="echo ------------Your curent aliases are:------------¡';alias"
alias fh='find . -name '
alias untar='tar -zxvf $1'
alias tar='tar -czvf $1'