Google Source Repository error when doing git push from GCP VM

1.5k views Asked by At

I'm trying to upload a dummy repository to Google Source Repository. I'm doing this to learn how to use this. The steps I did were:

  1. Open a GCP VM, created a directory named test_git and run git init

  2. Created a couple of files and folders. Edited the files.

  3. Did a git add <file>

  4. Did a git commit

  5. Went to Google Source Repository, created an empty repository (same name as the directory) and then, on the VM, did

    git remote add google ssh://<[email protected]>@source.developers.google.com/p/<PROJECTID>/r/test_git

This command was found in the Source Repository under the "Push code from local git repository"

  1. Did git push --all google

When I do this, I get an error that says Permission denied (publickey). fatal: Could not read from remote repository.

I honestly don't get it, because around 40 minutes ago I did a git push for some actual code (just one python file) and it actually worked (maybe because angels allowed it). And now that I followed some guides, read about how to use git and all stuffs, I'm stuck with this and I don't understand why. I also set a SSH key (generated with PuTTY) and registered it, but it didn't worked. What I'm doing wrong?

1

There are 1 answers

3
Donnald Cucharo On BEST ANSWER

I was able to replicate your problem when I didn't have an SSH key configured on CSR. Here's a post related to your concern and I suggest you double check your managed SSH keys.

If the SSH key from PuTTY didn't worked, then you can try generating a new SSH key using terminal (use Git Bash if you're using Windows):

  1. Open Terminal.
  2. Paste text below:
  ssh-keygen -t rsa -C "[email protected]"
  1. Enter a file in which to save the key (leave empty & press enter for default).
  2. Type a secure passphrase (recommended) then press enter.
  3. If default is selected on Step 3, open the file called id_rsa.pub and paste the entire text to Key when registering the SSH key on Cloud Source Repository. For Key Name, it should be something that is easy for you to remember as future reference.

Or as an alternative, you can follow this documentation to connect via HTTPS instead of SSH and run a credential helper script so you don't need to configure SSH keys:

Windows:

git config --global credential.https://source.developers.google.com.helper gcloud.cmd

Linux or MacOS:

git config --global credential.'https://source.developers.google.com'.helper gcloud.sh

Here's a reference if you want to dig deeper on credential helpers.

Another thing that could help you troubleshoot your problem is to review your Git configuration by running this command:

git config --list