Skip to content

Instantly share code, notes, and snippets.

@ChrisLundquist
Created December 19, 2012 22:12
Show Gist options
  • Save ChrisLundquist/4341033 to your computer and use it in GitHub Desktop.
Save ChrisLundquist/4341033 to your computer and use it in GitHub Desktop.
split apart a monolithic repo into several smaller ones while preserving commit history.
#!/usr/bin/env ruby
BASE_REMOTE_URL = "[email protected]: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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment