Create new pull request from fork without having commits of the previous fork

To really understand this, we need to define some things.

First, there’s a bit of a problem here because “pull request” is not a Git thing itself. You have included the tag and GitHub does define “pull request”—in fact, they’ve re-defined it at least once; see this early 2013 answer from VonC, revised numerous times afterward—but not everyone uses the exact same definitions (not just the amusing Fox Business image therein, there’s real disagreement on the exact details, and as just noted, even GitHub itself does not agree with itself). But they all share some common features. The general idea is that there are at least two humans involved: yourself, and someone else. Your goal is to get the Someone Else to incorporate your work into their work. To that end, you want to make it as easy as possible for them.

Next, there’s another problem because “fork” is also not a Git thing itself. The SO question Are git forks actually git clones? states this correctly:

I keep hearing people say they’re forking code in git. Git “fork” sounds suspiciously like git “clone” plus some (meaningless) psychological willingness to forgo future merges. There is no fork command in git, right?

Github makes forks a little more real by stapling correspondence onto it. That is, you press the fork button and later, when you press the pull request button, the system is smart enough to email the owner. Hence, it’s a little bit of a dance around repo ownership and permissions.

(and once again VonC has a nice answer: yes, “fork” is a clone, but done on the GitHub server side, with those extra attributes, permissions, and so on). Using this server-side clone makes it easier for someone who is also using GitHub to take back your work. In the end, though, it’s probably about git merge, since GitHub uses git merge (sometimes with --squash) under the covers. It just might have some web GUI clicky buttons that make it easier.

Back to your question

So i’ve made a few commits to my fork of someone else’s repo, and then submitted a pull request for the same. My old pull request hasn’t been merged yet, and now i need to submit a new pull request without the previous commits, but with new changes that i’m going to make to my fork (i need my old pull request with its commits to stay, too). How can i do this?

Some of this depends on the “someone else”. But:

  • if you isolate each pull request (“please incorporate this work”) to a branch of your own; and
  • if you have that branch-tip ready to merge with their branch-tip, so that they can easily git merge it, perhaps with a clicky button

then you have certainly made it as easy as you possibly can, for them.

Whether and how much “your fork”—by which we mean “your clone as maintained on GitHub”—matters depends on exactly how they are going to obtain your commits and merge (or decide whether to merge). But, putting each set of commits on its own branch, while keeping some branch—often but not always named master—in your fork up to date with some, probably same-named, branch in their fork, i.e., their clone as maintained on GitHub—should have the desired effect.

Doing all of this means that your commits become something they can easily add to their repository. Moreover, when they use the clicky buttons—if that’s their plan and their method—your commits will be copied into their repository in some fashion (straight copy plus merge commit, if regular merge; squashed into one new en-masse commit if squash “merge”). Once that’s done, it will also be a minimal amount of work on your part to update your fork to account for their incorporation of your work.

(Disclaimer: I don’t use the clicky buttons on GitHub. 🙂 I just load your commits into my repository directly, on my machines, where I have full control using the command-line interface.)

Leave a Comment