Maintain seperate git branches – One for heroku and another for github
I have got a project in nodejs which is on github and deployed on heroku. In that project I use a few API keys and those keys are stored in
config.js file which is ignored while pushing to github. But I need those files for deployment on heroku. So my problem is when ever I make any changes to push on github I have to ignore that
config.js file and when I deploy on heroku I have to include those again in my branch. I am stuck in this viscous cycle.
- How do I backup my project with git?
- Intstalling ibm_db package for node.js using github
- how to run npm/grunt command from jenkins
- Private npm/git dependencies on Google App Engine
- How to run node.js applications locally for development
- Heroku Node.js Error heroku: at=error code=H10 desc=“App crashed” method=GET path=“/”
This is my second time asking question here. So if I did not follow any convention please tell so that I may edit for future visitors.
2 Solutions collect form web for “Maintain seperate git branches – One for heroku and another for github”
This is pretty simple, maintain three branches,
github branch, write all your code (except the js file in question).
orphan branch, (created using
git branch branch_name --orphan), add and commit the js file.
Every time you want to push to heroku, create a new branch out of github (
git checkout heroku && git reset --hard github) and then merge the orphan branch (using
git merge orphan).
Now you can push this branch to heroku.
You could juggle multiple branches to maintain your configuration file, but you might prefer using environment variables instead.
In your Heroku app administration, go to the “Config Variables” or the “Settings” tab. You likely have default variables set already.
Add your API keys, and you can access them in Node using process.env.ENV_VARIABLE where ENV_VARIABLE is the name you give the variable.
You can setup the same environment variables in the local development environment in your Virtual Host or in your System Environment Variables depending on your setup.
Checkout this article for more details about config vars: https://devcenter.heroku.com/articles/config-vars