Last active
December 16, 2015 20:10
-
-
Save dannyroberts/5490641 to your computer and use it in GitHub Desktop.
My git-related shortcuts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source /usr/local/git/contrib/completion/git-completion.bash | |
alias g="git"; __git_complete g _git | |
alias l="git status" | |
alias d="git diff"; __git_complete d _git_diff | |
alias ds="git diff --cached" | |
alias m="git commit -m " | |
alias am="git commit -am " | |
alias a="git add " | |
alias o-="git checkout --" | |
alias o="git checkout"; __git_complete o _git_checkout | |
alias om="git checkout master" | |
alias ph="git push" | |
alias pl="git pull" | |
alias rh="git reset HEAD" | |
alias mg="git merge"; __git_complete mg _git_merge | |
alias gl="git log"; __git_complete gl _git_log | |
alias gs="git stash" | |
alias gsa="git stash apply" | |
alias b="git branch"; __git_complete b _git_branch | |
function delete-pyc() { | |
find . -name '*.pyc' -delete | |
} | |
function pull-latest-master() { | |
git checkout master; git pull origin master | |
git submodule update --init | |
git submodule foreach --recursive 'if [[ $(pwd) != *"corehq/apps"* ]]; then git checkout master; git pull origin master & fi' | |
until [ -z "$(ps aux | grep '[g]it pull')" ]; do sleep 1; done | |
delete-merged | |
# this is just copy-pasted from delete-merged | |
git submodule foreach --recursive "if [[ $(pwd) != *"corehq/apps"* ]]; then git branch --merged master | grep -v '\*' | xargs -n1 git branch -d; fi" | |
} | |
function update-code() { | |
pull-latest-master | |
delete-pyc | |
} | |
function switch-submodule-branches() { | |
git submodule foreach "git branch | grep $1 && git checkout $1 || exit 0" | |
} | |
alias branch="git branch | grep '^\*' | sed 's/* //'" | |
alias pho='git push origin $(branch)' | |
function force-edit-url { | |
git remote set-url origin $(pho 2>&1 | grep Use | awk '{print $2}') | |
} | |
function delete-merged() { | |
if [ $(branch) = 'master' ] | |
then git branch --merged master | grep -v '\*' | xargs -n1 git branch -d | |
else echo "You are not on branch master" | |
fi | |
} | |
function delete-merged-remote() { | |
git fetch | |
git remote prune origin | |
git branch --remote --merged master | grep -v 'master$' | grep 'origin/' | sed s:origin/:: | xargs -I% git push origin :% | |
} | |
# o that's bad | |
function submodule-branches() { | |
git submodule foreach 'echo $(basename `pwd`) " " `git branch | grep "^\*" | sed "s/* //"`' | grep -v Entering | grep -v master | awk '{ printf("%s\t%s\n", $1, $2) }' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Modified delete-merged that includes submodules: