I have a private git repository in which I have my own project and some 3rd party projects. This is its rough structure:
Root
|- My Project
| |-- myproject
| |-- __init__.py
| |-- __main__.py
| |-- tests
| |-- setup.py
|- Project1
|- Project2
However, if I want to push this to a public repository, I cannot include the 3rd party projects. So I have to push my project in a different state to the public repository.
I've thought of a few solutions so far but they each have their drawbacks:
Using a
public
branch, to which I only add my own code files. I then push thepublic
branch to the public repo and themaster
branch to my private repo. However, this solution results in the public repository containing a single folder, rather than looking like a regular Python project (see for example numpy's git repository). I would like a solution that hasMy Project
as the root directory for the public repo.Checking out the
public
branch, then movingMy Project
to the root and deleting everything else. With this approach, I'm not sure how merging development from themaster
branch would work though.Using a git subtree. However, this seems to have the same problems as using a separate branch.
Using an actual subrepository by running
git init
insideMyProject
. This solves the problem of the repo root, but it makes the public repository the default one when theMyProject
directory is the CWD. Sogit
(and any version control modules in the development tools I use that rely on git, such as VSCode's) will commit and push to the public repository instead of the private one. I want most of the development to be pushed to the private repo with only the occasional (deliberate) push to the public repo.Using a submodule. However, the way I understand it, submodules are intended for use when you want to independently develop a part of your repository, which is kind of the opposite of what I'm trying to achieve (I want to develop my repository as a whole and only occasionally push a part of it to the public repo). Additionally, the submodule would require specific handling on subsequent cloning of the private repo. Last, I've read that submodules are rarely a good idea (see for instance the first sentence of https://www.atlassian.com/git/tutorials/git-subtree).
Is there a solution that will let me connect my local repository to 2 remote ones (private and public), such that:
- The public repo will contain only my own code from
My Project
; - The public repo will be rooted at
My Project
; - Any development I do will by default be added, committed and pushed to the private repository (for instance, if using the exact commands
git add -A; git commit -m "msg"; git push
); - Cloning the private repo with
git clone path-to-remote-private-repo
will clone the entire project (including the content ofMy Project
); - I'll be able to seamlessly merge changes to the code in
My Project
to the public distro; - (optionally) I'll be able to, on a file-by-file basis, add certain files from
Project1
andProject2
as extra files to the public distro. I can probably do this easily using symlinks but maybe there's a better way.