Skip to content

Instantly share code, notes, and snippets.

@zach-taylor
Created October 29, 2016 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zach-taylor/ce2031693b94d2e6d243b1b3c909adac to your computer and use it in GitHub Desktop.
Save zach-taylor/ce2031693b94d2e6d243b1b3c909adac to your computer and use it in GitHub Desktop.
Rake script to migrate all repos from Bitbucket org to Github org
# gem install bitbucket_rest_api
# gem install octokit
require 'bitbucket_rest_api'
require 'octokit'
task :migrate do
bitbucket = BitBucket.new login: '', password: ''
bitbucket_owner = ''
github = Octokit::Client.new login: '', password: ''
github_org = ''
bitbucket.repos.list do |repo|
next unless repo.owner == bitbucket_owner
if github.repository?("#{github_org}/#{repo.slug}")
puts "#{repo.slug} exists! ================================="
else
github.create_repo(repo.slug, organization: github_org, private: true)
url = "https://bitbucket.org/#{repo.owner}/#{repo.slug}"
system("mkdir #{repo.slug}")
system("git clone --mirror #{url} #{repo.slug}/.git")
Dir.chdir(repo.slug) do
system("git config --bool core.bare false")
system("git remote add gh https://github.com/#{github_org}/#{repo.slug}")
system("git push --all gh")
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment