【问题标题】:Forking from GitHub to Bitbucket从 GitHub 分叉到 Bitbucket
【发布时间】:2011-12-29 14:16:33
【问题描述】:

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

【问题讨论】:

标签: git github bitbucket


【解决方案1】:

目前无法跨不同站点发送“拉取请求”。我在 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

我首先在 Bitbucket 中创建了 mg/cakephp 作为一个空的 Git 存储库。这样您就可以将变更集从 GitHub 推送/拉取到 Bitbucket。

【讨论】:

  • 那我们如何从上游拉取呢?
  • @RuchirShukla:基本上一样。您必须通过从上游拉动来通过您自己的机器移动提交。然后将其推送到另一个托管站点,从而使两者同步。
  • 这对我很有用,除了我需要在两个命令之间使用cd cakephp。对非初学者来说很明显,是的,但初学者可能想知道为什么它不起作用。
  • 你能制作一个 youtube 视频来演示吗?我无法复制它。我能够执行这些指令,但是当我推送和提交时,它仍然试图将其推送到主分支而不是分叉分支。
  • 这不适用于fork。分支和标签不会复制到 BitBucket。
【解决方案2】:

以下工作流程将 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

设置分支

# 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

现在您应该让本地 github 分支跟踪 github 存储库的 master 分支。并且您应该让本地 master 分支跟踪 bitbucket 存储库(默认为 master 分支)。

这使得拉动github 分支变得很容易,然后将这些更改合并到master 分支(尽管rebase 优先于合并),然后您可以推送master 分支(将其推送到位桶)。

【讨论】:

  • 这似乎不起作用,但这是个好主意。无论如何要修复它以使其正常工作?
  • 本地github分支跟踪远程github master分支,然后你推送到远程bitbucket master?什么时候推送到 github? @aleemb
  • 在 Git 2.2.1 中 --set-upstream 已被弃用...但只要您在尝试设置上游存储库之前创建 github 分支,这确实有效。
  • 不做 --set-upstream 做:git fetchgit branch --track github sync/master
  • 我认为缺少的是 git branch 命令之后的git checkout githubgit checkout -b master。你最终会得到这些分支 (git branch -a): github, master, remotes/origin/master, remotes/sync/master
【解决方案3】:

如果您想使您的 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

从 Github 拉取 CakePHP 的更新:

git pull upstream master

要将您的代码更改推送到 Bitbucket:

git push origin master

【讨论】:

  • 我认为您的意思是在第一个 git 命令中使用 `git clone mybitibucket/cakephp/cakephp`,对吧?这是要走的路……
  • 这太棒了!万分感谢!非常感谢
  • 这也行不通。 Bitbucket 中不包含分支和标签。
  • @JoelKarunungan 好点!要推送所有内容,包括分支和标签,我认为这应该可行:git push --all --mirror origin。答案已更新。
  • @Zubin 你试过这个吗? fatal: --all and --mirror are incompatible 另外:git pull upstream master 引发致命错误。 fatal: Couldn't find remote ref master
【解决方案4】:

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

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

【讨论】:

  • 这是克隆,而不是分叉,这是不同的东西。
  • 截至目前,该功能在 Bitbucket 上被标记为“导入存储库”。
  • @entropid a fork 是原始 repo 的克隆。在 git 世界中,Forking == 克隆
  • @enorl76 但在一般用途方面并非特别如此。
  • @enorl76 从技术上讲是的。但是 fork 是一种保持克隆“连接”到原始存储库的方法,以便从中获取更新并最终推送它。这就是“起源”和“上游”链接的组合发挥基本作用的地方。 Github 和 Bitbucket 然后围绕上游构建了所有工具集,以使 fork 更加高效和友好,例如“推送请求”:)
【解决方案5】:

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

能够成功地将 github.com 上的私有仓库导入 bitbucket.org 上的私有仓库

以下是步骤

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

Note the import repository link on right top corner of the screenshot

【讨论】:

    【解决方案6】:

    我猜你只是想轻松地下载你的项目的存储库......而且你不会贡献 cakePHP,对吗?

    如果是这样,您只需要为您的存储库添加一个外部引用。

    SVN:externals equivalent in GIT?

    以后,即使您想为 cakePHP 做出贡献,您也可以在原始 repo 中这样做。

    【讨论】:

      猜你喜欢
      • 2011-06-02
      • 2023-04-02
      • 2015-07-21
      • 2011-12-07
      • 2013-12-31
      • 1970-01-01
      • 2018-12-01
      • 2012-03-02
      • 1970-01-01
      相关资源
      最近更新 更多