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?
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.
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:
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.
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.
Since an SSH service is running on GCE Linux VMs by default, simply follow these steps:
gcloud auth login
to authorize gcloud to access Google Cloud Platform.gcloud compute config-ssh
to populate SSH config files with Host entries from each instance.Test SSHing to your VM instance by running ssh NAME.ZONE.PROJECT
Example: ssh example-instance.us-central1-a.MY-PROJECT
Set up an empty repository on your VM:
$ mkdir project.git
$ cd project.git
$ git init --bare
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With