将所有分支和完整历史从bitbucket移动到github的git存储库的最佳方法是什么?是否有我必须使用的脚本或命令列表?
答案 0 :(得分:399)
这很简单。
1º在GitHub中创建一个新的空存储库(没有自述文件或licesne,您可以在之前添加它们),以下屏幕将显示
2º在 导入代码 选项中,您可以粘贴bitbucket URL的repo和voilà!!
答案 1 :(得分:358)
您可以参考GitHub页面“Duplicating a repository”
它使用:
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
Import Code
feature from GitHub描述的MarMass更容易
请参阅https://github.com/new/import 答案 2 :(得分:124)
如果您在github上找不到“导入代码”按钮,您可以:
url
。它看起来像: Public
或Private
repo Begin Import
<强>更新强> 最近,Github宣布了“Import repositories with large files”
的能力答案 3 :(得分:37)
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
一旦我很高兴GitHub的推动成功,我可以 通过发出以下命令删除旧遥控器:
git remote rm bitbucket
答案 4 :(得分:13)
答案 5 :(得分:4)
我意识到这是一个老问题。几个月前,当我试图做同样的事情时,我发现它,并且给出的答案不知所措。他们似乎都在处理从Bitbucket一次导入到GitHub的一个存储库,无论是通过单点发出的命令,还是通过GitHub导入器。
我从一个名为gitter的GitHub项目中获取代码并对其进行修改以满足我的需求。
您可以分叉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
然后,使用脚本:
# 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
答案 6 :(得分:4)
使用GitHub导入程序导入存储库
如果您在另一个版本控制系统上托管的项目为Mercurial,您可以使用GitHub Importer工具自动将其导入GitHub。
完全导入存储库后,您将收到一封电子邮件。
答案 7 :(得分:1)
如果您要将本地git存储库移至另一个上游,也可以执行以下操作:
获取当前的远程URL:
git remote get-url origin
将显示如下内容: https://bitbucket.com/git/myrepo
设置新的远程存储库:
git remote set-url origin git@github.com:folder / myrepo.git
现在推送当前(开发)分支的内容:
git push --set-upstream起源开发
您现在在新遥控器中具有分支的完整副本。
(可选)返回此本地文件夹的原始git-remote:
git remote set-url origin https://bitbucket.com/git/myrepo
现在您可以从github的另一个文件夹中获得新的git-repository,这样您就有了两个本地文件夹,分别指向不同的遥控器,前一个(bitbucket)和新的都可用。
答案 8 :(得分:1)
brew install jq
转到https://github.com/settings/tokens并创建访问令牌。我们只需要“回购”范围。
将move_me.sh
脚本保存在工作文件夹中,并根据需要编辑文件。
别忘了CHMOD 755
运行! ./move_me.sh
享受您保存的时间。
它将在脚本所在的目录(您的工作目录)中克隆BitBucket存储库。
此脚本不会删除您的BitBucket存储库。
找到下面的"private": true
并将其更改为"private": false
。
Checkout the developer guide,几经修改。
移动愉快。
#!/bin/bash
BB_USERNAME=your_bitbucket_username
BB_PASSWORD=your_bitbucket_password
GH_USERNAME=your_github_username
GH_ACCESS_TOKEN=your_github_access_token
###########################
pagelen=$(curl -s -u $BB_USERNAME:$BB_PASSWORD https://api.bitbucket.org/2.0/repositories/$BB_USERNAME | jq -r '.pagelen')
echo "Total number of pages: $pagelen"
hr () {
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
}
i=1
while [ $i -le $pagelen ]
do
echo
echo "* Processing Page: $i..."
hr
pageval=$(curl -s -u $BB_USERNAME:$BB_PASSWORD https://api.bitbucket.org/2.0/repositories/$BB_USERNAME?page=$i)
next=$(echo $pageval | jq -r '.next')
slugs=($(echo $pageval | jq -r '.values[] | .slug'))
repos=($(echo $pageval | jq -r '.values[] | .links.clone[1].href'))
j=0
for repo in ${repos[@]}
do
echo "$(($j + 1)) = ${repos[$j]}"
slug=${slugs[$j]}
git clone --bare $repo
cd "$slug.git"
echo
echo "* $repo cloned, now creating $slug on github..."
echo
read -r -d '' PAYLOAD <<EOP
{
"name": "$slug",
"description": "$slug - moved from bitbucket",
"homepage": "https://github.com/$slug",
"private": true
}
EOP
curl -H "Authorization: token $GH_ACCESS_TOKEN" --data "$PAYLOAD" \
https://api.github.com/user/repos
echo
echo "* mirroring $repo to github..."
echo
git push --mirror "git@github.com:$GH_USERNAME/$slug.git"
j=$(( $j + 1 ))
hr
cd ..
done
i=$(( $i + 1 ))
done
答案 9 :(得分:0)
以下是移动私有Git存储库的步骤:
第1步:创建Github存储库
首先,在Github.com上创建一个新的私有存储库。保持存储库为空非常重要,例如创建存储库时,请勿选中选项使用自述文件初始化该存储库。
第2步:移动现有内容
接下来,我们需要使用Bitbucket存储库中的内容填充Github存储库:
$ git clone https://USER@bitbucket.org/USER/PROJECT.git
$ cd PROJECT
$ git remote add upstream https://github.com:USER/PROJECT.git
$ git push upstream master
$ git push --tags upstream
步骤3:清理旧存储库
最后,我们需要通过为同一项目提供两个存储库来确保开发人员不会感到困惑。这是删除Bitbucket存储库的方法:
再次检查Github存储库是否包含所有内容
转到旧Bitbucket存储库的Web界面
选择菜单选项设置>删除存储库
将新Github存储库的URL添加为重定向URL
这样,存储库就完全安置在Github的新家中了。让所有开发人员都知道!
答案 10 :(得分:0)
您可以查看:Here bitbucket 到 GitHub 的分步文档
答案 11 :(得分:-1)
最简单的方法:
git remote rename origin repo_bitbucket
git remote add origin https://github.com/abc/repo.git
git push origin master
推送到GitHub成功后,运行以下命令删除旧遥控器:
git remote rm repo_bitbucket