简体   繁体   中英

Make directory in private github repo public

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.

Submodule remains a simpler option:

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"

You can use gitexporter CLI tool. It's a utility that processes all git commit-tree and creates a new git repo with the same commits but with only allowed files and directories.

Example

  1. create config.json
{
    "forceReCreateRepo": true,
    "targetRepoPath": "my-open-source-repo-part",
    "sourceRepoPath": ".",
    "allowedPaths": ["src/*"],
    "ignoredPaths": [".env", "secret.json"]
}
  1. run gitexporter
npx gitexporter config.json
  1. publish your new public repo folder my-open-source-repo-part

You can also use this script in your CI and always have synced public repo.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM