从Github的分支叉 [英] Fork from a branch in github
问题描述
有没有办法从GitHub上的特定分支派生? ...例如,moodle有许多分支(1.9,2.0 ...等等)。克隆只能执行分支1.9而不是主分支?是否可以在我的PC上克隆一个特定的分支?
我还不知道原生方式,但是您可以按照这个配方做:
- 将GitHub网站上的问题存储库(称为'upstream')分支到您的工作空间。 li>
- 运行GitHub桌面应用程序并将存储库克隆到您的PC上。
- 使用GitHub桌面应用程序在存储库中打开一个shell。 (
git
命令不能从默认的PowerShell中使用,除非您手动配置。) -
将源存储库设置为上游:
git remote add upstream https://github.com/{user}/{source-repo}.git
-
获取完整的上游存储库。 (现在,你只有一个主分支的副本。)
git fetch upstream
$ c
$ li $ <$ p $
$ b $使
$让你的文件系统复制你想要的分支并给它任意名称:
git checkout upstream / {分支问题}
git checkout -b临时
-
使用GitHub桌面应用程序发布您的repo。
- 在GitHub网站上,打开您的存储库,设置'。
- 将默认分支更改为临时。 (只需更改下拉菜单,您不需要就需要点击重命名按钮。) 返回到您的存储库,转到'分支'选项卡,现在您可以删除主分支。
-
删除shell的master分支并创建一个新的master分支:
git分支-d master
git分支master
git checkout master
git -d临时
-
再次,使用GitHub桌面应用程序发布您的repo。
- 在GitHub网站上,打开您的存储库并点击'settings'。
- 将默认分支更改回(新)'master'分支。 b $ b
- 返回您的存储库,转到分支选项卡,现在您可以删除临时分支。
这应该是你正在寻找的。也许GitHub将在未来提供一种更方便的方式来做到这一点(例如,从项目分支点击Fork导致这种行为)。
Is there a way to fork from a specific branch on GitHub? … For example, moodle has many branches (1.9, 2.0 … and so on). Can a clone be performed of just branch 1.9 and not the master branch always? Is it possible to clone a specific branch onto my PC?
I don’t know a native way yet, but you can do it following this recipe:
- Fork the repository in question (called ‘upstream’) on the GitHub website to your workspace there.
- Run the GitHub desktop application and clone the repository onto your PC.
- Use the GitHub desktop application to open a shell in the repository. (The
git
commands are not available from the default PowerShell unless you configure that manually.) Set the source repository as upstream:
git remote add upstream https://github.com/{user}/{source-repo}.git
Fetch the full upstream repository. (Right now, you only have a copy of its master branch.)
git fetch upstream
Make your file system copy the branch you want and give it any name:
git checkout upstream/{branch-in-question} git checkout -b temporary
Publish your repo using the GitHub desktop application.
- On the GitHub website, open your repository and click ‘settings’.
- Change the "Default branch" to ‘temporary’. (Just change the drop-down menu, you don’t need to click the "Rename" button.)
- Go back to your repository, go to the ‘branches’ tab, now you can delete the "master" branch.
Delete the master branch on your shell and make a new master branch:
git branch -d master git branch master git checkout master git -d temporary
Once more, publish your repo using the GitHub desktop application.
- On the GitHub website, open your repository and click ‘settings’.
- Change the "Default branch" back to the (new) ‘master’ branch.
- Go back to your repository, go to the ‘branches’ tab, now you can delete the "temporary" branch.
This should be what you were looking for. Perhaps GitHub will provide a more convenient way to do this in future (e.g., clicking "Fork" from a project’s branch results in exactly this behaviour).
这篇关于从Github的分支叉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!