如何从bitbucket到github的所有分支移动git存储库?

swa*_*ner 316 github bitbucket

将所有分支和完整历史从bitbucket移动到github的git存储库的最佳方法是什么?是否有脚本或命令列表我必须使用?

Mar*_*ass 404

这很简单.

在GitHub中创建一个新的空存储库(没有自述文件或licesne,您可以在之前添加它们),以下屏幕将显示

在里面导入代码选项你粘贴你的bitbucket URL的repo和voilà!!

单击导入代码

  • 你真的回答了这个问题,因为接受的答案只显示了一个通用的Git相关方法.你的答案更简单! (12认同)
  • 只要您是创建存储库的人并且它是裸露的,这个答案就很好.如果其他人为您创建了存储库(例如创建分支的管理员),那么这不起作用.在这种情况下,接受的答案是可行的方法. (5认同)
  • 对于其他想要使用此方法的人,请在使用此服务之前删除先前存储库主机上的双因素身份验证,否则您将陷入无休止的循环,试图在GitHub中删除新创建的存储库,并且摆脱这种情况的唯一方法是用`/ settings`替换URL末尾的`/ import`来访问设置并将其删除. (4认同)

Von*_*onC 369

您可以参考GitHub页面" 复制存储库 "

它用:

这会给:

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
Run Code Online (Sandbox Code Playgroud)

如前所述在评论由s LS:

  • 如果您想将存储库从Github移动到Bitbucket,这也适用. (3认同)
  • 这个方法给我带来了一个问题(不确定它是否有问题).当我将来自bitbucket的repo镜像到github然后为5个分支时,它在github中显示为"Compare and Pull Request".它没有在github中显示为分支.我能做些什么呢? (2认同)
  • 然后问题和维基呢? (2认同)
  • 我需要使用这个方法来复制一个 repo,因为它包含一个大文件(> 100MB)。GH 不允许在其存储库中包含大文件。在将 repo 推送到 GH 之前,我删除了大文件。但是,除了其他问题,使用 GH 的“[Import repository](https://github.com/new/import)”功能是当时 **_95%_** 的正确选择,如 [another answer] 中所述(/a/26702623/543738)。但是,如果失败,它不会提供有用的错误消息,您必须联系 GH 支持。是 GH 支持让我知道了文件大小限制。 (2认同)

bin*_*iam 125

如果您在github上找不到"导入代码"按钮,您可以:

  1. 直接打开Github Importer并输入url.它看起来像:github importer的屏幕截图
  2. 给它一个名字(或者它会自动导入名字)
  3. 选择PublicPrivate回购
  4. 点击 Begin Import

UPDATE: 近日,Github上宣布的能力," 导入库处理大型文件 "


小智 39

http://www.blackdogfoundry.com/blog/moving-repository-from-bitbucket-to-github/

这帮助我从一个git提供者转移到另一个.最后,所有提交都在目标git中.简单直接.

git remote rename origin bitbucket
git remote add origin https://github.com/edwardaux/Pipelines.git
git push origin master
Run Code Online (Sandbox Code Playgroud)

一旦我对GitHub的推送成功感到高兴,我可以通过发出以下命令删除旧的遥控器:

git remote rm bitbucket
Run Code Online (Sandbox Code Playgroud)

  • 请在答案中包含链接的相关部分,因为它应该能够独立存在. (2认同)

k0p*_*kus 13

我有一个将现有存储库从github导入bitbucket的反向用例.

Bitbucket也提供导入工具.唯一必要的步骤是将URL添加到存储库.

看起来像:

bitbucket导入工具的屏幕截图


rbe*_*amy 5

我意识到这是一个老问题。几个月前我在尝试做同样的事情时发现了它,但对给出的答案感到不知所措。他们似乎都在处理从 Bitbucket 一次一个存储库导入到 GitHub 的问题,要么通过点菜发出的命令,要么通过 GitHub 导入器。

我从一个名为gitter的 GitHub 项目中抓取了代码并对其进行了修改以满足我的需求。

你可以 fork the gist,或者从这里获取代码:

#!/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
Run Code Online (Sandbox Code Playgroud)

然后,使用脚本:

# 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
Run Code Online (Sandbox Code Playgroud)


use*_*ser 5

使用 GitHub 导入器导入存储库

如果您有一个作为 Mercurial 托管在另一个版本控制系统上的项目,您可以使用 GitHub 导入器工具将其自动导入到 GitHub。

  1. 在任意页面的右上角,单击 ,然后单击导入存储库。
  2. 在“您的旧存储库的克隆 URL”下,键入要导入的项目的 URL。
  3. 选择您的用户帐户或拥有仓库的组织,然后在 GitHub 上键入仓库的名称。
  4. 指定新存储库应该是公共的还是私有的。
    • GitHub 上的任何用户都可以看到公共存储库,因此您可以从 GitHub 的协作社区中受益。
    • 公共或私有存储库单选按钮私有存储库仅对存储库所有者以及您选择与之共享的任何协作者可用。
  5. 查看您输入的信息,然后单击开始导入。

完全导入存储库后,您将收到一封电子邮件。

  1. https://help.github.com/categories/importing-your-projects-to-github
  2. https://help.github.com/articles/importing-a-repository-with-github-importer/