Skip to content

Instantly share code, notes, and snippets.

@petrzpav
Created March 22, 2017 08:30
Show Gist options
  • Save petrzpav/fed28b23844fe74f48357cb6d843379a to your computer and use it in GitHub Desktop.
Save petrzpav/fed28b23844fe74f48357cb6d843379a to your computer and use it in GitHub Desktop.
Usefull git aliases
#!/bin/bash
# Usage:
# 1) Download file (e.g. to your $HOME)
# 2) Place the following in your shell configuration file (e.g. ~/.bash_aliases, ~/.bashrc or ~/.zshrc):
# source '$HOME/git_aliases'
# 3) Reload shell configuration
# 4) Enjoy new aliases :-)
function git_diff_inclusive {
local from to
oIFS=$IFS; IFS=.; read from junk to <<< ${1:-HEAD}; IFS=$oIFS
[[ -z $to ]] && to=$from
git diff $from~1..$to $2
}
function git_delete_branch {
git branch -d $1
git push origin :refs/heads/$1
}
function git_delete_tag {
git tag -d $1
git push origin :refs/tags/$1
}
function git_log_since {
git log --decorate --oneline ${1:+$1~1..}
}
function git_upstream {
git branch -u "origin/${1:-$(gcb)}"
}
alias gdi='git_diff_inclusive'
alias gdb='git_delete_branch'
alias gdt='git_delete_tag'
alias gls='git_log_since'
alias gup='git_upstream'
alias gcb='git rev-parse --abbrev-ref HEAD' # git current branch
alias gb='git checkout -b'
alias gd='git diff'
alias gc='git commit'
alias gch='git checkout'
alias gl="git log --oneline --decorate --color --graph"
alias gla="gl --all"
alias gll="git log --all --color --graph --abbrev-commit --pretty=format:'%C(red)%h%Creset%C(yellow)%d%Creset %s %C(green)%cr%C(white dim) %an%Creset'"
alias gpush='git push --all; git push --tags'
alias gpull='git pull --all --tags; git fetch -p; git submodule update --init --recursive'
alias gpullhard='git reset --hard && gpull'
alias guc='git reset --soft HEAD~1' # git uncommit
alias gs='git status && git submodule status'
alias gaas='git add -A; gs'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment