Search code examples
google-cloud-platformgcloud

gcloud auth login does not update/identify my active account correctly for git usage


I have been trying to log with a new corporate account in order to push some code in gcp Cloud Repository. Despite all my attempts at logging in with the new user, somehow when I issue git push it still tells me

ERROR: Your current active account [old_email@domain.com] does not have any valid credentials
Please run:

  $ gcloud auth login

to obtain new credentials.

For service account, please activate it first:

  $ gcloud auth activate-service-account ACCOUNT
            Run 'gcloud auth login' to log in.
Username for 'https://source.developers.google.com':

When I run gcloud auth list only the new corporate email <new_corporate_email>@domain.com is displayed.

Here are the steps I took

  • gcloud auth login
  • gcloud auth login --no-launch-browser
  • gcloud auth application-default login
  • gcloud config set account <new_corporate_email>@domain.com
  • git config --global user.email "<new_corporate_email>@domain.com"

Where is the current active account stored and how do I refresh its value? Could this be strictly a git issue?


Solution

  • I suspected it was a problem with git and its relationship with gcloud since I am using Google Cloud Source Repositories.

    What I did was not solve this solution perse, but I offer you a workaround in case you get the same error. Here are the steps I applied to "fix" it:

    1. I made sure I was logged with the right account on gcloud
    2. I made sure that account had the right IAM rights within the GCP project
    3. I backed up my source repo (thankfully, only these few last changes were missing from my remote repo)
    4. I deleted the original local source code repo and recloned it using gcloud
    5. I took the changes from my backup folder via rsync
    6. I tested a commit & push and it worked