5

I have a Rails app with a config/my_private_data.yml file. I would like to push the entire app both to my test server and to github.

However, when I push to the test server, I want to include the private file. When I push to github, I don't want to include the private file. What is the easiest way to go about this?

Clay
  • 2,949
  • 3
  • 38
  • 54
  • 2
    How private? If it's a massive desaster if the file becomes public, don't include it at all (use a `config/private_data.yml.template` with default values). Chances are you, or someone makes a mistake and you have the data on github or somewhere else where you never thought of now. – Unapiedra Dec 06 '11 at 21:27
  • Not particularly private, but not something that I want to share. I wouldn't post my nuclear codes to github or even put them in my app. – Clay Dec 07 '11 at 00:47
  • this here should be a solution: http://stackoverflow.com/questions/1836742/using-git-how-do-i-ignore-a-file-in-one-branch-but-have-it-committed-in-another – Andre Holzner Sep 19 '12 at 18:59

1 Answers1

1

You can set up two branches. master and secret. You can then add and commit the config/my_private_data.yml in the secret branch which you can then push into the master branch at the testserver.

touch config/my_private_data.yml
git checkout -b secret
git add config/my_private_data.yml
git commit -m 'Commited secret file'
git push testserver_repo_url secret
git checkout master
git push repo_on_github master

Then do a git checkout secret; git rebase master if you have new commits on master.
Don't commit on secret and if you do, do a cherry pick of that commit.


Certainly, not all is good with this approach. From what I can think now, you could inadvertently push the secret branch to github. Also, you can't really work in master if you need the my_private_data.yml-file (you can do a checkout of that file from the secret branch though).

Unapiedra
  • 15,037
  • 12
  • 64
  • 93
  • Is there a better way to approach this? My use case is that I want to push to github for backup but push to my test server for testing and the app won't load without the private file. – Clay Dec 07 '11 at 00:49
  • I guess the next question would be whether the opposite is possible -- say, I work on master, which includes the secret file, and then I push a branch of master that doesn't have the secret file to github. Would there be a quick way and/or script to always branch master, delete all instances of the secret file, and then push the branch to github? – Clay Dec 07 '11 at 00:52
  • @Clay In theory you can use hooks (google git hooks) but there is no way to delete all instances of the secret file from git (because you can't change the git history). – Unapiedra Dec 07 '11 at 12:12
  • You can have a branch `public` and a `private` branch. (There is nothing special about that `master` branch, it's just a name.) If you want you can pretend that `private` is called master, and only push the public branch. Whereas, in my answer the master branch is the public one but really that's just the name I gave it. – Unapiedra Dec 07 '11 at 12:14