Created
October 2, 2013 20:22
-
-
Save favila/6799961 to your computer and use it in GitHub Desktop.
git-archive-branch.sh Replace a git branch with an archived tag.
This file contains hidden or 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/sh | |
| # git-archive-branch.sh | |
| # | |
| BRANCHNAME= | |
| PUSH= | |
| usage() { | |
| cat 1>&2 << EOF | |
| usage: $(filename $0) [-p] [-h] BRANCHNAME | |
| "Archive" a local git branch. | |
| Creates tag archive/BRANCHNAME pointing to the head of the branch, then | |
| deletes the branch. BRANCHNAME must exist in your local repository. | |
| If the option -p is provided, also pushes the tag and the deletion to the | |
| origin repository. | |
| EOF | |
| } | |
| archivebranch() { | |
| git tag archive/$BRANCHNAME $BRANCHNAME && git branch -d $BRANCHNAME | |
| } | |
| pushchanges() { | |
| git push --tags && git push origin :$BRANCHNAME | |
| } | |
| while getopts "ph" OPT; do | |
| case $OPT in | |
| p) PUSH=1;; | |
| h) usage; exit;; | |
| esac | |
| shift $((OPTIND-1)) | |
| done | |
| BRANCHNAME=$1 | |
| if [ -n "$BRANCHNAME" ]; then | |
| archivebranch | |
| else | |
| usage | |
| exit 1 | |
| fi | |
| if [ -n "$PUSH" ]; then | |
| pushchanges | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment