Skip to content

Instantly share code, notes, and snippets.

@DevWouter
Forked from peterjwest/git-cleanup.sh
Last active July 2, 2020 11:08
Show Gist options
  • Save DevWouter/84641b3c4e2e5eb560e614f4331760d6 to your computer and use it in GitHub Desktop.
Save DevWouter/84641b3c4e2e5eb560e614f4331760d6 to your computer and use it in GitHub Desktop.
Git aliases

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):

On Linux:

git config --global alias.pushup \!'git push --set-upstream origin `git symbolic-ref --short HEAD`'

On Windows:

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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment