Git Split Repository With Commit History

Andrew Bolster

Data Science Engineering Manager at NTT Application Security and Trustee at Farset Labs

Thesis submitted, Viva cleared (with minor corrections) but this post isn’t about all that…

Simple one; how do you go from one monolithic project repository to multiple respositories without losing all that tasty tasty commit history?

#! /bin/zsh
# Current_Repo username new_repo {list of files/folders you want to keep}
# Copyright (C) 2016 bolster <[email protected]>
# Distributed under terms of the MIT license.

NEWREPO="[email protected]:$2/$3.git"
shift 3
FILTER_ARGS=[email protected]

git filter-branch --index-filter "git rm --cached -qr --ignore-unmatch -- . && git reset -q \$GIT_COMMIT -- $FILTER_ARGS" --prune-empty -- --all && git repack -a -d -f --depth=250 --window=250 && git remote set-url origin $NEWREPO && git gc && git push -u origin master
ls -latrh
rm -rf $TMPDIR

YMMV, IANAGG, No refunds, Safety not guaranteed

(And I’d still like a better way of cleaning up the object history of the new repos… leave a comment if you’ve got a better idea!)

Published: October 17 2016

  • tags:
blog comments powered by Disqus