Reputation: 1192
I have a local git repo that I'm trying to push to a Gcloud source repo that I've created. Everything seems to be fine, except for when I try to push I get:
fatal: remote error: Access denied to [email protected]
I've gone thru these steps to get gcloud to use correct git credentials, but to no avail. I currently have 2 gcloud configurations on my computer, and have set the second configuration to be active. However, running git push google master
to push to gcloud source repo will always try to use email1
which is for configuration 1. I want to use email2
which is for configuration 2 - the active configuration - but I can't figure out how and can't seem to find any docs on it.
Any help is appreciated!
Upvotes: 3
Views: 1181
Reputation: 21
I encountered similar behaviour and the problem in my case was caused by ~/.gitcookies
file containing stored credentials for "[email protected]"
After editing/removal of this file, git started correctly using gcloud credentials helper.
Upvotes: 2
Reputation: 8980
When you run
$ gcloud source repos clone hello-world
in current configuration, gcloud will under the hood set git credential helper to always point to same account the repository was cloned with. You can see it with
$ git config -l
credential.helper=!gcloud.cmd auth git-helper [email protected] --ignore-unknown $@
So later switching gcloud
configurations or setting new gcloud
account will not change how this repo is authenticated.
I am not sure why you want to clone repo with email1 and then push to it with email2.
You can always change this be running
$ git config credential.helper \
'!gcloud.cmd auth git-helper [email protected] --ignore-unknown $@'
If you want for some reason to always use active configuration, simply omit --account
when setting credential helper.
Upvotes: 1
Reputation: 326
First thing I would check would be the permission on IAM on Google cloud for the user attempting to write to the GCR. To write to the Google Cloud Repository (GCR) you will need to have the correct permissions assigned prior to writing to the repository. When you use the gcloud sdk, the user credentials need to match with that in the IAM or you will encounter a lot of permission denied messages.
If you are unable to use the gcloud interface to access GCR, then you can test interaction using the cloud shell interface which will have the necessary service account access to your project. Personally, I would recommend using cloud shell in most cases over connecting through gcloud SDK.
Upvotes: 0
Reputation: 1327004
gcloud source repos clone
clones a git repository from the currently active Google Cloud project into the specified directory or into the current directory if no target directory is specified.
The clone operation configures the local clone to use your gcloud credentials to authenticate future git operations.
This should be an https URL, which means there is a credential helper which caches the credentials (username/password)
In your cloned repository, type:
git config credential.helper
If it is not git-credential-gcloud.cmd
(as in this issue) or if git-credential-gcloud.cmd
is not in your %PATH%
(where git-credential-gcloud.cmd
should return a path), it would not work.
Note: now the credential helper might be called simply gcloud.cmd
git config credential.https://source.developers.google.com.helper
If you don't have access to gcloud.cmd
, you will need to generate static credentials.
Upvotes: 0