如何使用初始化 shell 脚本克隆私有 git 存储库

How to clone a private git repository using a initialization shell script

我开始使用 google 计算引擎并尝试自动执行 VM 初始化过程。在启动时,虚拟机应该在 bitbucket 和 运行 应用程序上克隆一个私有 git 存储库。

所以,如果它是一个 public 回购协议,它应该是这样的:

git init myapp
cd myapp
git pull https://me@bitbucket.org/me/myapp.git

如果我想将我的代码保密怎么办? 我应该先下载 SSH 密钥吗?如果是这样,我该怎么做?

我也试过将它克隆到云存储库,但也要求提供凭据。这是更好的方法吗?

查看 Google 存储库文档,我发现您可以使用 Google Cloud SDK 运行 中的帮助程序访问 google 云上的项目存储库命令行:

git config credential.helper gcloud.sh

但是由于所有GCE实例都已经安装了SDK,所以只需:

git init myapp
cd myapp
git config credential.helper gcloud.sh
git pull https://source.developers.google.com/p/<project-id>/r/default

如果克隆到本地机器,只需安装 SDK