简体   繁体   English

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

[英]How to clone a private git repository using a initialization shell script

I'm start working with google compute engine and trying to automate the VM initialization process.我开始使用谷歌计算引擎并尝试自动化虚拟机初始化过程。 On startup the VM should clone a private git repo on bitbucket and run the aplication.在启动时,VM 应该在 bitbucket 上克隆一个私有的 git repo 并运行应用程序。

So, if it was a public repo would look like this:所以,如果它是一个公共回购,看起来像这样:

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

How do I do if I want to keep my code private?如果我想将我的代码保密,我该怎么做? Should I download a SSH Key first?我应该先下载 SSH 密钥吗? If so, how do I do this?如果是这样,我该怎么做?

I also tried cloning it to the cloud repository, but also asking for credentials.我还尝试将其克隆到云存储库,但也要求提供凭据。 Is this a better aproach?这是更好的方法吗?

Looking through the Google Repository docs I found that you can get access to the project repository on google cloud using a helper from the Google Cloud SDK running the command line:查看 Google Repository 文档,我发现您可以使用运行命令行的 Google Cloud SDK 中的帮助程序访问 Google Cloud 上的项目存储库:

git config credential.helper gcloud.sh

But as the SDK is already installed in all GCE instances, so just:但是由于 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

if cloning into a local machine, just install the SDK如果克隆到本地机器,只需安装SDK

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM