Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pushing .gitignore files to specific remote

I made a Sinatra app, that will be hosted on Heroku, and the source will be up on GitHub. The problem is that i have a file with API keys, that is currently in .gitignore. Is there a way, that I can push my repo to heroku with the key file and exclude the file when pushing to GitHub?

Thanks in advance!

like image 456
skazhy Avatar asked Oct 07 '11 20:10

skazhy


People also ask

Do Gitignore files get pushed?

A . gitignore file lists all of the files that are local to a project that Git should not push to GitHub. A . gitignore always goes in the top level of the project directory, which is also called the project's 'root'.

Is Gitignore specific to a branch?

Unfortunately, git doesn't support branch-specific . gitignore files or directives. Using different .

How do I ignore files while pushing to Git repository?

Excluding local files without creating a .Use your favorite text editor to open the file called . git/info/exclude within the root of your Git repository. Any rule you add here will not be checked in, and will only ignore files for your local repository.

Should Gitignore be pushed to repo?

Normally yes, . gitignore is useful for everyone who wants to work with the repository. On occasion you'll want to ignore more private things (maybe you often create LOG or something. In those cases you probably don't want to force that on anyone else.


2 Answers

It is possible to maintain a separate branch just for deployment, but it takes much discipline to maintain it properly:

  1. Add a commit to a production branch that adds the config file (git add -f to bybass your excludes).
  2. To update your production branch, merge other branches (e.g. master) into it.
    However, you must then never merge your production branch into anything else, or start branches based on any “production commit” (one whose ancestry includes your “add the keys” commit).

An easier path is to adopt Heroku’s custom of using environment variables to communicate your secret values to your instances. See the docs on Configuration and Config Vars:

heroku config:add KEY1=foobar KEY2=frobozz

Then access the values via ENV['KEY1'] and ENV['KEY2'] in your initialization code or wherever you need them. To support your non-Heroku deployments, you could either define the same environment variables or fall back to reading your existing config files if the environment variables do not exist.

like image 180
Chris Johnsen Avatar answered Sep 27 '22 17:09

Chris Johnsen


The Figaro gem provides a good way to manage this issue. It basically simulates Heroku's environment variable approach locally, and makes it easy to keep your keys in sync between your development environment and Heroku.

like image 37
Charles Worthington Avatar answered Sep 27 '22 17:09

Charles Worthington