-->

Git forking and pull-request workflow

2019-05-04 18:07发布

问题:

I have a repo of a react project. I'd like to take that repo as the "base" of a few other projects and use it as a starting point. I'd also like to keep all of the other repos which stem from it up-to-date based on what the "base" has going on.

I am using Bitbucket for remote repo hosting and Tower locally as a nice GUI.

Is the correct way to do this is fork the "base" in Bitbucket, and then clone it locally? Will the local repo be aware of updates to the "base" repo in any way? How would I know if a significant commit has been made to the "base" repo which would benefit any of the forked repos?

Alternately, if I make a change to the forked repo that would benefit all of the other repos, can I do a pull-request so the "base" repo knows that it should pull in the updates?

Please excuse any ignorance, I've not used forking or pull-requests at all at this time and am trying to get my head around it :)

回答1:

Will the local repo be aware of updates to the "base" repo in any way?

No: you will need to add a remote, named (usually) upstream, referencing the original repo

cd /path/to/local/clone/of/fork
git remote add upstream /url/original/repo

git checkout master

# detailed step:
git fetch upstream
git merge upstream/master

# or (shorter)
git pull upstream master

Alternately, if I make a change to the forked repo that would benefit all of the other repos, can I do a pull-request so the "base" repo knows that it should pull in the updates?

Yes, that would be a classic pull request.