Once I made a PR of a repo, should I delete my fork?


Working with a free project on GitHub, I made a fork of it, made some changes and asked for a PR, which was accepted.

I updated my fork upstream and kept making other changes, and then going back to doing another PR.

At that moment, I realized that my new PR included all the commits I had already made, and even all the files.

It was assumed that when doing the upstream, I should have been up to date, but either I failed at something, or my fork never heard about the accepted PR.

To avoid that, I made a branch with only the modified files. However, the PR of that branch still includes all the commits I made.

Not so with the files, only the modified one goes.

So, what is the correct way to work when you fork a project?

Should I have executed some more command besides the upstream? Or do I just have to empty my fork after each PR and go back to work as if it were zero?

asked by gbianchi 12.04.2018 в 22:02

1 answer


Sounds like you're going to be collaborating with this project for a long time, not because you want to fix a bug and disappear.

In that case, you can do the following:

  • Never touch master . On your fork, master reflects the status of the original project.
  • The first time, set a remote upstream that points to the original project, making git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git .
  • Make all your changes always in a branch. Imagine that you are working on the branch feature-guau . You can do quiet push, all that remains on your fork.
  • Once you want to send a PR, you make a PR of tufork/feature-guau to proyecto-original/master .
  • The mantainer asks you to work on your PR, every change you make you keep uploading to your branch (that updates the PR)
  • Once the mantainer merges the PR, it happens to be in your master ... but not in yours!
  • What you have to do now is to get the master of upstream . For that:
    • Make git checkout master (that makes you go to work in your master (which is out of date).
    • Make git fetch upstream (that makes your computer "know" what is in upstream/master , but does not make changes)
    • Make git reset --hard upstream/master . That makes your master equal to the master of the original repository. As your PR was merged, he brought it.
    • Finally, you have to update your fork ... for that, you can do git push -f . That will make your fork point to exactly the same place as the original project.
  • Step 7 you can do at any time, regardless of whether your PR was merged or not ... what it does is synchronize master .

    answered by 13.04.2018 / 00:28