Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
split apart a monolithic repo into several smaller ones while preserving commit history.
#!/usr/bin/env ruby
folders = ARGV
pwd = Dir.pwd
folders.each do |folder|
name = folder.split("/").last
name = name.gsub("-","_")
clone_command = "git clone chef/ #{name}"
system clone_command
Dir.chdir name
filter_command = "git filter-branch --tag-name-filter cat --prune-empty --subdirectory-filter #{folder.split("/")[1..-1].join("/")} HEAD"
system filter_command
`git reset --hard`
`git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d`
`git reflog expire --expire=now --all`
`git gc --aggressive --prune=now`
`git remote rm origin`
origin_command = "git remote add origin #{BASE_REMOTE_URL}/#{name}.git"
system origin_command
`git push origin master`
Dir.chdir pwd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment