将.gitignore文件推送到特定的远程 [英] Pushing .gitignore files to specific remote

查看:205
本文介绍了将.gitignore文件推送到特定的远程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个Sinatra应用程序,该应用程序将在Heroku上托管,并且源代码将在GitHub上运行。问题是我有一个带API密钥的文件,目前在.gitignore中。有没有办法,我可以推动我的回购与密钥文件heroku和推送到GitHub时排除文件?



提前致谢!

解决方案

可以为部署维护一个单独的分支,但需要很多纪律才能正确维护它:


  1. 向生产分支添加一个提交,该提交将配置文件( git add -f )添加到bybass您的排除项中。

  2. 要更新您的制作分支,请将其他分支(例如 master )合并到其中。

    但是,您必须从不将您的生产分支合并到其他任何内容中,或者基于任何生产提交(其祖先包括您的添加键提交)开始分支。

  3. $ b

    更简单的方法是采用Heroku使用环境变量将您的秘密值传递给您的实例的习惯。请参阅配置和配置变量上的文档:

      heroku config:add KEY1 = foobar KEY2 = frobozz 

    然后访问在您的初始化代码或您需要的任何地方通过 ENV ['KEY1'] ENV ['KEY2'] 他们。为了支持您的非Heroku部署,您可以定义相同的环境变量,或者在环境变量不存在的情况下退回到读取现有配置文件。


    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!

    解决方案

    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.

    这篇关于将.gitignore文件推送到特定的远程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆