Skip to content

Instantly share code, notes, and snippets.

@putermancer
Last active June 15, 2022 08:37
Show Gist options
  • Save putermancer/841286 to your computer and use it in GitHub Desktop.
Save putermancer/841286 to your computer and use it in GitHub Desktop.
git aliases
[alias]
man = help
unadd = reset HEAD
#co = checkout
co = "!f(){ git checkout \"$@\" && git sup; }; f"
feature = "!git reset HEAD && git checkout -b feature/\"$1\" && git commit --allow-empty -m \"Created feature branch $1\" && git push --set-upstream origin feature/\"$1\" && echo Branch feature/$1 published to origin"
cp = cherry-pick
sma = submodule add
st = status
br = branch
d = diff
dc = diff --cached
info = "!sh -c '[ $# -ne 0 ] && git remote show $1 && exit 0 || [ $# = 0 ] && git remote show origin && exit 0' -"
track = "!sh -c '[ $# = 2 ] && git branch --track \"$1\" \"$2\" && exit 0 || [ $# = 1 ] && git branch --track \"$1\" origin/\"$1\" && exit 0 || echo \"usage: git track <branch> [remote_branch]\\n\\nIf remote branch is not specified, the default is to use origin/<branch>\" && exit 1' -"
pulls = "!f(){ git pull origin --prune \"$@\" && git submodule update --init; }; f"
pop = stash pop
today = log --stat --since "12am" --reverse
reach = "!~/bin/git-run-for-each-rev"
ab = "!sh -c ' git bisect start $0 $1 && shift; git bisect run $@ '" # example: git ab BAD_REF GOOD_REF "ant testOne -Dtest=VodAsset -Denv.DEVMODE=1"
x = "!gitx"
rm-untracked = !git ls-untracked | xargs rm
release = !git push origin release && git push origin master && git push origin --tags
issues = "!sh -c 'git log --oneline $@ | egrep -o [A-Z]+-[0-9]+ | sort | uniq' -"
recent = "!git for-each-ref --count=5 --sort=-committerdate refs/heads/ --format='%(refname:short)' -"
# The below are courtesy of bobthecow
edit-unmerged = "!f() { git ls-files --unmerged | cut -f2 | sort -u ; }; $EDITOR `f`"
add-unmerged = "!f() { git ls-files --unmerged | cut -f2 | sort -u ; }; git add `f`"
lc = log ORIG_HEAD.. --stat --no-merges
smash = merge --no-commit --log
eat = branch -M # rename OLD_BRANCH to NEW_BRANCH, eating NEW_BRANCH if it already exists
prune-all = !git remote | xargs -n 1 git remote prune
whois = "!sh -c 'git log -i --pretty=\"format:%an <%ae>\" --author=\"$1\" | sort -u' -"
whatis = show -s --pretty='tformat:%h (%s, %ad)' --date=short
this = !git init && ( [[ -n $(ls) ]] || echo ".DS_Store" > .gitignore ) && git add . && git commit -m \"initial commit\"
sp = ![[ -z $(git status --porcelain -uno) ]] && git pull --rebase || git stash && git pull --rebase && git stash pop
spp = ![[ -z $(git status --porcelain -uno) ]] && git pull --rebase || git stash && git pull --rebase && git push && git stash pop
pp = !git pull --rebase && git push
ppu = !git pp && git submodule sync && git submodule update --init
ls = "!git status -suno"
ls-modified = "!git status --porcelain -uno | awk 'match($1, /M/) {print $2}'"
ls-added = "!git status --porcelain -uno | awk 'match($1, /A/) {print $2}'"
ls-deleted = "!git status --porcelain -uno | awk 'match($1, /D/) {print $2}'"
ls-renamed = "!git status --porcelain -uno | awk 'match($1, /R/) {print $2}'"
ls-copied = "!git status --porcelain -uno | awk 'match($1, /C/) {print $2}'"
ls-updated = "!git status --porcelain -uno | awk 'match($1, /U/) {print $2}'"
ls-staged = "!git status --porcelain -uno | grep -P '^[MA]' | awk '{ print $2 }'"
ls-untracked = "!git status --porcelain -uall | awk '$1 == \"??\" {print $2}'"
sup = !git submodule sync && git submodule update --init --recursive
alias = "!sh -c '[ $# = 2 ] && git config --global alias.\"$1\" \"$2\" && exit 0 || [ $# = 1 ] && [ $1 = \"--list\" ] && git config --list | grep \"alias\\.\" | sed \"s/^alias\\.\\([^=]*\\)=\\(.*\\).*/\\1@@@@=>@@@@\\2/\" | sort | column -ts \"@@@@\" && exit 0 || echo \"usage: git alias <new alias> <original command>\\n git alias --list\" >&2 && exit 1' -"
ignore = "!sh -c '([ $# = 2 ] && ([ \"$1\" = \"--local\" ] && echo \"$2\" >> \"./$(git rev-parse --show-cdup)/.git/info/exclude\" || ([ \"$2\" = \"--local\" ] && echo \"$1\" >> \"./$(git rev-parse --show-cdup)/.git/info/exclude\"))) || ([ $# = 1 ] && (([ \"$1\" == \"--list\" ] && git ls-files -i --exclude-standard) || (([ ! -e .gitignore ] && touch .gitignore || echo \"$(cat .gitignore)\" > .gitignore) && echo \"$1\" >> .gitignore))) || echo \"usage: git ignore <file>\\n git ignore --local <file>\\n git ignore --list\" >&2 && exit 1' -"
lol = log --graph --decorate --pretty=oneline --abbrev-commit
lola = log --graph --decorate --pretty=oneline --abbrev-commit --all
peeps = !git log --pretty=format:%aN | sort | uniq -c | sort -rn
graph = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
cloen = clone
@taxilian
Copy link

Worth adding to this gist our PS1 that shows the current branch. Mine is export PS1="[\e[0;32m]\u[\e[m][\e[1;33m]@[\e[m][\e[1;32m]\h[\e[m][\e[0;33m]:[\e[m][\e[1;37m]\w[\e[m] [\e[0;35m]$(git branch 2> /dev/null | grep -e '* ' | sed 's/^..(.*)/{\1} /')$ [\e[m]"

note that this makes the branch name purple... I actually kinda like that. you could play with it, though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment