File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ # Delete all local branches that are merged / deleted branches in remote
4+
5+ # Fetch and prune remote branches
6+ git fetch --prune
7+
8+ # Get the default branch name (either main or master)
9+ default_branch=$( git symbolic-ref --short refs/remotes/origin/HEAD 2> /dev/null | cut -d ' /' -f 2)
10+
11+ # If default_branch is not found, default to main
12+ if [ -z " $default_branch " ]; then
13+ default_branch=" main"
14+ fi
15+
16+ # Delete local branches that are merged into the default branch
17+ git branch --merged origin/" $default_branch " | grep -v " ^\*" | grep -v " ^$default_branch $" | xargs -r git branch -d
18+
19+ # Delete local branches that track deleted remote branches
20+ git branch -vv | grep ' : gone]' | awk ' {print $1}' | grep -v " ^$default_branch $" | xargs -r git branch -D
21+
You can’t perform that action at this time.
0 commit comments