Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I 'git push' from a local machine to a Google Cloud Platform instance?

The documentation for Google Cloud Platform describes a number of ways of transferring files to Google Compute Engine instances. But it does not mention how to use Git to do this. Also, while I have Google Cloud code repositories available under "Development" in the Web console, it's not clear to he how to associate these with Compute instances.

How do I associate a Git repository with a Google Compute Engine instance and git push from my local machine to that the instance repo?

like image 863
orome Avatar asked May 14 '16 17:05

orome


People also ask

How to push a project to git repository from Google Cloud Platform?

On your local computer run gcloud auth login to authorize gcloud to access Google Cloud Platform. Run gcloud compute config-ssh to populate SSH config files with Host entries from each instance. On your local computer add the remote repository: Now you should be able to push your project to the Git repository on your VM. Show activity on this post.

What Git commands can I use to interact with Google Cloud?

You can use the standard set of Git commands to interact with these repositories, including push, pull, clone, and log. To push from your local Git repository to a Google Cloud repository, enter the following command: To pull from a Google Cloud repository to your local Git repository, enter the following command:

What is Git push in Git?

git push. The git push command is used to upload local repository content to a remote repository. Pushing is how you transfer commits from your local repository to a remote repo.

How do I push changes from local to remote Git?

The git push command allows you to send (or push) the commits from your local branch in your local Git repository to the remote repository. To be able to push to your remote repository, you must ensure that all your changes to the local repository are committed.


1 Answers

Since an SSH service is running on GCE Linux VMs by default, simply follow these steps:

  1. On your local computer run gcloud auth login to authorize gcloud to access Google Cloud Platform.
  2. Run gcloud compute config-ssh to populate SSH config files with Host entries from each instance.
  3. Test SSHing to your VM instance by running ssh NAME.ZONE.PROJECT

    Example: ssh example-instance.us-central1-a.MY-PROJECT

  4. Set up an empty repository on your VM:

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

  5. On your local computer add the remote repository:

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

Now you should be able to push your project to the Git repository on your VM.

like image 134
Kamran Avatar answered Sep 21 '22 09:09

Kamran