github sync from fork

2019-06-05 06:44发布

问题:

I am pretty new to github.

I made a fork from a third party, then I modified several files in this fork and committed to my fork. Based on my fork, I made a branch.

I noted there are some update in upstream (the third party source which I made the fork), so I sync my fork. Now how do I push the changes from my fork to my branch ?

Another situation is after I made some changes in my branch, how do I push them back to my fork?

回答1:

You need to do a:

git request-pull original_repo <repo_url> repo_with_changes

This is will pull the new code into the original_repo

Here is more information on it: https://git-scm.com/docs/git-request-pull



回答2:

Based on my fork, I made a branch. I noted there are some update in upstream (the third party source which I made the fork), so I sync my fork. Now how do I push the changes from my fork to my branch ?

Actually, if you have added a remote referring to the original repo, what you do is:

 git remote add upstream /url/original/repo
 git fetch upstream
 git checkout your-pr-branch
 git rebase upstream/master
 git push --force

This assume your-pr-branch was done from the upstream repo master branch.
You can also pull upstream/master into master and push master to your fork if you want to sync your fork.