I finished a project that contains an API Key and I want to upload it to Github. I want to be careful not to expose the API Key on Github.
Two methods I've discovered are
ApiKey="YOUR-API-KEY-HERE"
Questions
If the file containing my API Key is 'hidden' in gitignore and I upload my project to Github, will this cause my project to not function properly by anyone who downloads it because the project can't find the 'hidden' API Key? If someone looks at my project on Github, are the 'hidden' files inaccessible to them?
In which cases should I use Gitignore or the "YOUR-API-KEY-HERE" method?
Typically, other individuals who download your code will need to acquire their own API key to make your project run (depending on how your project is setup). They will then add the API Key to their fork (as a secret) or local repository on their machine.
You can securely store your API key as a "Secret" in your GitHub repository by going to:
Settings
tab at top of your repoSecrets
option near bottom of left-most columnNew Repository Secret
Name
fieldexample: SECRET_API_KEY
Value
field.Add Secret
Now you just need to ensure that your project references the SECRET_API_KEY variable.
Note: Other individuals will not be able to access this Secret. Only you, as repo owner, can access this key. Other developers will need to acquire their own API key and store it as a secret in their fork of your project.