Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having a private branch of a public repo on GitHub?

People also ask

Can you have a private branch in a public repo?

You might as well want to merge every new commit on the public branch to your private branch. This situation happens mostly when you are creating a public repository but also want to use it for your private project. Sadly, GitHub did not allow a private branch on a public repository.

Can you make a public GitHub repo private?

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.

Should my GitHub repo be public or private?

There's no harm in hosting on GitHub or Bitbucket. In fact its accessible from anywhere and you can attract other developers to contribute. You could use private repos if you don't want to make projects open source. And it depends on the hiring manager on how much impact a good github profile makes.


Is it possible to have a private branch on a public repo?

On GitHub, your repository is either public or private; you cannot selectively "privatize" just a branch.

Can I fork my own public repo into my own private branch/fork?

You can clone your public repo to your local machine, branch as needed, and simply not push your "private" branches upstream (by specifying which branch to push to origin: git push origin master or git push origin branch-i-want-to-be-public:master).

Which is the best way forward/how should I proceed?

In order to take advantage of GitHub for both your public and private development, I would suggest forking your public branch within GitHub, changing the settings of the new fork to "Private", and then cloning the private version down to your local machine. When you're ready to make changes public, push everything up to your private fork on GitHub and then use pull requests to selectively copy branches to the public repo.

To make a repository private on GitHub, you must have an upgraded (paid) account. If you're only rocking the free account, you can still use the first process I suggested — clone public to local machine, branch, and push specific "public" branches to origin — without needing a private repo.

If you have a paid GitHub account, or are using another service that offers public and private forks and pull requests (such as BitBucket), then you can use either of the above approaches to make your code public.


  1. Duplicate your repo.
  2. Make the duplicated repo a private one on GitHub.
  3. Clone the private repo to your machine
  4. Add a remote to your public repo (git remote add public [email protected]:...)
  5. Push branches with commits intended for your public repo to that new public remote. (make sure you don't accidentally commit private-only code)
  6. You can bring in changes to your public repo using 'git fetch public' and then merge them locally and push to your private repo (origin remote).

There is another solution which I find better as it doesn't result in duplicate repos on the same machine.

  • Make a branch with the stuff you want private.
  • Make a new repo on GitHub, set it to private.
  • Add new GitHub repo as a second remote to your repo on your machine.
  • Push private branch to second remote.

End result is 1 repository with 2 remotes. 1 public, 1 private.
Just need to be careful about which you push to so name accordingly.