简体   繁体   English

“fork”和“push upstream”对GitHub意味着什么?

[英]What does “fork” and “push upstream” mean for GitHub?

I am currently using GitHub for a project with my college professor. 我目前正在与我的大学教授一起使用GitHub进行项目。 Since I am not too conversant with GitHub, I cannot understand the instructions he has sent me. 由于我不太熟悉GitHub,我无法理解他寄给我的指示。

I was hoping someone could interpret these for me and help me understand it. 我希望有人能为我解释这些并帮助我理解它。

Student should use GIT Hub and use the Project7 branch. 学生应该使用GIT Hub并使用Project7分支。 Fork his own repository and push newly developed branch upstream to the main Project repository 分叉他自己的存储库并将新开发的分支上游推送到主项目存储库

I know a bit about GitHub and its repositories and I'm reading up on branches now. 我对GitHub及其存储库有所了解,现在我正在读取分支机构。 But I still cannot understand how to implement the above mentioned instructions using commands. 但我仍然无法理解如何使用命令实现上述指令。

The first part of the instructions is quite clear. 说明的第一部分非常清楚。 You need to: 你需要:

  • Log in to GitHub, go to the professor's repository and click "Fork". 登录GitHub,转到教授的存储库,然后单击“Fork”。
  • Find the SSH URL for your fork of the repository, and clone it locally with something like: 找到存储库的fork的SSH URL,并使用以下内容在本地克隆它:

     git clone git@github.com:whoever/whatever.git 
  • If you run git branch -r you should see that you've now got the remote-tracking branch origin/Project7 如果您运行git branch -r您应该会看到您现在已经拥有了远程跟踪分支origin/Project7
  • You need to work on that branch, so you need to create a local branch based on origin/Project7 . 您需要在该分支上工作,因此您需要基于origin/Project7创建本地分支。 You can do that with: 你可以这样做:

     git checkout -b Project7 origin/Project7 
  • Now you should do your development and create commits as usual to advance your Project7 branch. 现在,您应该像往常一样进行开发并创建提交以推进Project7分支。

Now is the part that is slightly unclear to me: 现在这部分对我来说有点不清楚:

[...] push newly developed branch upstream to the main Project repository [...]将新开发的分支上游推送到主项目存储库

This might mean: 这可能意味着:

(a) That you should push your branch back to your own forked repository on GitHub. (a)你应该把你的分支推回到GitHub上你自己的分叉存储库。 You can do that with: git push origin Project7 你可以这样做: git push origin Project7

On the other hand, it might mean (b) that your professor has added you as a collaborator to his repository on GitHub, and wants you to push to a new branch in his repository. 另一方面,它可能意味着(b)您的教授已将您作为协作者添加到GitHub上的存储库中,并希望您推送到其存储库中的新分支。 In that case you might do something like: 在这种情况下,您可能会执行以下操作:

git remote add professor git@github.com:professor/whatever.git 
git push professor Project7:WarDoGG-Project7

That would push your branch Project7 to a new branch in the professor's repository called: WarDoGG-Project7 . 这会将您的分支Project7Project7教授的存储库中的一个新分支: WarDoGG-Project7 Or he might want you just to advance his branch by pushing back to the original Project7 , in which case you can just miss off the :<destination-branch> part of the command. 或者他可能希望你通过推回原来的Project7来推进他的分支,在这种情况下你可以错过命令的:<destination-branch>部分。

I think that situation (a) is more likely, but you should check. 我认为情况(a)更有可能,但你应该检查。

I understand from the instructions that: 我从说明中了解到:

1) You should go to the main project github page (once logged in) and click on the "Fork" upper right button. 1)您应该转到主项目github页面(登录后)并单击“Fork”右上角的按钮。 With this you have forked the main project to your github account. 有了这个,您已将主项目分支到您的github帐户。

2) Clone your forked project to your computer: 2)将您的分叉项目克隆到您的计算机:

3) On your local git repository: > git checkout -b Project7 origin/Project7 3)在你当地的git仓库: > git checkout -b Project7 origin/Project7

4) Work on the code.... 4)处理代码....

5) Push your changes to your github repo. 5)将您的更改推送到您的github仓库。

6) Make a pull request on github to the main repo. 6)在github上向主仓库发出拉取请求。

He's telling you to download the repository and then switch to the Project7 branch, and to fork off your own branch. 他告诉你下载存储库,然后切换到Project7分支,并分叉你自己的分支。 You should be able to clone a forked repo by following these instructions (works exactly like a normal clone except you've gotta fork it on github first): 你应该能够按照这些说明克隆一个分叉的repo(就像普通的克隆一样,除了你必须先在github上分叉):

http://help.github.com/fork-a-repo/ http://help.github.com/fork-a-repo/

Then, after you get it cloned, switch to the Project7 branch 然后,在克隆之后,切换到Project7分支

git checkout -b newlocalbranchname origin/branch-name git checkout -b newlocalbranchname origin / branch-name

Then, make sure you push back to your branch: 然后,确保你回到你的分支:

git push origin branch-name git push origin branch-name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM