如何将git仓库与所有分支从bitbucket移动到github?
将所有分支和完整的历史logging从bitbucket移动到github的最佳方式是什么? 有一个脚本或我必须使用的命令列表?
您可以参考GitHub页面“ 复制存储库 ”
它用:
-
git clone --mirror
:克隆每个引用(提交,标记,分支) -
git push --mirror
:推动一切
那会给:
git clone --mirror https://bitbucket.org/exampleuser/repository-to-mirror.git # Make a bare mirrored clone of the repository cd repository-to-mirror.git git remote set-url --push origin https://github.com/exampleuser/mirrored # Set the push location to your mirror git push --mirror
正如LS 在评论中注意到的那样:
- 使用MarMass描述的GitHub中的
Import Code
function更容易。
请参阅https://github.com/new/import - 除非 …你的回购包括一个大文件:问题是,导入工具将失败,没有一个明确的错误信息。 只有GitHub支持才能够诊断发生的事情。
这很简单。
1º在GitHub中创build一个新的空的存储库(没有自述文件或licesne,你可以添加它们),下面的屏幕将会显示
2º内部导入代码选项,你粘贴你的bitbucket URL的回购和voilà!
如果您在github上找不到“导入代码”button,您可以:
- 直接打开Github Importer并input
url
。 它会看起来像: - 给它一个名字(或者它会自动导入名字)
- select
Public
或Private
回购 - 点击
Begin Import
更新:最近,Github宣布能够“ 导入大型文件的存储库 ”
http://www.blackdogfoundry.com/blog/moving-repository-from-bitbucket-to-github/
这帮助我从一个git提供者转移到另一个git提供者。 在最后,所有的提交都在目标git中。 简单而直接。
git remote rename origin bitbucket git remote add origin https://github.com/edwardaux/Pipelines.git git push origin master
一旦我很高兴GitHub的推送成功,我可以通过发出以下命令来删除旧的远程服务器:
git remote rm bitbucket
我有一个从github导入现有仓库到bitbucket的反向用例。
Bitbucket也提供了一个导入工具 。 唯一必要的步骤是将URL添加到存储库。
看起来像:
我意识到这是一个古老的问题。 几个月前,当我试图做同样的事情的时候,我发现了这一点,并且被给出的答案所困扰。 他们似乎一次处理从Bitbucket到GitHub一个存储库的导入,无论是通过单点菜单还是通过GitHub导入程序。
我从一个名为gitter的GitHub项目中获取了代码,并对其进行了修改以满足我的需求。
您可以将要点分开 ,或者从这里获取代码:
#!/usr/bin/env ruby require 'fileutils' # Originally -- Dave Deriso -- deriso@gmail.com # Contributor -- G. Richard Bellamy -- rbellamy@terradatum.com # If you contribute, put your name here! # To get your team ID: # 1. Go to your GitHub profile, select 'Personal Access Tokens', and create an Access token # 2. curl -H "Authorization: token <very-long-access-token>" https://api.github.com/orgs/<org-name>/teams # 3. Find the team name, and grabulate the Team ID # 4. PROFIT! #---------------------------------------------------------------------- #your particulars @access_token = '' @team_id = '' @org = '' #---------------------------------------------------------------------- #the verison of this app @version = "0.2" #---------------------------------------------------------------------- #some global params @create = false @add = false @migrate = false @debug = false @done = false @error = false #---------------------------------------------------------------------- #fancy schmancy color scheme class String; def c(cc); "\e[#{cc}m#{self}\e[0m" end end #200.to_i.times{ |i| print i.to_s.c(i) + " " }; puts @sep = "-".c(90)*95 @sep_pref = ".".c(90)*95 @sep_thick = "+".c(90)*95 #---------------------------------------------------------------------- # greetings def hello puts @sep puts "BitBucket to GitHub migrator -- v.#{@version}".c(95) #puts @sep_thick end def goodbye puts @sep puts "done!".c(95) puts @sep exit end def puts_title(text) puts @sep, "#{text}".c(36), @sep end #---------------------------------------------------------------------- # helper methods def get_options require 'optparse' n_options = 0 show_options = false OptionParser.new do |opts| opts.banner = @sep +"\nUsage: gitter [options]\n".c(36) opts.version = @version opts.on('-n', '--name [name]', String, 'Set the name of the new repo') { |value| @repo_name = value; n_options+=1 } opts.on('-c', '--create', String, 'Create new repo') { @create = true; n_options+=1 } opts.on('-m', '--migrate', String, 'Migrate the repo') { @migrate = true; n_options+=1 } opts.on('-a', '--add', String, 'Add repo to team') { @add = true; n_options+=1 } opts.on('-l', '--language [language]', String, 'Set language of the new repo') { |value| @language = value.strip.downcase; n_options+=1 } opts.on('-d', '--debug', 'Print commands for inspection, doesn\'t actually run them') { @debug = true; n_options+=1 } opts.on_tail('-h', '--help', 'Prints this little guide') { show_options = true; n_options+=1 } @opts = opts end.parse! if show_options || n_options == 0 puts @opts puts "\nExamples:".c(36) puts 'create new repo: ' + "\t\tgitter -c -l javascript -n node_app".c(93) puts 'migrate existing to GitHub: ' + "\tgitter -m -n node_app".c(93) puts 'create repo and migrate to it: ' + "\tgitter -c -m -l javascript -n node_app".c(93) puts 'create repo, migrate to it, and add it to a team: ' + "\tgitter -c -m -a -l javascript -n node_app".c(93) puts "\nNotes:".c(36) puts "Access Token for repo is #{@access_token} - change this on line 13" puts "Team ID for repo is #{@team_id} - change this on line 14" puts "Organization for repo is #{@org} - change this on line 15" puts 'The assumption is that the person running the script has SSH access to BitBucket,' puts 'and GitHub, and that if the current directory contains a directory with the same' puts 'name as the repo to migrated, it will deleted and recreated, or created if it' puts 'doesn\'t exist - the repo to migrate is mirrored locally, and then created on' puts 'GitHub and pushed from that local clone.' puts 'New repos are private by default' puts "Doesn\'t like symbols for language (ex. use \'c\' instead of \'c++\')" puts @sep exit end end #---------------------------------------------------------------------- # git helper methods def gitter_create(repo) if @language %q[curl https://api.github.com/orgs/] + @org + %q[/repos -H "Authorization: token ] + @access_token + %q[" -d '{"name":"] + repo + %q[","private":true,"language":"] + @language + %q["}'] else %q[curl https://api.github.com/orgs/] + @org + %q[/repos -H "Authorization: token ] + @access_token + %q[" -d '{"name":"] + repo + %q[","private":true}'] end end def gitter_add(repo) if @language %q[curl https://api.github.com/teams/] + @team_id + %q[/repos/] + @org + %q[/] + repo + %q[ -H "Accept: application/vnd.github.v3+json" -H "Authorization: token ] + @access_token + %q[" -d '{"permission":"pull","language":"] + @language + %q["}'] else %q[curl https://api.github.com/teams/] + @team_id + %q[/repos/] + @org + %q[/] + repo + %q[ -H "Accept: application/vnd.github.v3+json" -H "Authorization: token ] + @access_token + %q[" -d '{"permission":"pull"}'] end end def git_clone_mirror(bitbucket_origin, path) "git clone --mirror #{bitbucket_origin}" end def git_push_mirror(github_origin, path) "(cd './#{path}' && git push --mirror #{github_origin} && cd ..)" end def show_pwd if @debug Dir.getwd() end end def git_list_origin(path) "(cd './#{path}' && git config remote.origin.url && cd ..)" end # error checks def has_repo File.exist?('.git') end def has_repo_or_error(show_error) @repo_exists = has_repo if !@repo_exists puts 'Error: no .git folder in current directory'.c(91) if show_error @error = true end "has repo: #{@repo_exists}" end def has_repo_name_or_error(show_error) @repo_name_exists = !(defined?(@repo_name)).nil? if !@repo_name_exists puts 'Error: repo name missing (-n your_name_here)'.c(91) if show_error @error = true end end #---------------------------------------------------------------------- # main methods def run(commands) if @debug commands.each { |x| puts(x) } else commands.each { |x| system(x) } end end def set_globals puts_title 'Parameters' @git_bitbucket_origin = "git@bitbucket.org:#{@org}/#{@repo_name}.git" @git_github_origin = "git@github.com:#{@org}/#{@repo_name}.git" puts 'debug: ' + @debug.to_s.c(93) puts 'working in: ' + Dir.pwd.c(93) puts 'create: ' + @create.to_s.c(93) puts 'migrate: ' + @migrate.to_s.c(93) puts 'add: ' + @add.to_s.c(93) puts 'language: ' + @language.to_s.c(93) puts 'repo name: '+ @repo_name.to_s.c(93) puts 'bitbucket: ' + @git_bitbucket_origin.to_s.c(93) puts 'github: ' + @git_github_origin.to_s.c(93) puts 'team_id: ' + @team_id.to_s.c(93) puts 'org: ' + @org.to_s.c(93) end def create_repo puts_title 'Creating' #error checks has_repo_name_or_error(true) goodbye if @error puts @sep commands = [ gitter_create(@repo_name) ] run commands end def add_repo puts_title 'Adding repo to team' #error checks has_repo_name_or_error(true) goodbye if @error puts @sep commands = [ gitter_add(@repo_name) ] run commands end def migrate_repo puts_title "Migrating Repo to #{@repo_provider}" #error checks has_repo_name_or_error(true) goodbye if @error if Dir.exists?("#{@repo_name}.git") puts "#{@repo_name} already exists... recursively deleting." FileUtils.rm_r("#{@repo_name}.git") end path = "#{@repo_name}.git" commands = [ git_clone_mirror(@git_bitbucket_origin, path), git_list_origin(path), git_push_mirror(@git_github_origin, path) ] run commands end #---------------------------------------------------------------------- #sequence control hello get_options #do stuff set_globals create_repo if @create migrate_repo if @migrate add_repo if @add #peace out goodbye
然后,使用脚本:
# create a list of repos foo bar baz # execute the script, iterating over your list while read p; do ./bitbucket-to-github.rb -a -n $p; done<repos # good nuff
有导入与GitHub导入器的存储库
如果您有一个项目作为Mercurial在另一个版本控制系统上托pipe,则可以使用GitHub导入器工具将其自动导入到GitHub。
- 在任何页面的右上angular,单击,然后单击导入存储库。
- 在“您的旧版本库的克隆URL”下,input您要导入的项目的URL。
- select您的用户帐户或组织来拥有存储库,然后在GitHub上input存储库的名称。
- 指定新的存储库是公共还是私人。
- GitHub上的任何用户都可以看到公共存储库,所以您可以从GitHub的合作社区中受益。
- 公共或私有存储库单选button私有存储库仅供存储库所有者以及您select与之共享的任何协作者使用。
- 查看您input的信息,然后点击开始导入。
当储存库完全导入时,您会收到一封电子邮件。
最简单的方法
git远程重命名repo_bitbucket
git远程添加源https://github.com/abc/repo.git
git推送起源大师
一旦推到GitHub成功,通过删除旧的远程
git remote rm repo_bitbucket