GitHub pull request from private to public repo possible?

2021 Update

@VonC's answer is conceptually correct and still the one supported by GitHub. After nine years, @Sebi finally gets the answer he wanted -- I eliminated the "indirection" he commented on that occurs in the second bullet of VonC's answer.

For my use case, I need to make both public and private changes to a public repo. Public commits can be pushed periodically as soon as they are ready. Private changes must remain in my private repo until I complete my PhD research. At that time, I'll need all private changes to flow from my public fork to the original public repo via pull requests.

The bulk of the work is getting things set up correctly. I provided detailed steps in this SO answer. The following steps are done exclusively in the eclipse GUI (v2020-12; EGit 5.11), but can easily be translated to command line operations. The repositories I used are these:

  • eclipse/org.aspectj is the original public repo; the upstream remote for fetching
  • cb4/org.aspectj is my fork; the origin remote for pushing
  • cb4/remPrivAJ is my remote private repo; the private remote for pushing and pulling
  • I:\local is the local repo on my workstation

For github authentication, I used ssh with an ed25519 ssh key (how-to in this SO question) so my connection URIs look like this: ssh://[email protected]/<user>/<repo>.

Notation: -> is a mouse click or selection; right-> and double-> are right-click and double-click, respectively.


I separated public from private changes by putting each in separate branches: pub for public changes; priv for private changes. I'm fairly new to git, so there may be a better way to do this.

  1. Create and configure branches
  • 1.1 In the eclipse Git Perspective, under the local repo: open Branches then open Local (-> v beside each)
  • 1.2 For the private branch: right-> master -> Create Branch -> Select -> private/master -> Ok enter priv for Branch name: -> Configure upstream for push and pull -> When pulling: Merge -> Finish
  • 1.3 For the public branch: right-> master -> Create Branch enter pub for Branch name: -> Finish
  • 1.4 The result: commit numbers in my private repo private/master, my public fork orign/master, and the original public repo upstream/master all match config

  1. Make a private change and commit
  • 2.1 Make some changes, then see detailed info about them on the Git Staging tab in the Git Perspective
  • 2.2 Select individual changes and add them to the index by clicking the green plus sign
  • 2.3 OR select them all by clicking green double plus sign
  • 2.4. Enter a commit message and -> Commit and Push -> Preview -> Push -> Close
  • 2.5 Note the new commit number
    commit

  1. Push private changes to the public fork
  • right-> priv -> Push Branch -> Remote: dropdown v -> origin: URI (mine is origin:ssh://[email protected]/cb4/org.aspectj) double-> master in the Branch: text box and type priv then double-> priv [branch] -> Preview -> Push -> Close

  1. On GitHub, private changes in my public fork. Note same commit number here as above (click image to zoom). changes pushed

  1. To complete the process and open a pull request for a private change against the original public repo, just click on Compare & pull request and Voila! (click image to zoom). pull request

Additional Features and Functions

  • Of course, you can push public commits to the public fork: right-> pub -> Push Branch -> Preview -> Push -> Close
  • Pull and merge updates from the original public repo as frequently as it changes to reduce merge conflicts: under Remotes right-> upstream -> Fetch
  • Then push them to your fork: under Remotes right-> origin -> Push
  • And to your private repo: under Remotes right-> private -> Push

One solution would be to fork the original public repo into your own public repo on GitHub.
Then duplicate your forked public repo into a private one.

You then clone both on your local workstation, and:

  • do public and private modifications on your private local repo
  • push private modifications first to your local public repo
  • then push them to your GitHub forked public repo
  • make your pull request from your forked public repo on GitHub.

I doubt it's intended by Github but you can actually make a pull request from a private to a public repo with a bit of simple DOM manipulation:

  1. Make your changes on your private repo, probably on a fresh branch.
  2. Start a pull request. Hit the change commits button.
  3. Open up an editor that allows you to modify the DOM. Things like Firebug or the Safari web inspector or Chrome developer tools seem to work fine.
  4. Edit the base branch repository. You'll want to change the selected option tag's value.
  5. Next, click on the branch name (and change it if you want). You need to do this to trigger an ajax update.
  6. Update the commit range and you should be good to go.

Some caveats:

  • Clicking the commit links or view file will 404 for the public or users who aren't listed as collaborators. Everything seems fine once it's merged in, but it may be a bit weird for the maintainer of the public repo.
  • The pull request needs to be accepted only from the UI. I don't think it'll let anyone merge or cherry-pick the commits in manually. Conflicts will likely need to be resolved by the private repo owner.

Tags:

Git

Github