git 从 GitHub 分叉到 Bitbucket
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8137997/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Forking from GitHub to Bitbucket
提问by entropid
I'm working on a project based on CakePHP, that's hosted on GitHub. My projectis being hosted on Bitbucket. Both of them use git. Basically I'd like to create a ‘fork' (I don't know if I'm using the right terms, since I'm new to git) of CakePHP in my Bitbucket repository, in order to be able to get the updates without the need to download all the CakePHP zip/tar and replace the folder, then commit and push, but maybe with a ‘merge'(?).
我正在开发一个基于CakePHP的项目,该项目托管在GitHub 上。我的项目托管在Bitbucket 上。他们都使用git。基本上,我想在我的 Bitbucket 存储库中创建 CakePHP的“分叉”(我不知道我是否使用了正确的术语,因为我是git 的新手),以便能够获得更新无需下载所有 CakePHP zip/tar 并替换文件夹,然后提交和推送,但可能需要“合并”(?)。
采纳答案by Martin Geisler
It's not possible to send "pull request" across different sites today. I've added a feature request for this in the Bitbucket issue tracker: #3288. I suggest you add yourself as a follower if you want to track this.
今天不可能在不同的站点之间发送“拉取请求”。我在 Bitbucket 问题跟踪器中为此添加了一个功能请求:#3288。如果您想跟踪此内容,我建议您将自己添加为关注者。
However, you can still move the source from GitHub to Bitbucket without having to download any zip files or tarballs. You make a clone from GitHub and push to Bitbucket:
但是,您仍然可以将源代码从 GitHub 移动到 Bitbucket,而无需下载任何 zip 文件或 tarball。您从 GitHub 克隆并推送到 Bitbucket:
$ git clone https://github.com/cakephp/cakephp
$ cd cakephp
$ git push [email protected]:mg/cakephp.git master
I created mg/cakephp
as an empty Git repository in Bitbucket first. That way you can push/pull changesets from GitHub to Bitbucket.
我mg/cakephp
首先在 Bitbucket 中创建了一个空的 Git 存储库。这样你就可以将变更集从 GitHub 推送/拉取到 Bitbucket。
回答by aleemb
The workflow below adds the github repository as a a new remote called sync
and the bitbucket remote as origin
. It also adds a branch called github
to track the github repository and a branch called master
to track the bitbucket repository. It assumes you have a bitbucket repository called "myrepository" which is empty.
下面的工作流程将 github 存储库添加为名为的新远程sync
,并将 bitbucket 远程添加为origin
. 它还添加了一个称为github
跟踪 github 存储库的分支和一个称为master
跟踪 bitbucket 存储库的分支。它假设您有一个名为“myrepository”的 bitbucket 存储库,它是空的。
Setup remotes
设置遥控器
# setup local repo
mkdir myrepository
cd myrepository
git init
# add bitbucket remote as "origin"
git remote add origin ssh://[email protected]/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
Setup branches
设置分支
# 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
Now you should have the local github
branch tracking the github repo's master
branch. And you should have the local master
branch tracking the bitbucket repo (master
branch by default).
现在您应该让本地github
分支跟踪 github 存储库的master
分支。并且您应该让本地master
分支跟踪 bitbucket 存储库(master
默认情况下为分支)。
This makes it easy to do a pull on the github
branch, then merge those changes onto the master
branch (rebase preferred over merge though) and then you can push the master
branch (will push it to bitbucket).
这使得在github
分支上拉动变得容易,然后将这些更改合并到master
分支上(尽管 rebase 优先于合并),然后您可以推送master
分支(将其推送到 bitbucket)。
回答by Zubin
If you want to keep your repo up to date, use two remotes: Github (upstream
) and Bitbucket (origin
) like this:
如果你想让你的仓库保持最新,使用两个遥控器: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
To pull updates to CakePHP from Github:
从 Github 拉取 CakePHP 的更新:
git pull upstream master
To push your code changes to Bitbucket:
将您的代码更改推送到 Bitbucket:
git push origin master
回答by shmuli
When creating a new repository in BitBucket, click the button Import repository
at the top right. Enter the https url found when clicking Clone or download
in Github for the repository you want to fork.
在 BitBucket 中创建新存储库时,单击右上角的按钮Import repository
。输入Clone or download
在 Github 中单击要分叉的存储库时找到的 https url 。
Give your repository a name, configure your privacy settings, and there you go!
为您的存储库命名,配置您的隐私设置,然后就可以了!
回答by de1123bu58nk
I have noticed that since @Martin Geisler 's answer, Bitbucket has enabled a feature to import repositories from github.com
我注意到自从@Martin Geisler 的回答以来,Bitbucket 启用了从 github.com 导入存储库的功能
I was able to successfully import a private repo from github.com into a private repo on bitbucket.org
我能够成功地将一个私有仓库从 github.com 导入到 bitbucket.org 上的私有仓库中
Here are the steps:
以下是步骤:
- Click on the Create button and select Repository ('+' > Repository)
- Now, instead of creating a new repository select a import repository from the top right corner of the modal that pops up.
- fill in your github repo's URL and your authentication credentials on the new modal for importing the repository.
- That's it. Everything imports into bitbucket from github smoothly.
- 单击 Create 按钮并选择 Repository ('+' > Repository)
- 现在,不是创建一个新的存储库,而是从弹出的模式的右上角选择一个导入存储库。
- 在用于导入存储库的新模式上填写您的 github 存储库的 URL 和您的身份验证凭据。
- 就是这样。一切顺利从github导入bitbucket。
Note the import repository link on right top corner of the screenshot
回答by gcb
I'm guessing you just want to easily download the repository with your project... and that you will NOT be contributing the cakePHP, correct?
我猜您只是想轻松地随项目一起下载存储库……而且您不会贡献 cakePHP,对吗?
if so, you just need to add a external reference to your repo.
如果是这样,您只需要为您的存储库添加一个外部引用。
SVN:externals equivalent in GIT?
And later, even if you want to contribute to cakePHP, you can just do so at the original repo just fine.
之后,即使您想为 cakePHP 做出贡献,您也可以在原始 repo 中这样做就好了。