Yoast / archive

Yoast repository archive
1 stars 1 forks source link

Better archiving #1

Open courajs opened 7 years ago

courajs commented 7 years ago

Hi! Feel free to close & ignore this, but this was one of the things I found while looking for how to archive a github repo, so I thought I'd share what I came up with. My main extra requirement was archiving all branches, not just master.

#!/usr/bin/env bash

if [ ! "$1" -o ! "$2" ]; then
  echo 'archive.sh <repo_name> <repo_remote_path>'
  exit 1
fi

repo_name=$1
remote_path=$2

# add all branches
git remote add $repo_name $remote_path
git fetch $repo_name
git push origin refs/remotes/$repo_name/*:refs/heads/$repo_name-*
git fetch origin

# copy the archivee's master branch into a folder of our master branch
git fetch $repo_name master
git read-tree --prefix=$repo_name -u $repo_name/master
git commit -m "Add $repo_name snapshot to master"
git push origin master

This pushes all branches of the old repository to prefixed branches in the archive repo, as well as snapshotting master in a subfolder on the archive's master. The snapshot makes for easy browsing, while the branches provide a more accurate replica.

omarreiss commented 6 years ago

Hi @courajs I only now found your issue. That's cool! Thanks for sharing! I'll leave this open for others to find.