Skip to main content

How to delete a ton (lot) of remote (gitlab) branches

  • Create a text file, call it branches.txt (with branches one per line)
branch1
branch2
branch3

  • Create a shell file, call it delete.sh
#!/bin/bash
while IFS='' read -r line || [[ -n "$line" ]]; do
echo "Deleting branch: $line"
git push origin --delete $line
done < "$1"

  • chmod the file to make it executable
chmod 0700 delete.sh

  • Make sure both of these files are on the repo, meaning it should be on the root directory of your local git repo
  • Run this command, and sit back and relax while the magic happens:-
./delete.sh branches.txt