Every developer should have these git aliases!

Sunday, April 12th 2020 1 min read git

  1. Amend last commit, without editing commit message:
amend = !git add -A && git commit --amend --no-edit
  1. Sync and rebase with remote:
f = !git fetch --all && git rebase origin/master
  1. Compact status:
st = !git status -sb
  1. Pretty git logs (single line):
ls = !git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit

pretty log using `git ls`
pretty log using `git ls`

  1. Remove merged branches (needs grep and xargs):
rmb = !git branch --merged | grep -v '*' | xargs -n 1 git branch -d
  1. Push annotated tags simultaneously to master:
gpt = !git push origin master --follow-tags

At the end, some general purpose ones:

alias gac="git add . && git commit -m"
alias gi="git init"
alias gb="git branch"
alias gc="git checkout"
alias gcb="git checkout -b"
alias gra="git remote add"
alias gpm="git push origin master"
alias gsu="git stash -u -k"
alias undo="reset --soft HEAD^"