如何从本地计算机"推送"到Google Cloud Platform实例?

oro*_*ome 6 git google-compute-engine google-cloud-platform

Google Cloud Platform 的文档介绍了将文件传输到Google Compute Engine实例的多种方法.但它没有提到如何使用Git来做到这一点.此外,虽然我在Web控制台的"开发"下可以使用Google Cloud代码存储库,但他不清楚如何将这些存储库与Compute实例相关联.

如何将Git存储库与Google Compute Engine实例以及git push从本地计算机关联到实例存储库?

Kam*_*ran 10

由于SSH服务默认在GCE Linux VM上运行,因此只需按照以下步骤操作:

  1. 在您的本地计算机上运行gcloud auth login以授权gcloud访问Google Cloud Platform.
  2. 运行gcloud compute config-ssh以使用每个实例的主机条目填充SSH配置文件.
  3. 通过运行ssh NAME.ZONE.PROJECT

    示例测试SSH到您的VM实例:ssh example-instance.us-central1-a.MY-PROJECT

  4. 在VM上设置空存储库:

    $ mkdir project.git
    $ cd project.git
    $ git init --bare

  5. 在本地计算机上添加远程存储库:

git remote add origin NAME.ZONE.PROJECT:/<PATH>/project.git

现在,您应该能够将项目推送到VM上的Git存储库.


Cod*_*ard -2

您必须为此操作定义远程。(使用 git 远程添加/设置 url)


远程添加

# Add new remote
git remote add godaddy1 $user1@foo.com:~/root.git 
Run Code Online (Sandbox Code Playgroud)

远程设置 url

# replace the current remote if want to replace instead of adding a new one
git remote set-url godaddy $user1@foo.com:~/root.git
Run Code Online (Sandbox Code Playgroud)

列出所有遥控器

# List all remotes
git remote -v
Run Code Online (Sandbox Code Playgroud)