Skip to content

Instantly share code, notes, and snippets.

@adrian-enspired
Created September 30, 2020 13:30
Show Gist options
  • Save adrian-enspired/605d27d5c2d5ccc1031a67a173f8b0bb to your computer and use it in GitHub Desktop.
Save adrian-enspired/605d27d5c2d5ccc1031a67a173f8b0bb to your computer and use it in GitHub Desktop.
Various useful git aliases
# general shortcuts
###################
# status
s = status
# update working tree
u = add -u
# commit
c = commit -S
# push to working remote
a = push adrian
# force push to working remote
af = push -f adrian
# push origin
o = push origin
# force push to origin
oof = push -f origin
# switch to master and pull origin
mp = "!git checkout master && git pull origin master"
# rebase the working branch on origin/master
mr = "!f() { BRANCH=$(git rev-parse --abbrev-ref HEAD); git master-pull; git checkout ${BRANCH}; git rebase master; }; f"
# list branches in order last worked on (asc)
b = !"git for-each-ref --sort='authordate:iso8601' --format=' %(color:green)%(authordate:iso8601)%09%(color:white)%(refname:short)' refs/heads"
# delete all merged branches
bd = "!f() { git branch --merged ${1-master} | grep -v " ${1-master}$" | xargs -r git branch -d; git branch --merged ${1-master} | grep -v " ${1-master>
# search branch names
bg = "!f() { git branch | grep -i ${1}; }; f"
# managing jira
###############
# create a new branch for a given jira issue.
# - $1 jira issue key
# - $2 branch name
jc = "!f() { git master-pull && git checkout -b ${2}.${1} master && git jira-transition in-progress; }; f"
# same as jc but assumes MAD- issue prefix.
# - $1 mad issue number
# - $2 branch name
mc = "!f() { git master-pull && git checkout -b ${2}.MAD-${1} master && git jira-transition in-progress; }; f"
# checkout an existing branch by MAD number.
# (as it happens, $1 can be anything unique. this function fails if there's more than one match.)
# - $1 mad issue number
mad = "!f() { BRANCH=$(git for-each-ref --sort='authordate:iso8601' --format='%(refname:short)' refs/heads | grep $1); git checkout $BRANCH; }; f"
# opens a PR and transitions associated jira issue to review.
jp = "!f() { hub pull-request; git jira-transition in-review; }; f"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment