Last active
May 7, 2018 07:27
-
-
Save faishal/57e5d9979182d9b5138aa8b7c0df88b5 to your computer and use it in GitHub Desktop.
Git archive branches which are merged in master, Also creates archive/branch-name tag and push to remote.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Run from master to avoid not able to delete current branch error | |
git checkout master --force | |
git submodule update --init --recursive | |
# Update our list of remotes | |
git fetch | |
git remote prune origin | |
# Remove local fully merged branches | |
# git branch --merged master | grep -v 'master$' | xargs git branch -d | |
# Show remote fully merged branches | |
echo "The following remote branches are fully merged and will be archived:" | |
git branch -r --merged master | sed 's/ *origin\///' | grep -v 'master$' | grep -v 'development$' | grep -v 'staging$' | |
read -p "Continue (y/n)? " | |
if [ "$REPLY" == "y" ] | |
then | |
read -p "Do you want to create archive branch (y/n)? " | |
for MERGED_BRANCH in $(git branch -r --merged master | sed 's/ *origin\///' | grep -v 'master$' | grep -v 'development$' | grep -v 'staging$') | |
do | |
if [ "$REPLY" == "y" ] | |
then | |
echo "Creating archive tag for $MERGED_BRANCH..." | |
echo $MERGED_BRANCH | xargs -I% git tag archive/% origin/% | |
fi | |
echo "Deleting remote branch $MERGED_BRANCH" | |
echo $MERGED_BRANCH | xargs -I% git push origin :%s | |
done | |
git push --tags | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment