I want to host the source code for a website I created in a public repository on Github. I want it to be public so that I can also show the source code to others, however there are some files that I want to remain private. Files that may contain passwords and such (like when connecting to databases). Is there a way to do that?
No, you cannot have different public/private settings within one repository. The closest thing I can think of would be to keep the repositories separate and use submodules to create a unified directory tree, but I can't judge if that makes sense for your workflow.
Just mark your repository as private by going to your repository's Settings -> Danger Zone -> Change repository visibility.
I see three options:
either you add these files to your .gitignore
, don't commit them into the repository. You may optionally provide templates for these files (something like config.php.example
), for other people to customise them. That way, they can keep their config and pull the changes easily.
or you put these files outside of the repository, and reference them with a relative path. define('CONFIG_DIR', '../config/');
(not recommended, submodules are hard) or you put these files in a git submodule. That'll be a little longer though ;)
For reference, the Symfony framework (PHP) uses the first option and provides configuration templates.
I've used successfully option 2 in many projects, it just works, but is less user-friendly.
Never used option 3 for this kind of cases, and submodules are probably not the best tool for this. It can work though...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With