Skip to content

Instantly share code, notes, and snippets.

@jcayzac
Last active August 23, 2024 04:54
Show Gist options
  • Save jcayzac/a7727db5834589fae38a80972d8ea757 to your computer and use it in GitHub Desktop.
Save jcayzac/a7727db5834589fae38a80972d8ea757 to your computer and use it in GitHub Desktop.
Git subcommand for sync'ing a working copy's branches and tags
#!/usr/bin/env bash
set -eu -o pipefail
echo "Pruning local tracking branches that don't exist anymore on the remote…"
git update
echo "Pruning local branches that have been merged…"
echo "Note: top-level branches are considered protected, only branches with a / in their name will be deleted."
git branch --format '%(refname:lstrip=2)' --merged | grep '/' || true | xargs -n 1 git branch -d
echo "Synchronizing tags with remote…"
git tag -l | xargs -n 1 git tag -d && git fetch --tags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment