This content originally appeared on DEV Community and was authored by Tony Metzidis
If you're like me your github account is littered with hundreds of legacy experimental repos that you don't want to toss.
git subtree
is the magic needed to consolidate them into an archive, preserving all of the commit history . Once consolidated, all of those legacy repos can be archived to your cloud storage and deleted from github.
Clone the Archive Repo
First step is to choose (or create) your archive repo that will contain all of your experiments
USERNAME=tony
REPO=archive
git clone git@github.com:$USERNAME/$REPO.git
cd $REPO
Clone one or more Experiment Repos (you would like to delete)
USERNAME=tony
REPO=experiment-web
git clone git@github.com:$USERNAME/$REPO.git
Add the local experiment-web as a "remote"
note: Git remotes can be copies from a local directory. This is the magical source of subtree's power to fan-in or fan-out repos
cd archive
name=experiment-web ; git remote add subtree/$name ../$name
Do this any number of times for all of your experiment Repos
Subtree The Repo and Test the Results
# stay within Archive
name=experiment-web
git subtree add -P $name subtree/$name master # or any branch
Test that all the contents match exactly
cd $name
diff -r . ../../$name
# Only in ../../experiment-web: .git
Test that the subtree'd log matches the log of the original repo
git log --graph -4
* a19d970 - (HEAD -> master, tonymet/master) Add 'oh-my-zsh/' from commit '9f3f282699dccc11221debbdbec4be654c63ac83' (11 minutes ago) <tony>
|\
| * 9f3f282 - (subtree/oh-my-zsh-origin/anthony) macbook (14 minutes ago)
Archive and Delete The Repo
Now you can archive the repo to your cloud storage ( Google Cloud , etc).
# Save to TGZ file and copy to your Google Drive
name=experiment-web && tar -zcf archive/$name-`date +%Y-%m-%d`.tgz $name && rm -rf $name
# Visit repo on the web to delete
This content originally appeared on DEV Community and was authored by Tony Metzidis

Tony Metzidis | Sciencx (2025-08-05T00:47:08+00:00) Archive Legacy Github Repos with Subtree. Retrieved from https://www.scien.cx/2025/08/05/archive-legacy-github-repos-with-subtree/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.