Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Private folder (submodule) in a public repo

I have a public repository. In it I want to use a submodule that is private. If i include this submodule into my public repo, will everyone be able to see the contents of that submodule?

like image 846
Noitidart Avatar asked Jun 05 '16 03:06

Noitidart


People also ask

Can submodules be private?

Also, git submodules can also be used for both private and public repos. First you can add the submodule. From the root of blog , you would run this command. This would clone the posts repo into a folder in blog .

How do I create a submodule for an existing repo?

In order to add a Git submodule, use the “git submodule add” command and specify the URL of the Git remote repository to be included as a submodule. When adding a Git submodule, your submodule will be staged. As a consequence, you will need to commit your submodule by using the “git commit” command.

Can I make a public git 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.

How do I move a submodule to a different directory?

Git Submodules Moving a submodule If needed, create the parent directory of the new location of the submodule ( mkdir -p new/path/to ). Move all content from the old to the new directory ( mv -vi old/path/to/module new/path/to/submodule ). Make sure Git tracks this directory ( git add new/path/to ).


Video Answer


2 Answers

No: Including a submodule in a public repository means recording its URL in a public .gitmodules file.

The repository at that URL will not be any more accessible through a recursive clone of your repository than it is on its own.

That is why, for instance, using submodules with GitHub Pages is not possible:

You can only use submodules with GitHub Pages sites that point to public repositories.
Using a submodule that points to a private repository is not possible because the Pages server cannot access private repositories.

like image 160
VonC Avatar answered Oct 20 '22 07:10

VonC


If you push your branch with the submodule to the public repository, it means that the public will be able to see the URL to the submodule. Whether the public can see the contents of the submodule depends on whether you have it accessible to the public. For example, if you have it in a private Github repository, the public will be able to see the URL but won't be able to access the contents.

All adding a submodule actually does is put an entry to the url in .gitmodules, it doesn't paste in the contents of that repository. Whether that URL is publicly accessible is another matter entirely.

If you want to keep even the URL to the private repository private, you have to work on a separate local branch and never push that branch to the public repository. eg.

git clone somePublicRepo
cd somePublicRepo
git branch neverPushThisBranch
git checkout neverPushThisBranch
git submodule add privateRepo
git submodule update

Since the file that describes what submodules a repository contains (.gitmodules) is checked in just like any other file in Git, if you check out a submodule on a branch, nobody sees that submodule unless you push the branch to a public place.

This is how different git branches can have a different set of submodules.

With this approach you need to be fairly disciplined in how you work on branches, lest you accidentally push your private branch to the world.

like image 20
MichaelM Avatar answered Oct 20 '22 08:10

MichaelM