Skip to content

Instantly share code, notes, and snippets.

@thejhh
Last active March 29, 2021 09:15
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 thejhh/7e505fdc56d08253cdaf7de5f25838db to your computer and use it in GitHub Desktop.
Save thejhh/7e505fdc56d08253cdaf7de5f25838db to your computer and use it in GitHub Desktop.
Simple script to archive branches as a git tag
#!/bin/bash
# Origin: https://gist.github.com/thejhh/7e505fdc56d08253cdaf7de5f25838db
# USAGE: git-archive BRANCH [...BRANCH_N]
set -e
#set -x
DATE="$(date '+%Y%m%d-%H%M%S')"
BRANCH_NAME=$1
for BRANCH_NAME in "$@"; do
ARCHIVE_TAG_NAME="archive/$DATE-$BRANCH_NAME"
git tag "$ARCHIVE_TAG_NAME" "$BRANCH_NAME"
git branch -d "$BRANCH_NAME" > /dev/null
echo "Archived '$BRANCH_NAME' as '$ARCHIVE_TAG_NAME'"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment