0

I forked a repository on GitHub and create pull requests whenever I have something new to contribute. I usually do it like this:

  1. Pull/merge changes from the original upstream repository
  2. Commit and push my changes to my fork
  3. Create a pull request on GitHub

Now somebody of the original repository complained that in the pull request he can see the entire fork history and not only the commits relevant to the pull request.

How can I fix this?

Krisztián Balla
  • 19,223
  • 13
  • 68
  • 84

1 Answers1

2
  • Make a branch before you start work, and create the pull request on the branch. Never ever do a pull request on the main stream of work.

  • Also, make sure the branch is rebased on top of the latest state of the main stream on the original just before you make the pull request.

  • Optionally, squash the branch to a single commit before the pull request.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • I did the first point, but don't know how to do the rebase. Can you give me an example please? – Krisztián Balla May 20 '20 at 20:52
  • Think about it this way. A pull request is a merge. The merge base will be the oldest point at which the branch and the main stream diverge. You want that point to be the end of the main stream on their machine as it is now. So you need a branch in your local world that tracks their main branch. That is what you should have branched off before doing your work. There's no point branching off _your_ main branch if it has changed, because they will, as you say, get everything you've done since you forked whether they like it or not. – matt May 20 '20 at 20:56
  • Thanks for the elaboration. Sorry, I meant an example for the git command I need to execute. – Krisztián Balla May 20 '20 at 20:58
  • 1
    See https://stackoverflow.com/questions/7244321/how-do-i-update-a-github-forked-repository/ for example, lots of great info there. – matt May 20 '20 at 21:05
  • Thank you so much. This was so frustrating. I knew what I wanted to do but didn't know the terminology so could not find anywhere what I was looking for. – Krisztián Balla May 20 '20 at 21:18