1

Please note: I know this question may seem similar to this one and perhaps others, but I assure you it is not a duplicate because I was able to pinpoint a more specific problem than those other questions, and I believe my specific problem commands a unique/distinct answer.


Mac OSX 10.13.6 here.

I am a committer on a few different git/GitHub repositories. I have made several commits to these repos using once GitHub user (let's call it "some.random.dev1.example.com" or SRD1 for short). I now need to make some commits to the same repos but from a different GitHub user, let's say "some.random.dev2.example.com" or SRD2) from the same machine.

So I updated my user.name, user.email and user.username fields in ~/.gitconfig to match those for my SRD2 user. I then, for good measure, cleaned out 2 different github.com keys in my OSX Keychain Access manager.

I also removed two old SSH and GPG keys that were associated with my SRD1 user, and replaced them with two new ones associated with my SRD2 user.

I just went to pull one of the repos (to pull down any changes made by other developers in the last few months) and I got:

$ git pull
remote: Repository not found.
fatal: repository 'https://some.random.dev1.example.com@github.com/IdeaEvolver/cutter-platform-app.git/' not found

So it seems that when I do a git pull on a repo, its defaulting (somehow) to pull with my some.random.dev1.example.com user (which no longer has access to the repo). I want to be using only my SRD2 user from here on out. How do I override this default, and where is this default stored?

Everyone
  • 23
  • 8
hotmeatballsoup
  • 385
  • 6
  • 58
  • 136
  • Is your real question why you cannot pull from two different GitHub repos? – Greg Burghardt Jan 19 '21 at 17:48
  • Why would you think I'm pulling from two different repos @GregBurghardt? They are the same repo. I'm trying to pull from the same repo but with a different **user** ("SRD2"). FWIW, SRD2 does have access to the repo. – hotmeatballsoup Jan 19 '21 at 17:53
  • Ok, so your question is how to pull to the same repository using two different user. Can you update your question title? It was a little hard to understand the true question. – Greg Burghardt Jan 19 '21 at 18:10
  • Have you tried the solutions proposed in [Git - remote: Repository not found](https://stackoverflow.com/q/37813568/3092298)? It's an older question with no accepted answer. – Greg Burghardt Jan 19 '21 at 18:13
  • Well I think its a little more complicated than that. The question is more about understanding why simply running `git pull` is using a user _other_ than what is stored as my `user.username` inside `.gitconfig`, which was my understanding of the location where such information is stored. So if its not using `.gitconfig`, where is it getting my SRD1 username from? – hotmeatballsoup Jan 19 '21 at 18:13
  • Yes, if you read my question, you'll see I deleted the GH keys out of my Keychain Access manager, which was the solution proposed in the link you provided. – hotmeatballsoup Jan 19 '21 at 18:13
  • Silly question. Have you tried rebooting? I know you are on MacOS, but if Git caches credentials, maybe a reboot will help. – Greg Burghardt Jan 19 '21 at 18:13
  • I just restarted and still the same result, but it was worth a try! – hotmeatballsoup Jan 19 '21 at 18:17
  • Do you have any SSH keys in your `~/.ssh` directory? – Greg Burghardt Jan 19 '21 at 18:18
  • Yes I do have several that I've used for various reasons over the years, one of those keys was an SSH key I used in conjunction with my SRD1 (old) GitHub user, however I have added it as an SSH key with my SRD2 GitHub user as well (perhaps thats the root of my problem). – hotmeatballsoup Jan 19 '21 at 18:25
  • Might be? Hard to tell. I would recommend using different SSH keys for different remotes. I'm pretty sure the SSH key also has a username in it. If you reused SSH keys, it might be referring to your GitHub username. Although that might only be a problem if you have two different usernames... – Greg Burghardt Jan 19 '21 at 18:28
  • If you look at the output from the SourceTree console, it looks like its trying to use HTTPS though, right? And still failing?! Am I reading that wrong? – hotmeatballsoup Jan 19 '21 at 18:30
  • Yup, it sure is. You should see `ssh://user@domain/path/to/repo.git` if you need to authenticate by SSH key. – Greg Burghardt Jan 19 '21 at 18:31
  • OK I removed an SSH key that was associated with my old SRD1 user (let's call it `~/.ssh/srd1`. And I generated a new SSH key for my new SRD2 user (let's call it `~/.ssh/srd2`). I also generated a new GPG key that I will (eventually) use for making signed commits and added it to my SRD2 GitHub settings/account. But still, when I go to do a simple `git pull` from the repo, it still thinks my old SRD1 account is the one doing the pull. – hotmeatballsoup Jan 19 '21 at 19:04
  • Does it work when rebooting the device? It might be cached in the RAM. – dan1st Jan 19 '21 at 19:08
  • 1
    Look in that repo's `.git/config`. You're using an https URL, so ssh and gpg have nothing to do with it. `git remote -v` will also prove useful. – Schwern Jan 19 '21 at 19:10
  • Hey! Thanks @Schwern (+1) !!! Yes, in that file I see `url = https://some.random.dev1.example.com@github.com/SomeExampleOrg/SomeRepo.git`. Can I just modify that directly to use my new user instead? Will that affect git history or muck with anything else git-related? – hotmeatballsoup Jan 19 '21 at 19:13
  • I think that just tells git where to push and pull from. – Greg Burghardt Jan 19 '21 at 19:14
  • Looks like you've got the user hard coded in the remote's URL. You could edit the file, but the command line is safer. Don't hard code your username, that's what caused this problem, use the URL provided by Github. `git remote set-url origin https://github.com/SomeExampleOrg/SomeRepo.git`. None of this will change your Git history. See https://docs.github.com/en/github/using-git/which-remote-url-should-i-use for more. – Schwern Jan 19 '21 at 19:16

1 Answers1

1

Git stores information about the repository within the repo's .git/config. It can be edited by hand, but it's better to use the command line tools such as git remote. git remote -v will show the URLs used by your repository.

in that file I see url = https://some.random.dev1.example.com@github.com/SomeExampleOrg/SomeRepo.git

I also removed two old SSH and GPG keys that were associated with my SRD1 user, and replaced them with two new ones associated with my SRD2 user.

Since you're using an HTTPS url, neither SSH nor GPG have any affect.

So I updated my user.name, user.email and user.username fields in ~/.gitconfig to match those for my SRD2 user.

Authentication does not use user.name nor user.email, they are only used for committing. There is no user.username. See git-config for all the config options.

Your actual credentials are stored using a credential helper which on OS X means the keychain.


You've hard-coded your username in the repository URL. Change it so it's just the URL provided by Github.

git remote set-url origin https://github.com/SomeExampleOrg/SomeRepo.git

See Github's Which remote URL should I use? for more.


Will that affect git history or muck with anything else git-related?

If you use the same URL, minus the username, it will not change anything but your authentication. It will not affect your Git history.

If you used a different URL pointing at a different repository then yes, git pull would try merge your local branches with a different remote. If the repository is unrelated it would refuse to pull.

Schwern
  • 153,029
  • 25
  • 195
  • 336