Created
April 28, 2025 10:04
-
-
Save antony-scott/f69105ec1e56b02cfab861ff048300cf to your computer and use it in GitHub Desktop.
git-prune: remove all remotely deleted branches & get latest master/main
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function git-prune() { | |
# Determine the default branch (main or master) | |
local branch | |
branch=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@') | |
# Fallback if detection fails | |
if [ -z "$branch" ]; then | |
branch="master" | |
fi | |
git checkout "$branch" | |
git fetch -p | |
git pull | |
git branch -vv | awk '/: gone]/{print $1}' | xargs -r git branch -d -f | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment