git pushup
- Pushes a branch and sets the upstream to be the branch of the same name (useful if your git push.default
is simple
):
git config --global alias.pushup \!'git push --set-upstream origin `git symbolic-ref --short HEAD`'
git trim
- Prunes branches which are merged or have been deleted on the remote (never deletes develop or master):
git config --global alias.trim \!'git fetch --prune && git branch --merged | grep -E -v "^((\* )|\s*(develop|master)$)" | xargs git branch -d'
git pullup
- Pulls a branch only if it can be fast forwarded, branch doesn't have to be checked out
git config --global alias.pullup \!'f() { BRANCH=$(git symbolic-ref --short HEAD); if [ $# -eq 0 ] || [[ $BRANCH == $1 ]]; then git pull --ff-only; else git fetch origin $1:$1; fi; }; f'
Others:
pushup = !git push --set-upstream origin `git symbolic-ref --short HEAD`
trim = !git fetch --prune && git branch --merged | grep -E -v \"^((\\* )|\\s*(develop|master|main)$)\" | xargs git branch -d
pullup = "!f() { BRANCH=$(git symbolic-ref --short HEAD); if [ $# -eq 0 ] || [[ $BRANCH == $1 ]]; then git pull --ff-only; else git fetch origin $1:$1; fi; }; f"
restash = "!f() { NAME=$(git stash list | head -n 1 | sed 's/.*\\: //'); git stash pop; git stash save ${@:-$NAME}; }; f"
destash = "!f() { NAME=$(git stash list | grep \": $1$\" | cut -d: -f1); if [[ ! -z $NAME ]]; then git stash apply $NAME; else echo \"Stash not found '$1' \"; git --no-pager stash list; fi; }; f"
rebranch = "!f() { BRANCH=$(git symbolic-ref --short HEAD); if [ $# -eq 0 ] || [[ $BRANCH == $1 ]]; then git reset --hard origin/$BRANCH; else git branch -f $1 origin/$1; fi; }; f"
uncommit = !git reset HEAD~1
cleanup = "!f() { ~/git-cleanup.sh; }; f"