Skip to content

Instantly share code, notes, and snippets.

@thejhh
Last active February 3, 2025 08:50
Show Gist options
  • 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
# Origin: https://gist.github.com/thejhh/7e505fdc56d08253cdaf7de5f25838db
# USAGE: .\git-archive.ps1 BRANCH [...BRANCH_N]
$ErrorActionPreference = "Stop"
#$VerbosePreference = "Continue"
$DATE = Get-Date -Format "yyyyMMdd-HHmmss"
foreach ($BRANCH_NAME in $args) {
$ARCHIVE_TAG_NAME = "archive/$DATE-$BRANCH_NAME"
git tag $ARCHIVE_TAG_NAME $BRANCH_NAME
git branch -d $BRANCH_NAME | Out-Null
Write-Output "Archived '$BRANCH_NAME' as '$ARCHIVE_TAG_NAME'"
}
#!/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