从Github的分支叉 [英] Fork from a branch in github

查看:238
本文介绍了从Github的分支叉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从GitHub上的特定分支派生? ...例如,moodle有许多分支(1.9,2.0 ...等等)。克隆只能执行分支1.9而不是主分支?是否可以在我的PC上克隆一个特定的分支?

解决方案

我还不知道原生方式,但是您可以按照这个配方做:


  1. 将GitHub网站上的问题存储库(称为'upstream')分支到您的工作空间。

    li>
  2. 运行GitHub桌面应用程序并将存储库克隆到您的PC上。

  3. 使用GitHub桌面应用程序在存储库中打开一个shell。 ( git 命令不能从默认的PowerShell中使用,除非您手动配置。)

  4. 将源存储库设置为上游:

      git remote add upstream https://github.com/{user}/{source-repo}.git 


  5. 获取完整的上游存储库。 (现在,你只有一个主分支的副本。)

      git fetch upstream 

    $ li $ <$ p $
    $ b $使

    $让你的文件系统复制你想要的分支并给它任意名称:

      git checkout upstream / {分支问题} 
    git checkout -b临时


  6. 使用GitHub桌面应用程序发布您的repo。


  7. 在GitHub网站上,打开您的存储库,设置'。

  8. 将默认分支更改为临时。 (只需更改下拉菜单,您不需要就需要点击重命名按钮。) 返回到您的存储库,转到'分支'选项卡,现在您可以删除主分支。

  9. 删除shell的master分支并创建一个新的master分支:

      git分支-d master 
    git分支master
    git checkout master
    git -d临时


  10. 再次,使用GitHub桌面应用程序发布您的repo。

  11. 在GitHub网站上,打开您的存储库并点击'settings'。

  12. 将默认分支更改回(新)'master'分支。 b $ b
  13. 返回您的存储库,转到分支选项卡,现在您可以删除临时分支。



这应该是你正在寻找的。也许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:

  1. Fork the repository in question (called ‘upstream’) on the GitHub website to your workspace there.
  2. Run the GitHub desktop application and clone the repository onto your PC.
  3. 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.)
  4. Set the source repository as upstream:

    git remote add upstream https://github.com/{user}/{source-repo}.git
    

  5. Fetch the full upstream repository. (Right now, you only have a copy of its master branch.)

    git fetch upstream
    

  6. Make your file system copy the branch you want and give it any name:

    git checkout upstream/{branch-in-question}
    git checkout -b temporary
    

  7. Publish your repo using the GitHub desktop application.

  8. On the GitHub website, open your repository and click ‘settings’.
  9. Change the "Default branch" to ‘temporary’. (Just change the drop-down menu, you don’t need to click the "Rename" button.)
  10. Go back to your repository, go to the ‘branches’ tab, now you can delete the "master" branch.
  11. 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
    

  12. Once more, publish your repo using the GitHub desktop application.

  13. On the GitHub website, open your repository and click ‘settings’.
  14. Change the "Default branch" back to the (new) ‘master’ branch.
  15. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆