从GitHub分叉到Bitbucket

ent*_*pid 155 git github bitbucket

我正在开发一个基于CakePHP的项目,该项目托管在GitHub上.我的项目正在Bitbucket上托管.他们俩都使用git.基本上我想在我的Bitbucket存储库中创建一个'fork'(我不知道我是否使用了正确的术语,因为我是git的新手)CakePHP,以便能够获得更新无需下载所有CakePHP zip/tar并替换文件夹,然后提交并推送,但可能使用'merge'(?).

谢谢!

Mar*_*ler 140

今天不可能在不同的网站上发送"拉取请求".我在Bitbucket问题跟踪器中添加了一个功能请求:#3288.如果你想追踪这个,我建议你把自己添加为追随者.

但是,您仍然可以将源从GitHub移动到Bitbucket,而无需下载任何zip文件或tarball.你从GitHub克隆并推送到Bitbucket:

$ git clone https://github.com/cakephp/cakephp
$ cd cakephp
$ git push git@bitbucket.org:mg/cakephp.git master
Run Code Online (Sandbox Code Playgroud)

mg/cakephp首先在Bitbucket中创建了一个空的Git存储库.这样你就可以将变换集从GitHub推送/拉到Bitbucket.

  • 这对我很有用,除了我需要在两个命令之间`cd cakephp`.对于非初学者来说很明显,是的,但是初学者可能会想知道为什么它不起作用. (4认同)
  • 然后我们如何从上游拉? (2认同)

ale*_*emb 79

下面的工作流程将github存储库添加为一个新的远程调用sync和bitbucket远程调用origin.它还添加了一个名为github跟踪github存储库的分支和一个名为master跟踪bitbucket存储库的分支.它假设你有一个名为"myrepository"的bitbucket存储库,它是空的.

安装遥控器

# setup local repo
mkdir myrepository
cd myrepository
git init

# add  bitbucket remote as "origin"
git remote add origin ssh://git@bitbucket.org/aleemb/myrepository.git

# add github remote as "sync"
git remote add sync https://github.com/aleemb/laravel.git

# verify remotes
git remote -v
# should show fetch/push for "origin" and "sync" remotes
Run Code Online (Sandbox Code Playgroud)

设置分支

# first pull from github using the "sync" remote
git pull sync

# setup local "github" branch to track "sync" remote's "master" branch
git branch --track github sync/master

# switch to the new branch
git checkout github

# create new master branched out of github branch
git checkout -b master

# push local "master" branch to "origin" remote (bitbucket)
git push -u origin master
Run Code Online (Sandbox Code Playgroud)

现在你应该让本地github分支跟踪github repo的master分支.你应该让本地master分支跟踪bitbucket repo(master默认为分支).

这样可以很容易地对github分支进行拉动,然后将这些更改合并到master分支上(虽然优先选择rebase),然后你可以推动master分支(将它推到bitbucket).

  • 而不是做--set-upstream做:`git fetch`和`git branch --track github sync/master` (3认同)
  • 我认为缺少的是git branch命令之后的`git checkout github`和`git checkout -b master`.你将最终得到那些分支(`git branch -a`):github,master,remotes/origin/master,remotes/sync/master (3认同)

Zub*_*bin 29

如果你想让你的repo保持最新,请使用两个遥控器:Github(upstream)和Bitbucket(origin)如下:

# Clone original CakePHP source code from Github
git clone --mirror https://github.com/cakephp/cakephp
cd cakephp
# Rename remote from `origin` to `upstream`
git remote rename origin upstream
# Add your Bitbucket repo (this is where your code will be pushed)
git remote add origin https://bitbucket/your/repo.git
# Push everything to Bitbucket
git push --mirror origin
Run Code Online (Sandbox Code Playgroud)

从Github获取CakePHP的更新:

git pull upstream master
Run Code Online (Sandbox Code Playgroud)

将代码更改推送到Bitbucket:

git push origin master
Run Code Online (Sandbox Code Playgroud)


shm*_*uli 15

在BitBucket中创建新存储库时,单击右上角的按钮Import repository.输入Clone or download在Github中单击要分叉的存储库时找到的https url .

为您的存储库命名,配置您的隐私设置,然后就可以了!

  • 截至目前,该功能在Bitbucket上标记为"导入存储库". (6认同)
  • 这是克隆,而不是分叉,这是不同的事情。 (3认同)
  • @enorl76 不过,在一般用途方面并不是特别重要。 (2认同)
  • @enorl76 是的,技术上确实如此。但是 fork 是一种保持克隆与原始存储库“连接”的方法,以便从中获取更新并最终推送它。这就是“起源”和“上游”链接的组合发挥基本作用的地方。Github 和 Bitbucket 然后围绕上游构建了所有一组工具,以使 fork 更加高效和友好,例如“推送请求”:) (2认同)

小智 5

我注意到自从 @Martin Geisler 的回答以来,Bitbucket 启用了从 github.com 导入存储库的功能

能够成功将 github.com 上的私有存储库导入到 bitbucket.org 上的私有存储库中

步骤如下:

  1. 单击“创建”按钮并选择“存储库”(“+”>“存储库”)
  2. 现在,无需创建新存储库,而是从弹出的模式的右上角选择导入存储库。
  3. 在导入存储库的新模式中填写 github 存储库的 URL 和身份验证凭据。
  4. 就是这样。一切顺利地从 github 导入到 bitbucket 中。

请注意屏幕截图右上角的导入存储库链接