Skip to content

Instantly share code, notes, and snippets.

@jplagostena
Created October 5, 2016 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jplagostena/c05c0a2646270e936e84bdc6dd4650a7 to your computer and use it in GitHub Desktop.
Save jplagostena/c05c0a2646270e936e84bdc6dd4650a7 to your computer and use it in GitHub Desktop.
Pequeño script para limpiar branches ya mergeados y referencias que ya no existen
#!/usr/bin/env bash
BRANCHES_TO_FILTER="master|development"
MERGED_BRANCHES=$(git branch --merged | egrep -v "(^\*|$BRANCHES_TO_FILTER)")
if [ "$MERGED_BRANCHES" == "" ]; then
echo "No hay branches sin mergear"
exit 0
fi
echo -e "Se eliminaran los siguientes branches.\n\n$MERGED_BRANCHES\n\nEstá seguro? "
read -n 1 -r REPLY
echo ""
if [[ $REPLY =~ ^[Ss]$ ]]; then
echo "Eliminando branches localmente"
echo $MERGED_BRANCHES | xargs git branch -d
echo "Eliminando branches remotos"
echo $MERGED_BRANCHES | xargs git push --delete origin
echo "Limpiando referencias que ya no existen en origin"
git remote prune origin
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment