Skip to content

Instantly share code, notes, and snippets.

@joshlevinson
Created June 7, 2016 18:57
Show Gist options
  • Save joshlevinson/a42407a76e40fa42f86a18b208ac5360 to your computer and use it in GitHub Desktop.
Save joshlevinson/a42407a76e40fa42f86a18b208ac5360 to your computer and use it in GitHub Desktop.

Revisions

  1. joshlevinson created this gist Jun 7, 2016.
    33 changes: 33 additions & 0 deletions git-archive.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    #!/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}