【问题标题】:How to clone a private git repository using a initialization shell script如何使用初始化 shell 脚本克隆私有 git 存储库
【发布时间】:2016-11-11 16:26:36
【问题描述】:

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

所以,如果它是一个公开的 repo,应该是这样的:

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

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

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

【问题讨论】:

    标签: git shell bitbucket google-compute-engine


    【解决方案1】:

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

    git config credential.helper gcloud.sh
    

    但由于 SDK 已安装在所有 GCE 实例中,所以只需:

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

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

    【讨论】:

    • 所有这些步骤都打包到一个 gcloud 命令中:gcloud source repos clone default。此外,对于新项目,您可能需要创建存储库,因为 default 默认情况下可能不会退出。创建 GCE 实例时,您可能希望允许访问所有 API。见stackoverflow.com/questions/38067253/…
    猜你喜欢
    • 2011-05-18
    • 2022-01-23
    • 2018-03-14
    • 2021-07-30
    • 2021-02-04
    • 2021-09-04
    • 2020-09-20
    • 2019-05-09
    • 2019-06-07
    相关资源
    最近更新 更多