2

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.

Nathan Wailes
  • 9,872
  • 7
  • 57
  • 95

3 Answers3

2

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:

printf "Host=github.com\nusername=xxx\nprotocol=https" | \

git credential-manager-core erase

On Mac:

printf "Host=github.com\nusername=xxx\nprotocol=https" | \

git credential-credential-osxkeychain erase

(As detailed in "Remove credentials from Git")

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you for responding. I tried this but it gave me an error, and I then looked into the docs enough to get it working, and it unfortunately still didn't resolve my problem. So it may be that the credentials are correct and that I'm instead not connecting to the repo appropriately. It may be that I need to use SSH, although I don't remember using SSH before for this repo or GitHub in general. – Nathan Wailes Jan 24 '20 at 22:47
  • @NathanWailes Check at least `git remote -v` to see what URL is used. – VonC Jan 24 '20 at 22:48
  • It's using https now. I've tried switching it to SSH before but nothing seems to work. – Nathan Wailes Jan 24 '20 at 23:49
  • If it is using https, do you have a `git config credential.helper` set? It could cache the wrong credentials for your private repo. – VonC Jan 25 '20 at 05:26
  • This command is no longer working for me. Follow this instead: https://stackoverflow.com/questions/15381198/remove-credentials-from-git – RayLoveless Feb 26 '22 at 01:12
  • 1
    @RayLoveless I agree. I have updated this to reflect the commands I mentioned in my other answer. – VonC Feb 26 '22 at 01:21
1

I got it to work by changing the remote URL to:

https://my-github-user-name@github.com/org/repo

workerbee
  • 243
  • 3
  • 8
0

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: enter image description here

enter image description here

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

Nathan Wailes
  • 9,872
  • 7
  • 57
  • 95