public
Last active

split apart a monolithic repo into several smaller ones while preserving commit history.

  • Download Gist
splitter.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#!/usr/bin/env ruby
BASE_REMOTE_URL = "git@github.blueboxgrid.com:chef"
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
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.