Skip to content

Instantly share code, notes, and snippets.

@sfdcale
Last active December 27, 2019 02:46
Show Gist options
  • Select an option

  • Save sfdcale/ef1c7c2d2e4c709d3db600f86b81524e to your computer and use it in GitHub Desktop.

Select an option

Save sfdcale/ef1c7c2d2e4c709d3db600f86b81524e to your computer and use it in GitHub Desktop.
Script to delete merged branches
#!/bin/bash
git remote prune origin
rm -f branchesToDelete.txt
git branch -r --merged TEST > branchesToDelete.txt
sed -i '.bak' 's/^[ \t]*origin\///g' branchesToDelete.txt
sed -i '.bak' '/master/d; /QA_branch/d; /Production/d; /OSA_Invoices_Payment/d; /TEST/d; /Invoice_One_Time_Payment/d;' ./branchesToDelete.txt
input="branchesToDelete.txt"
while IFS= read -r branchName
do
echo "$branchName"
git push origin --delete $branchName
done < "$input"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment