简体   繁体   中英

Github how to update the forked repo, entirely the same as newly forked

Many days ago, I forked the Airflow repo and I modified a little then submitted a PR.

But today, I want to submit another PR, so I need to re-fork the latest Airflow source code, and discard all the changes in my repo.

A clumsy way is to delete my repo, then fork the official repo again. Actually, after searching, it doesn't have to delete and fork.

What I tried:

$ git remote add upstream <original-repo-url>
$ git fetch upstream                 # update local with upstream

$ git diff HEAD..upstream/master     # see diffs between local and upstream/master (if there is no diff then both are in sync)

$ git pull upstream master           # pull upstream's master into local branch
$ git push origin HEAD               # push to your forked repo's remote branch

In this way, however, I have to git commit before git push origin master , so there is an additional commit showing in my repo.

My question is how can I update the forked repo, just like a newly forked repo.

Reference

How to synchronize fork with original GitHub project? How do I update a GitHub forked repository?

you need to pull the changes from upstream, rebase option will put your changes on top of synced changes from upstream.

pull will fetch and merge the changes automatically however you may have conflicts in some files that were out of sync or outdated.

$ git pull upstream --r

update your fork with your changes + synched changes from upstream , sometimes you may have situation where there are some changes in your remote fork that are not in your local git. in this case you can pull such changes from your fork and merge locally or use force or -f option to force pushing and overwriting your fork.

$ git push origin branch

Now you can safely open PR from github itself.

I hope this helps you out, if not please feel free to leave comment and I would be happy to help more and update my answer

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