Skip to content

Instantly share code, notes, and snippets.

@Daij-Djan
Created March 29, 2016 19:54
Show Gist options
  • Save Daij-Djan/4d24fadf62d81a96e6bf5f3d13f60c0c to your computer and use it in GitHub Desktop.
Save Daij-Djan/4d24fadf62d81a96e6bf5f3d13f60c0c to your computer and use it in GitHub Desktop.
#!/bin/bash
# This has to be run from develop (NOTE: if master is your main dev branch, edit the file.)
git checkout develop
# Update our list of remotes
git fetch
git remote prune origin
# Remove local fully merged branches
git branch --merged develop | grep -v 'develop$' | grep -v 'release/' | xargs git branch -d
# Show remote fully merged branches
echo "The following remote branches are fully merged and will be removed:"
git branch -r --merged develop | sed 's/ *origin\///' | grep -v 'develop$' | grep -v 'release/'
read -p "Continue (y/n)? "
if [ "$REPLY" == "y" ]
then
# Remove remote fully merged branches
git branch -r --merged develop | sed 's/ *origin\///' \
| grep -v 'develop$' | grep -v 'release/' | xargs -I% git push origin :%
echo "Done!"
say "Obsolete branches are removed"
fi
echo "Please, tell your teammates to run 'git remote prune origin' command in order to clean their local repository"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment