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.

Thank You

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.

  • Managing development of 2+ nodejs packages with dependencies
  • Setting NODE_ENV variable in elasticbeanstalk
  • NPM install from Github, ambiguous argument
  • Modifying sample Hello World Node.js code not taking effect in Google Compute Engine
  • Generate a TopoJSON
  • How to get a Git repo url saved in a bash script to a variable
  • optional githook behaving as non-optional
  • npm install failed because of virtual directory
  • 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, heroku, and orphan.

    In the github branch, write all your code (except the js file in question).

    In the 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

    Git Baby is a git and github fan, let's start git clone.