Search code examples
gitconfiggitignore

Function of .gitignore to avoid pushing of API keys?


Hi I will be using MySQL Connector/Python to access some data in DB. I have read in the guidelines not to hardcode the keys on to the code but use config.py. I have also found that it can be done with JSON. My app will be served to Heroku. What's the use of .gitignore? On this example, he used the name databaseconfig.py. But added a line *config.py in the .gitignore file. Why is not *databaseconfig.py? Also what is the equivalent if I have to add the JSON config file to the .gitignore? Thanks!


Solution

  • He is using *config.py line in the .gitignore because then git will ignore every file which ends in config.py, for example dabaseconfig.py, config.py, networkconfig.py and testingtestingothertestconfig.py all get ignored (but for example confignotcorrectformat.py will not get ignored). The * is a so called wildcard and will match anything.

    If you need to ignore a JSON config file you can use the line *config.json in your .gitignore.