Last Updated: February 25, 2016
·
632
· destructuring

Work in hardlinked git clones

One of my 500mb git repositories got corrupted and I had to clone from scratch. This time, I cloned to a cache directory. Then I clone again from the cache directory to my real workarea. Takes less than 2 seconds on SSD and hopefully it will save me some time when I want another clone.

Clone the large repo in a cache directory:

git clone git@github.com:destructuring/badonkadonk ~/work/cache/

Created a hardlinked clone, but the straightforward way only fetches one
branch:

git clone ~/work/cache/badonkadonk ~/work/

To fetch all branches, create a mirror and then convert back to a normal
working repository:

cd ~/work/cache
git clone --mirror cache/badonkadonk badonkadonk/.git

Fix up the remotes in the harlinked clone. Deleting the hardlinked
origin takes a while so will just rename it.

cd ~/work/badonkadonk
git remote rename origin hardlinked
git remote add origin git@github.com:destructuring/badonkadonk
git fetch origin

Convert to a working repository and check out a branch:

git config core.bare false
git checkout master
git push -u origin master