the workflow we are required to follow is this:
- fork a project on github into your own private githib account.
- clone forked project to local machine.
- create feature branch (of master) on local machine.
- commit branch to forked repo.
- do a pull request on the main repo to the new branch on the forked repo.
This is great, but a few days later we need to create a new feature branch. In the mean time some features have been commited to master on the main repo.
If we now create a new branch on our repo, push it to our forked copy, we are working with old out of date code.
So how do we pull the latest master from the original repo we dont have permission on, into our forked repo, then down to our local repo?
Or is it best to always create a new fork for each feature branch, and try to work quickly (as the code will soon be out of date as we cant pull in changes pushed by others).
This has some discussion on the subject:
Best practice for tracking upstream in fork on github
But is missing what I need, which is how to do this with actual git commands.
E.g. what we have now is this:
- fork on github to local repo using github web ui
- git clone https://github.com/myname/aproject
- git remote add origin https://github.com/myname/aproject # not sure why we have to do this.
- git checkout -b mybranch
- do some work.
- git commit -m ...
- git push origin mybranch # puts the new branch on our personal github forked copy
- make a pull request via github ui.
What we dont know is what commands we would need to get the latest master updates from the original github repo, through to our forked copy of that repo on in our private github account, then finally down to our local cloned copy of the forked repo.
E.g. how would we tell the github hoasted forked repo to update itself from the repo it was forked from?
Or, if this is not possible, a way to pull the latest master from the original github hosted repo directly to the local cloned copy on the developers PC (bypassing the forked repo in the devs. private github account)
I also saw this post:
How do I update a GitHub forked repository?
The accepted answer is this:
git remote add upstream https://github.com/whoever/whatever.git
git fetch upstream
git checkout master
git rebase upstream/master
- How does the fork get the new master updates? This updates the master of your local repo only?
- This implies that your local cloned repo has 2 parents - the original repo and your forked repo. How can this work? How can you fetch from two different repos into one repo? Presumably, the forked repo will never know about the updates pulled from the original repo? When you next push a second feature branch back to your forked repo, it will be based on the wrong code, so the forked repo will be differnt to your local repo, and tests which work locally would not work if you re-checked out everything from your forked repo to a fresh dir?