如何将代码推送到隐藏API密钥的Github? [英] How to push code to Github hiding the API keys?

查看:88
本文介绍了如何将代码推送到隐藏API密钥的Github?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一些代码推送到我的GitHub存储库中.这些代码使用不同的语言,例如JavascriptJavaPython等.其中一些代码包含一些我不想发布的私有API密钥.

I want to push some codes to my GitHub Repository. These codes are in different languages like Javascript, Java, Python etc. Some of those codes contain some private API key that I don't want to publish.

有什么方法可以自动隐藏键?我应该手动将其从代码中删除吗?

Is there any way to hide the keys automatically.? Should I remove it from my code manually.?

我想推送到GitHub的项目很多.因此,手动删除不是一个好的选择.

There are many projects that I want to push to GitHub. So, manual removal is not a good option.

推荐答案

您应该考虑使用.env文件,并从环境变量中读取密钥.如何执行操作取决于您使用的语言和工具(对于 node.js

You should consider using .env files and read the keys from the environmental variables. How to do so depends on the language and tools you use (for node.js, php, etc.).

通过将.env添加到.gitignore,可以从提交中排除.env文件.您还可以上传带有虚拟数据或空白的示例配置.env.example,以显示您的应用程序所需的架构.

You can exclude .env file from commits by adding .env to the .gitignore. You can also upload an example configuration .env.example with dummy data or blanks to show the schema your application requires.

这篇关于如何将代码推送到隐藏API密钥的Github?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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