Skip to content

Instantly share code, notes, and snippets.

@joshlevinson
Created June 7, 2016 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshlevinson/a42407a76e40fa42f86a18b208ac5360 to your computer and use it in GitHub Desktop.
Save joshlevinson/a42407a76e40fa42f86a18b208ac5360 to your computer and use it in GitHub Desktop.
Archive git branches
#!/bin/sh -x
# Exit if any error is encountered:
set -o errexit
# git name-rev is fail
# Get the branch name and replace the string from an array of values for instance "feature/" with "archive/"
CURRENT=`git branch | grep '\*' | awk ' {print $2}'`
ARCHIVE=`git branch | grep '\*' | awk ' {print $2}' | sed 's,.*[a-z]/,,g' | sed 's,^,archive/,g'`
#Check if we are on master or develop since we don't want to tag those
if [ $CURRENT = 'master' ]
then
echo 'you are on the master branch so we are done here'
exit
elif [ $CURRENT = 'develop' ]
then
echo 'you are on the develop branch so we are done here'
exit
fi
# Create the tag
git tag ${ARCHIVE}
# Push the tags
git push --tags
# Ensure the origin has the branch in question
git push origin ${CURRENT}
#Switch to master branch
git checkout -f master
# Delete the local and remote branches
git push origin --delete ${CURRENT}
git branch -D ${CURRENT}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment