git 你如何在 GitHub 上 fork 自己的仓库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10963878/
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
How do you fork your own repository on GitHub?
提问by WowBow
I have a public repository on GitHub. I want to replicate/copy it and work on a new project based on this repository, but I don't want to affect how it is now. I tried forking it using the GitHub UI but it didn't do anything.
我在 GitHub 上有一个公共存储库。我想复制/复制它并在基于此存储库的新项目上工作,但我不想影响它现在的状态。我尝试使用 GitHub UI 对它进行分叉,但它没有做任何事情。
回答by VonC
I don't think you can fork your own repo.
Clone it and push it to a new repo is good but you need to:
我不认为你可以分叉你自己的回购。
克隆它并将其推送到新的存储库很好,但您需要:
git clone https://github.com/userName/Repo New_Repo
cd New_Repo
git remote set-url origin https://github.com/userName/New_Repo
git remote add upstream https://github.com/userName/Repo
git push origin master
git push --all
(see git push
)
(见git push
)
See the all process described at "Fork your own project on GitHub".
请参阅“在 GitHub 上分叉您自己的项目”中描述的所有过程。
Six years later (2016), you now have the GitHub importerwhich allows you to import a repo from another source... including GitHub.
See "Importing a repository with GitHub Importer"
六年后(2016 年),您现在拥有GitHub 导入器,它允许您从其他来源导入存储库……包括 GitHub。
请参阅“使用 GitHub 导入器导入存储库”
narf's answer(upvoted) also illustrate that process.
That will allow you to create a new repository and import the full history of the old one into the new one, using its GitHub url.
这将允许您创建一个新存储库并使用其 GitHub url 将旧存储库的完整历史记录导入到新存储库中。
Again: what you get is a copy, not a real fork: you cannot make pull request from the new repo to the old one.
再说一遍:你得到的是一份副本,而不是一个真正的分叉:你不能从新的 repo 到旧的 repo 发出拉取请求。
Again (bis), as stated in the commentsby mpersico
, this is nota TRUE FORK.
再次(之二),如所述的评价通过mpersico
,这是不一个TRUE FORK。
If I have a foo which is the canonical source repo for an open source project that I want other people to fork and have access to do PR, then I do not want to work in that repo, I want a fork I can use to issue proper PRs against my project.
I have solved this my creating a second account in GitHub and forking to that.
如果我有一个 foo,它是一个开源项目的规范源代码仓库,我希望其他人对其进行分叉并有权进行 PR,那么我不想在该仓库中工作,我想要一个可以用来发布的分叉针对我的项目的适当 PR。
我已经解决了这个问题,我在 GitHub 中创建了第二个帐户并分叉到那个帐户。
回答by narF
A super easy way to do it in 30 seconds from the GitHub website:
从 GitHub 网站 30 秒内完成的超级简单方法:
- Copy your repo's URL. Ex:
https://github.com/YourName/YourOldRepo
(hint: it's the URL when you look at your repo's main page on github. - Click the
+
icon in the top right corner. - Select "Import repository".
- Where it asks for the "Old URL", paste the URL you copied at step #1
- Enter the name of your new repo and click
Begin Import
. - That's it! You now have a copy of the full repo, with all commit history and branches!
- 复制您的存储库的 URL。例如:(
https://github.com/YourName/YourOldRepo
提示:这是您在 github 上查看 repo 主页时的 URL。 - 单击右上角的
+
图标。 - 选择“导入存储库”。
- 在它要求“旧 URL”的地方,粘贴您在第 1 步中复制的 URL
- 输入新存储库的名称,然后单击
Begin Import
。 - 就是这样!您现在拥有一份完整的 repo 副本,其中包含所有提交历史记录和分支!
Limitations: It's not actually a real fork. It's a copy of the repo. It won't allow to do pull requests back and forth.
限制:它实际上不是一个真正的分叉。这是回购的副本。它不允许来回执行拉取请求。
回答by shekar
- git clone https://github.com/YOURREPO.gitTargetRepoName
- cd TargetRepoName/
- git remote set-url origin https://github.com/TargetRepoName.git
- git push -u origin master
- git clone https://github.com/YOURREPO.gitTargetRepoName
- cd 目标仓库名称/
- git remote set-url origin https://github.com/TargetRepoName.git
- git push -u origin master
回答by mcepl
Just clone it, create new blank repo, and push to it.
只需克隆它,创建新的空白存储库,然后推送到它。
回答by Nabil_H
Simplest way to achieve the desired effect is to create a new repository, then select the import option and supply the URL of the repo you wish to fork.
达到预期效果的最简单方法是创建一个新的存储库,然后选择导入选项并提供您要分叉的存储库的 URL。
Images below will help:
下面的图片会有所帮助:
回答by Zuzu Softman
For non tech savvy using GitHub, here is one simple solution as an alternative to other great answers above. What you need is just a GitHub Desktop application.
对于使用 GitHub 的非技术专家,这里有一个简单的解决方案,作为上述其他优秀答案的替代方案。您只需要一个 GitHub 桌面应用程序。
- Open your own project repo from browser, and download as a zip, eg
your-project-master.zip
. - Unzip and rename it as your new repo.
- Open GitHub Desktop, and add your new repo by browsing it to your unzipped local path new repo.
- Publish it to your github, by clicking the publish button. Don't forget to add the name and the description :)
回答by Nick
The accepted solution of VonC, unfortunately, did not work for me as I got
不幸的是,接受的 VonC 解决方案对我不起作用
remote: Repository not found
远程:未找到存储库
What did work was the following:
什么起作用了:
- Create a new_repo at github
- git clone new_repo
- cd new_repo
- git remote add upstream old_repo.git
- git pull upstream master
- git push origin master
- 在 github 创建一个 new_repo
- git clone new_repo
- cd new_repo
- git 远程添加上游 old_repo.git
- git pull 上游主
- git push origin master
I got all the above from here.
我从这里得到了以上所有内容。
回答by Akash Mugu
You can now mark the?base repository as a template (in Settings, mark it as a Template repository) and on the main page of the repo, click Use this templateto create your second repo
您现在可以将?base 存储库标记为模板(在设置中,将其标记为模板存储库)并在存储库的主页面上,单击使用此模板创建您的第二个存储库
Github Help: creating a template repositorycreating a repository from a template
Github 帮助:创建模板存储库 从模板创建存储库
回答by phocks
I followed these official instructions for "Duplicating a repository" and it seemed to work.
我按照“复制存储库”的这些官方说明进行操作,它似乎有效。
https://help.github.com/articles/duplicating-a-repository/
https://help.github.com/articles/duplicating-a-repository/
To create a duplicate of a repository without forking, you need to run a special clone command against the original repository and mirror-push to the new one. This works with any git repository, not just ones hosted on GitHub.
要在不分叉的情况下创建存储库的副本,您需要对原始存储库运行特殊的克隆命令并将镜像推送到新存储库。这适用于任何 git 存储库,而不仅仅是托管在 GitHub 上的那些。
回答by Gino
When you create a new repo, you can import from another repo with the repo .git url. It took me 30 seconde.
当你创建一个新的 repo 时,你可以使用 repo .git url 从另一个 repo 导入。我花了 30 秒。