Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub pull request from private to public repo possible?

I forked a public repo and made the new repo private.

I added a new remote branch on my private repo with some fixes committed.

Now, I want to create a pull request from the branch in my private repo towards the public repo I forked from.

I select the branch in my private repo and click "Pull request".

I click on "Change commits".

I can't change the organisation/repo owner. I only see my organisation, but not the one of the public repo. I could only create a pull request against master branch of my private repo, but that's not what I want.

Is it not possible to fix something of a public repo in a private one and create a pull request afterwards?

like image 766
Sebi Avatar asked Jan 12 '12 12:01

Sebi


People also ask

Can you change a GitHub repository from private to public?

Changing a repository's visibilityOn GitHub.com, navigate to the main page of the repository. Under your repository name, click Settings. Under "Danger Zone", to the right of to "Change repository visibility", click Change visibility. Select a visibility.

Can you fork a private repository and make it public?

No. You can fork it and it still remains private. Private collaborators may fork any private repository you've added them to without their own paid plan. Their forks do not count against your private repository quota.

Can you make a private pull request?

Pull requests opened on private repositories remain private. Therefore, if you aim to prevent students from copying others' solutions, then you'd better consider making the assignments private. To do so, you could ask GitHub for an academic discount on your organization.

How do you raise a pull request in public repo?

Create Pull Request Now if you open a public repository you get this: After clicking on Compare & pull request you get: GitHub will alert you that you are able to merge the two branches because there is no competing code. You should add in a title, a comment, and then press the “Create pull request” button.


2 Answers

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.
like image 117
VonC Avatar answered Oct 20 '22 19:10

VonC


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
like image 27
cb4 Avatar answered Oct 20 '22 20:10

cb4