Unable to clone/fetch from private repo after creating new GitHub account

为君一笑 提交于 2020-05-28 03:44:29

问题


I'm a freelance developer who uses git and SourceTree.

I have been working for the past few months for a particular client who has a private GitHub repo, and I've been using SourceTree during that time to pull and push changes to GitHub.

I have another client who wanted me to create an 'Intro to Programming' course, and I (stupidly) just used my normal OS environment/user rather than creating a new OS user. I created a new 'demo' GitHub user and connected it to SourceTree so that I could show students how to push and pull from a GitHub repository. I also closed the SourceTree tab for my other client's repo.

I'm now trying to get back to working on my first client's project and I'm finding myself unable to fetch/pull from the remote repo, or even to re-clone the repo.

The error I see when I try to do a fetch or clone is:

git -c diff.mnemonicprefix=false -c core.quotepath=false --no-optional-locks fetch --prune origin remote: Repository not found. fatal: repository 'https://github.com/org_name/repo_name/' not found

Completed with errors, see above.

Things I've tried

I've:

  • logged out of the demo GitHub account in my browser,
  • removed the demo account from SourceTree,
  • restarted my computer
  • deleted any git/GitHub-related entries in my Windows Credential Manager, and was prompted to log in when trying to fetch
  • uninstalled and reinstalled SourceTree
  • I verified that I can clone another private repo that's under my GitHub account using both an HTTPS URL and also an SSH URL.

What I think is happening

At first I suspected that git was somehow still using that demo account when trying to access the private repo. However, I was able to add another GitHub repo from my GitHub account to SourceTree and fetch from it without problems, which presumably wouldn't have happened if git or SourceTree were still using my demo account's credentials.

At this point, I suspect there may be some problem in the way I'm trying to connect to the repository, but I'm not sure what it might be.


回答1:


Check your git config credential.helper.

If set, it might have cached the wrong user credentials for GitHub: you need to remove it.

On Windows:

git credential-manager reject https://github.com

On Mac:

git credential-osxkeychain erase https://github.com



回答2:


I finally got it working with the SSH URL.

I never got it working with the HTTPS origin URL. I have no idea why it doesn't work that way, that has to be the way that I was using it before because I didn't have any SSH keys set up on my GitHub account, so I couldn't have been using the SSH origin URL.

Here are the settings that worked for me:

I also had to convert my Putty-generated SSH key to the OpenSSH format and add it to my GitHub account.



来源:https://stackoverflow.com/questions/59889768/unable-to-clone-fetch-from-private-repo-after-creating-new-github-account

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!