Last active
May 31, 2021 06:58
-
-
Save jaumef/0b593d0c67d7dbad2dee2db8fc762d82 to your computer and use it in GitHub Desktop.
Clean local branches with PR status via github client
This file contains 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
#!/bin/bash | |
for branch in $(git branch | grep -v master | grep -v '*') | |
do | |
branch_pr_status=$(gh pr view $branch | grep 'state:' | awk '{print $2}') | |
if [[ $branch_pr_status ]] | |
then | |
echo "$branch is $branch_pr_status" | |
if [[ "$branch_pr_status" == "MERGED" ]] | |
then | |
git branch -D $branch | |
elif [[ "$branch_pr_status" == "CLOSED" ]] | |
then | |
git branch -D $branch | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment