Skip to content

Instantly share code, notes, and snippets.

@eneko
Last active April 2, 2025 16:11
Show Gist options
  • Select an option

  • Save eneko/ebaf7e04eb898391afff5371c70887d1 to your computer and use it in GitHub Desktop.

Select an option

Save eneko/ebaf7e04eb898391afff5371c70887d1 to your computer and use it in GitHub Desktop.
`git purge` command to delete local branches that have been deleted on remote
#!/usr/bin/env sh
set -e
echo "Pulling latest code..."
git pull
echo "Deleting local branches that were removed in remote..."
git fetch -p
git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -D
echo "Remaining local branches:"
git branch -vv
echo "Done."
@eneko
Copy link
Copy Markdown
Author

eneko commented Mar 30, 2017

Git command to delete local branches that where tracking a remote branch which has been deleted from remote.

Installation

  1. Save the file (with no extension) in a folder in your path (~/bin, /usr/local/bin, etc.)
  2. Make the file executable: $ chmod 755 git-purge

Usage

Within your repository type:

$ git purge

@bwbohl
Copy link
Copy Markdown

bwbohl commented Apr 2, 2025

nice, many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment