Skip to content

Instantly share code, notes, and snippets.

@simondch
Last active March 10, 2021 10:09
Show Gist options
  • Save simondch/1613127c91c87d0506ce19317e0d9cfb to your computer and use it in GitHub Desktop.
Save simondch/1613127c91c87d0506ce19317e0d9cfb to your computer and use it in GitHub Desktop.
Git: remove tracking local branches not on remote anymore
#! /bin/bash
git fetch -p && \
for branch in $(git for-each-ref --format '%(refname) %(upstream:track)' refs/heads | \
awk '$2 == "[gone]" {sub("refs/heads/", "", $1); print $1}'); do git branch -D $branch; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment