Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
587 views
in Technique[技术] by (71.8m points)

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?
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...