I share my Java project on GitHub (because I believe in open-source code and no hidden tricks). Anyways, I have a unique UserAgent I got from a website for API usages... I want to know how I can hide that from GitHub without making my project private... What can I do? I tried searching Google, but no one seems to have the same problem. I can't use a separate file and then add it to .gitignore because it won't work when I deploy the project. Please help!
-
1I think, you should make your unique UserAgent a configurable parameter and/or read if from a configuration file instead of hard-coding it into your sources anyway. – Feb 23 '14 at 08:37
-
Yeah I plan on switching it to a config file, problem is that it will still be displayed publically on github and I don't know how you can possibly hide it... – XQEWR Feb 23 '14 at 08:43
-
1You should not push configuration files into GitHub in the first place. You should not publish the actual content of *your personal configuration files* but instead provide an example of a configuration file with your sources at most (the proper way of doing this would be to provide documentation for configuration file, letting anyone using your sources to generate a configuration file suitable for their environment). – Feb 23 '14 at 08:54
-
And just to add to that, you should add the real config file to `.gitignore` if you read it from a location in the project tree. That way, you (or other contributors) won't accidentally add it with `git add .`. – yshavit Feb 23 '14 at 09:07
3 Answers
I want to know how I can hide that from GitHub without making my project private
You cannot push that information to the repo then.
What you can do is declaring a content filter driver which, on checkout, will check if it has access to a private source of information (elsewhere than your public repo, potentially elsewhere than GitHub), and generate the right file (which remains private, and is declared in the .gitignore).
That content filter driver is declared in a .gitattributes, and is taking a template file (which is versioned but contains, by its nature, no value), and will generate the complete file with:
- default values (if the source of the private data isn't found)
- sensitive values (if the script has access to the private source of information)
-
The problem is that I need to give my Unique UserAgent to all users and not a template because the UserAgent is only given to developers which I had to apply for. – XQEWR Feb 23 '14 at 19:50
-
@RWEQX that doesn't make much sense. If it is only given to developers and you had to apply for it, how is it possible that you would be able to just give it to all users? I mean, is it really *meant* to be given to users, or should the API only be used by developers having such a personal key? – eis Nov 11 '15 at 20:36
As suggested in comments: put this information in a config file.
Here is an example: this javascript project provides a config.js.template file, but the application expects a config.js
file (which is gitignored). If this file doesn't exist, the template is copied.
That way, it will run with sensible default values even if the user doesn't take the time to write his own config first.
Moreover, since you're saying yo plan to "switch" to a config file, I guess those personal config values are currently in your code. So don't forget to also clean your old commits before pushing to github!

- 13,807
- 9
- 40
- 57
-
I can't do this because the UserAgent I have is required to access the website. (Its a Dev key that not everyone can get).. So I don't mind others using my key but I can't have them copying and using it in their own programs so I want the key to be hidden – XQEWR Feb 23 '14 at 16:51