Skip to content

Instantly share code, notes, and snippets.

@youpy
Created November 30, 2012 05:57
Show Gist options
  • Save youpy/4173999 to your computer and use it in GitHub Desktop.
Save youpy/4173999 to your computer and use it in GitHub Desktop.
consolidate two git repos
#!/usr/bin/env ruby
# -*- coding: utf-8; ruby -*-
# http://d.hatena.ne.jp/okinaka/20111010/1318211550
require 'shellwords'
def main
old = File.expand_path(ARGV[0])
new = File.expand_path(ARGV[1])
branch_name = Time.now.to_i.to_s
Dir.chdir(old) do
git('fetch %s refs/heads/master:refs/heads/%s' % [Shellwords.escape(new), branch_name])
git('checkout %s' % branch_name)
git('rebase master')
git('checkout master')
git('merge %s' % branch_name)
git('branch -d %s' % branch_name)
end
end
def git(cmd)
cmd = 'git ' + cmd
puts cmd
system cmd
end
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment