将 .gitignore 文件推送到特定远程

发布于 2024-12-08 21:06:44 字数 159 浏览 4 评论 0原文

我制作了一个 Sinatra 应用程序,将托管在 Heroku 上,源代码将发布在 GitHub 上。问题是我有一个包含 API 密钥的文件,当前位于 .gitignore 中。有没有办法,我可以使用密钥文件将我的存储库推送到heroku,并在推送到GitHub时排除该文件?

提前致谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鹿童谣 2024-12-15 21:06:44

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

  1. 向添加配置文件的生产分支添加提交(git add -f 以绕过您的排除) )。
  2. 要更新您的生产分支,请将其他分支(例如 master)合并到其中。
    但是,您必须永远将您的生产分支合并到其他任何分支中,或者基于任何“生产提交”(其祖先包括您的“添加密钥”提交)启动分支。

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

heroku config:add KEY1=foobar KEY2=frobozz

然后通过 ENV['KEY1']< 访问值/code> 和 ENV['KEY2'] 位于初始化代码中或您需要的任何位置。为了支持非 Heroku 部署,您可以定义相同的环境变量,或者在环境变量不存在时转而读取现有的配置文件。

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.

安稳善良 2024-12-15 21:06:44

Figaro gem 提供了一种解决此问题的好方法。它基本上在本地模拟 Heroku 的环境变量方法,并且可以轻松地在开发环境和 Heroku 之间保持密钥同步。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文