Skip to content

Instantly share code, notes, and snippets.

@jost125
Last active November 28, 2025 09:32
Show Gist options
  • Select an option

  • Save jost125/7006654 to your computer and use it in GitHub Desktop.

Select an option

Save jost125/7006654 to your computer and use it in GitHub Desktop.
Checkouts to master and delete all fully merged branches
#!/bin/bash
if [ -z "$1" ]; then
echo "Error: Main branch argument is missing."
echo "Usage: $0 <main-branch>"
exit 1
fi
MAIN_BRANCH="$1"
git checkout "$MAIN_BRANCH"
for b in $(git branch | grep -v "$MAIN_BRANCH"); do git branch -d "$b"; done
git fetch -p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment