Skip to content

Instantly share code, notes, and snippets.

@jaumef
Last active May 31, 2021 06:58
Show Gist options
  • Save jaumef/0b593d0c67d7dbad2dee2db8fc762d82 to your computer and use it in GitHub Desktop.
Save jaumef/0b593d0c67d7dbad2dee2db8fc762d82 to your computer and use it in GitHub Desktop.
Clean local branches with PR status via github client
#!/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