How to archive a (document) repo and copy the last commit to a new one. republik/magazine
is used as an example here. For other repos, make sure to also copy the meta
tag in step 4.
mkdir backup
cd backup
git clone --mirror git@github.com:republik/magazine.git
cd ..
git clone git@github.com:republik/magazine.git
cd magazine
Make sure you're on the right branch before running.
ref=$(git symbolic-ref HEAD 2> /dev/null)
b="${ref#refs/heads/}"
c="$(git rev-parse $b)"
echo "Current branch: $b $c"
echo "Recreating $b branch with initial commit $c ..."
git checkout --orphan new-start $c
git commit -C $c
git rebase --onto new-start $c $b
git branch -d new-start
git reflog expire --expire=all
git gc --prune=all
- Rename repo on github
${name}-${yearStart}${monthStart}-${yearEnd}${monthEnd}
- Archiv the renamed repo
${name}-${yearStart}${monthStart}-${yearEnd}${monthEnd}
- Create new repo
${name}
If your repo has a meta
tag, copy it too.
# note tag messages (M) & version (X)
git show publication
git tag -d vX
git tag -d publication
git tag -d prepublication
git tag -a vX # insert message (M)
git tag publication vX
git tag prepublication vX
git push origin vX
git push origin publication
git push origin prepublication