Skip to content

Instantly share code, notes, and snippets.

@mser-om
Created June 15, 2023 22:57
Show Gist options
  • Select an option

  • Save mser-om/63ff8b638e8c1f09824eadc335d3bbb5 to your computer and use it in GitHub Desktop.

Select an option

Save mser-om/63ff8b638e8c1f09824eadc335d3bbb5 to your computer and use it in GitHub Desktop.
Git Pfetch command
#!/bin/bash
# This command does a git fetch, determines which branches on the remote have been removed, and clear them out of
# your local repository. This is best performed when the `main` or `master` branch is currently checked out.
# Place this file in /usr/local/bin (e.g. /usr/local/bin/git-pfetch) and mark as executable. Then simply use
# it at the command line like you would any other git subcommand: `git pfetch`. Enjoy a cleaner workspace!
git fetch -p && for branch in $(git branch -vv | grep ': gone]' | awk '{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