简体   繁体   中英

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

I am currently using GitHub for a project with my college professor. Since I am not too conversant with GitHub, I cannot understand the instructions he has sent me.

I was hoping someone could interpret these for me and help me understand it.

Student should use GIT Hub and use the Project7 branch. 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. 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".
  • Find the SSH URL for your fork of the repository, and clone it locally with something like:

     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
  • You need to work on that branch, so you need to create a local branch based on 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.

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. You can do that with: 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. 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 . 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.

I think that situation (a) is more likely, but you should check.

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. With this you have forked the main project to your github account.

2) Clone your forked project to your computer:

3) On your local git repository: > git checkout -b Project7 origin/Project7

4) Work on the code....

5) Push your changes to your github repo.

6) Make a pull request on github to the main repo.

He's telling you to download the repository and then switch to the Project7 branch, and to fork off your own branch. 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):

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

Then, after you get it cloned, switch to the Project7 branch

git checkout -b newlocalbranchname origin/branch-name

Then, make sure you push back to your branch:

git push origin branch-name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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