default_branch=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')
git checkout $default_branch
git pull
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
Last active
June 7, 2025 11:28
-
-
Save sajaddp/f9704465b0cb0a2c09f5fe53652ec8a4 to your computer and use it in GitHub Desktop.
Git: Remove all local branches that are not on remote
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment