Last active
February 3, 2025 08:50
-
-
Save thejhh/7e505fdc56d08253cdaf7de5f25838db to your computer and use it in GitHub Desktop.
Simple script to archive branches as a git 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
# 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'" | |
} |
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/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