Skip to content

Instantly share code, notes, and snippets.

@OmegaRelay
Created January 26, 2026 09:42
Show Gist options
  • Select an option

  • Save OmegaRelay/b7344ab729424bc3244256fdcf290f32 to your computer and use it in GitHub Desktop.

Select an option

Save OmegaRelay/b7344ab729424bc3244256fdcf290f32 to your computer and use it in GitHub Desktop.
Prunes local branches no longer in the remote
#!/bin/bash
# Prunes local branches no longer in the remote
echo -e "git fetch -p"
git fetch -p
echo -e "git remote prune origin"
git remote prune origin
for branch in $(git for-each-ref --format '%(refname) %(upstream:track)' refs/heads | awk '$2 == "[gone]" {sub("refs/heads/", "", $1); print $1}'); do
echo -e "git branch -D \"$branch\""
git branch -D "$branch"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment