Git: How to ignore a file from one repo and add it to another?

I have a Ruby on Rails application that I am trying to host on Heroku. I would also like to use a GitHub public (free) repository to track changes. I need to check-in a file containing passwords to the Heroku remote repo, but ignore the file so I don't check it in to GitHub. Is there a way I can add the file to one repo, and ignore it from another?

Update: I figured out how to solve my immediate problem of storing passwords in Heroku by using Heroku Config vars. However, I'm still interested in the concept of pushing a file to only specified repos.


What you could do is to add to the GitHub repo a smudge script (filter driver) which will:

  • test for the existing of a private branch
  • checkout the the password file from that branch
  • 替代文字

    Since that private branch would only exist on the Heroku repo, the smudge script wouldn't do anything on the GitHub repo side.
    But once pushed to the Heroku side, if a hook is checkouting a working directory on he Heroku server, then that same filter driver will kicks in and generate the sensitive file.

    That being said, it is best for such a sensitive file to never be versioned in any Git repo, but rather being stored elsewhere.
    The smudge script, rather than testing some Git repo content (like a private branch) would then test for an external repo (a ssh ftp, a Nexus repo, any other data referential out there where you choosed to stored those private informations), extract the right content and generate the file.


    As VonC mentioned, the best (and least error-prone) bet is to keep sensitive config info out of Git and put them in environment variables on your server. Here are instructions for how to do so on Heroku:

    http://docs.heroku.com/config-vars

    See also the linked questions.

    链接地址: http://www.djcxy.com/p/46912.html

    上一篇: 如何设置ASP.NET SQL数据源以接受TVP

    下一篇: Git:如何忽略来自一个仓库的文件并将其添加到另一个仓库?