File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : Delete All Merged Branches
2+
3+ on :
4+ workflow_call :
5+
6+ jobs :
7+ delete-merged-branches :
8+ runs-on : ubuntu-24.04
9+ steps :
10+ - name : Checkout repository
11+ uses : actions/checkout@v4
12+ with :
13+ fetch-depth : 0
14+
15+ - name : Delete merged branches
16+ run : |
17+ git config --global user.name "github-actions"
18+ git config --global user.email "github-actions@github.com"
19+ git remote set-url origin "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}"
20+
21+ echo "Fetching all remote branches..."
22+ git fetch --all --prune
23+
24+ echo "Looking for merged branches..."
25+ MERGED_BRANCHES=$(git branch -r --merged origin/main | grep -v 'origin/main' | grep -v 'origin/release/' | sed 's|origin/||')
26+
27+ if [[ -z "$MERGED_BRANCHES" ]]; then
28+ echo "No merged branches found."
29+ exit 0
30+ fi
31+
32+ echo "Merged branches to delete:"
33+ echo "$MERGED_BRANCHES"
34+
35+ for branch in $MERGED_BRANCHES; do
36+ echo "Deleting branch: $branch"
37+ git push origin --delete "$branch"
38+ done
You can’t perform that action at this time.
0 commit comments