githubgit-branch

Having a private branch of a public repo on GitHub?


I have a public PHP project in a GitHub repo, which contains just one branch (master).

I want to have a separate branch/fork that is private for me (I have paid for private GitHub repos). I would like to be able to merge changes from the private branch/fork to the public repo, and vice versa.

With that in mind, here are my questions:

  1. Can I have a private branch on a public repo?
  2. Can I fork my own public repo into my own private branch/fork?
  3. If both of the above are possible, which is the best way forward? If neither, how should I proceed?

Solution

    1. Duplicate your public repo.
    2. Make the duplicated repo a private one on GitHub.
    3. Clone the private repo to your machine.
    4. In this local clone of your private repo:
      1. Add a remote to your public repo: git remote add public git@github.com:...
      2. Push branches with commits intended for your public repo to that new public remote. Make sure you don't accidentally commit private-only code.
      3. You can bring in changes from your public repo using git fetch public and then merge them locally and push to your remote private repo (origin remote).