Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make directory in private github repo public

Tags:

git

github

I have a private repo on Github, Repo A. The structure of the project in Repo A is like:

dist/
src/
project-file.js
project-file2.js

I want to make available the src/ directory in a (new) public repo on Github.

Ideally, I would like this to be as automatic as possible. So in the event that I update source files in Repo A, I would like the public repo to be easily updated, too.

I've found a couple of solutions: the first one involves using Github releases and submodules. This one seems to keep the two repos connected but I'm unsure how to push the src/ directory into(?) the submodule and then push that to a fresh, public remote repository.

The other solution I found is using filter-branch on a cloned repo. The only problem with using the latter that I can foresee is that the two branches then become detached and any changes I make to Repo A will have to be re-cloned again and pushed anew to the public repo.

Basically, I have a private project but I want to make some of the files public for viewing. I believe the first option, using submodules is the better choice, but I'm not sure how to do this in practice. I am not too well-versed with advanced Git techniques so apologies if I'm missing something.

like image 763
David Gaskin Avatar asked Aug 12 '19 19:08

David Gaskin


People also ask

Can you make a private GitHub repo public?

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.

Can you fork a private repository and make it public?

No. You can fork it and it still remains private. Private collaborators may fork any private repository you've added them to without their own paid plan. Their forks do not count against your private repository quota.

Can anyone see my GitHub private repository?

Private repositories are only accessible to you, people you explicitly share access with, and, for organization repositories, certain organization members.


1 Answers

Submodule remains a simpler option:

  • first: split your repository src folder into a new one
  • push that new repo to a new public GitHub empty repository
  • add that repository as submodule in your current one:

That is:

cd /path/to/cloned/original/repo
git rm -r src/
git commit -m "Remove src"
git submodule add https://github.com/you/newSrcRepo src

From there, you can modify files in src and push to that new repo:

cd /path/to/cloned/original/repo
cd src
# work in src
git add .
git commit -m "new src modifications"
git push

And record the new src in your parent repo:

cd ..
git add .
git commit -m "src new state"
like image 163
VonC Avatar answered Nov 15 '22 06:11

VonC