Skip to content

Instantly share code, notes, and snippets.

@danielwhite
Last active September 30, 2019 07:19
Show Gist options
  • Save danielwhite/d094e0d8ab0907f681dfc6dcd34f6895 to your computer and use it in GitHub Desktop.
Save danielwhite/d094e0d8ab0907f681dfc6dcd34f6895 to your computer and use it in GitHub Desktop.
Git Tools
#!/bin/bash
set -euo pipefail
#
# Tidies up the remote and local references of a Git repository.
#
# By default, it assumes that origin/master is the mainline branch.
#
GIT_UPSTREAM_REMOTE=${GIT_UPSTREAM_REMOTE:-origin}
GIT_UPSTREAM_HEAD=${GIT_UPSTREAM_HEAD:-master}
git remote update -p
merge_ref="${GIT_UPSTREAM_REMOTE}/${GIT_UPSTREAM_HEAD}"
git branch --format '%(refname:short)' --merged ${merge_ref} \
| xargs git branch -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment