Maiasaura
Maiasaura

Reputation: 32996

How to I push two branches to two separate GitHub remotes?

I have a project where the data folder need to private (but tracked by VCS). So the entire git repo on GitHub is private. The code, however, is quite useful to many people and so I'd like to keep that public.

Currently my repo has only a master and dev. Once features in dev are working, they get merged into master. I'd like to create a no_data branch and have that push to a public GitHub repo. master should continue tracking the private repo. I already have a private GitHub repo for this (let's call it private_project). I can create a public repo called project for the no_data branch.

Questions:
a) How do I set this up so each branch track a separate repo?

b) Since the only thing different between the two branches is that the public one will ignore the data/ folder, I just plan to add that in a .gitignore file. However, I'd like the rest of the code to stay the same in both branches. So I'm afraid that every time I merge master to no_data, I have to manually resolve the .gitignore merge.

Upvotes: 1

Views: 88

Answers (1)

VonC
VonC

Reputation: 1328712

Don't. This is bound to result in an error on day or another.

Make the data directory a submodule, with its own remote upstream repo (the 'private_project' one), declared with its parent repo (which has the upstream repo 'public_project').

That way, you can push any branch of the parent repo to 'public_project': it won't matter.
All that the other contributors would get when cloning 'public_project' is the full repo plus a reference to another repo ('private_project'), which they can't access (because it is a private repo).
See "How exactly does git submodule work?".

Upvotes: 1

Related Questions