Search code examples
gitgithub

Make some files private in a repository


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?


Solution

  • I see three options:

    1. 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.

    2. or you put these files outside of the repository, and reference them with a relative path. define('CONFIG_DIR', '../config/');

    3. (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...