'Cloud Shell git repository not found after repo move

After creating a new organisation on GitHub and moving the repo from the old organisation to the new one I get the error message: "fatal: repository 'https://github.com/newOrganisation/repo.git/' not found" when doing git push within the Cloud Shell.

Within Cloud Shell I never have to input a personal access token to be able to do git push, on my local machine I do have to input it. Therefore I assume my git credentials are somehow stored within Cloud Shell and need to be updated, I just do not know how. Any help would be appreciated.

What I have tried out so far:

  1. Cloned the repo to my local machine and pushed a commit --> everything worked fine
  2. Compared git config -l on both machines, user.email and remote.origin.url were the same


Solution 1:[1]

Although you can workaround with:

git remote remove origin 
git remote add origin https://[personal-access-token]@github.com/username/repo_name.git

Cloud Shell is just a Debian-based Linux distribution which includes Git pre-installed.

As it is told in this issue tracker report, we don't do anything special with git credentials in Cloud Shell. As long as the credentials are in the user's home directory, they will be persisted across sessions. Otherwise, Cloud Shell works the same as any other Linux VM, so it's possible the user messed up their global or repo git configuration somewhere.

As you can read here, the git credentials can be stored in ~/.git-credentials but also in another file like ~/.my-credentials. The “store” mode saves the credentials to a plain-text file on disk, and they never expire. This means that until you change your password for the Git host, you won’t ever have to type in your credentials again. The downside of this approach is that your passwords are stored in cleartext in a plain file in your home directory.

You can also find your credentials as described here in .git/config file. In Cloud Shell, you can find it in ./cloudshell_open/python-storage/.git from your $HOME directory. config is the local configuration file, as you can read in this post.

As established here, the Git configuration file contains a number of variables that affect the Git commands' behavior. The .git/config file in each repository is used to store the configuration for that repository, and $HOME/.gitconfig is used to store a per-user configuration as fallback values for the .git/config file. The file /etc/gitconfig can be used to store a system-wide default configuration.

With this respect, there’s no particular configuration related to Cloud Shell.

In other case, when authenticating with git, if you're working with Cloud Source Repositories, Cloud Shell handles authentication for you automatically. If that’s your case, you could view your repository settings and display your repository location. This could be outdated with the previous one before you move it to the new organization.

Probably you also need to toggle between your repositories to connect to the one that is in your new organization. This updates your Source Control: Git panel with the context of your chosen repository.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1