2

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
JShinigami
  • 7,317
  • 3
  • 14
  • 22
  • Note that GitHub will claim that a private repository does not exist (rather than cannot be accessed) if you have not provided proper credentials. So this looks like a credential-providing issue. (That's what you concluded as well.) – torek Apr 01 '22 at 20:50

1 Answers1

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.

Osvaldo
  • 473
  • 1
  • 12
  • Unfortunately I am not working with Cloud Source Repositories, it is GitHub. – JShinigami Apr 04 '22 at 05:07
  • Have you [check this post](https://stackoverflow.com/q/37813568/17544309) to see if any solution works for you? You could try `git push ` or other git push related options as described in [this doc](https://git-scm.com/docs/git-push) to update your push destination. This doc also establishes that when the command line does not specify where to push with the argument, `branch.*.remote` configuration for the current branch is consulted to determine where to push. If the configuration is missing, it defaults to origin. – Osvaldo Apr 05 '22 at 18:21
  • 2
    Thank you. It seems that this is working: ```git remote remove origin``` and ```git remote add origin https://[personal-access-token]@github.com/username/repo_name.git``` Nevertheless it seems to be another way of pushing this repo than for my other repos. It would be great if I understand how the credentials are stored withing Cloud Shell, becasue then I could use the same method for all repos/organisations. – JShinigami Apr 06 '22 at 07:05
  • was this answer useful? – Osvaldo Apr 15 '22 at 14:07
  • Yes it was useful, I have managed to push the repo. Do you also know how the credentials are stored within Cloud Shell, so I can solve the underlying issue? – JShinigami Apr 18 '22 at 05:59
  • I updated my answer. Does the update solve your underlying issue related to how the credentials are stored within Cloud Shell? – Osvaldo Apr 21 '22 at 14:31
  • Thank you. Unfortunately there is no ```~/.git-credentials``` and also no custom file. I also double checked via ```git config --global -l``` there is no path to a custom file stored, only user.email and user.name are stored. – JShinigami Apr 28 '22 at 07:09
  • I wrote a new update to my answer. Please, let me know if that solves the underlying issue. – Osvaldo Apr 28 '22 at 19:36
  • Thank you. The right repo seems to be connected. But I am using VS Code's "Code Server" and not the default Cloud Shell editor Theia. Can it be that "Code Server" somehow stores the credentials? – JShinigami Apr 29 '22 at 05:56
  • Because Cloud Shell is not the same as VS Code's Code Server, please, as a best practice in Stackoverflow, create a new post for your question related to VS Code's "Code Server". The VS Code Server is a component of the Remote Development extensions and is managed by a VS Code client. Meanwhile [this article](https://code.visualstudio.com/docs/remote/faq) may help you. – Osvaldo May 05 '22 at 15:59