Git keeps mentioning my old username even if I can't find a trace of it
Asked Answered
V

8

16

remote: Permission to MYUSERNAME/project.git denied to OLD-USER-NAME

I have 2 GitHub users. One for personal use and one for work use. MYUSERNAME will be my personal one for this example and OLD-USER-NAME the work one. I've stopped using OLD-USER-NAME a while ago but I'm getting the above error when trying to push to a github https. I solved the problem by pushing directly to https://[email protected]...

I'm trying to figure out why my OLD-USER-NAME was even mentioned and how git "knows about it".

Things I've tried:

  1. ssh-add -l -> The agent has no identities.
  2. I couldn't find any .ssh folder.
  3. I don't have any ssh keys on both of my github accounts
  4. git config --global --edit or git config --edit shows MYUSERNAME
  5. git remote --verbose which gave me: origin https://github.com/MYUSERNAME/project.git (fetch) origin https://github.com/MYUSERNAME/project.git (push)
  6. OLD-USER-NAME GitHub -> Settings -> Security History I can see my ip with a green dot next to it. Maybe it got something to do with it?
Verena answered 24/12, 2013 at 22:23 Comment(8)
What happens if you cd to the .git folder of the repository and run grep -r OLD-USER-NAME .? If that shows nothing, you can pretty much rule out anything on the local system.Politesse
@DavidZ Great idea. I got no results. For MYUSERNAME I get a lot of results. If local system is out what else is there?Verena
Actually you can also run the same grep command from within your home directory if you have time to wait around for it. That way it'll catch things like ~/.gitconfig, ~/.ssh/config, and so on. (So I was wrong to say that running it from the repository git directory eliminates anything on the local system.) Of course I see that you have already checked those, but just in case...Politesse
@DavidZ Just did that. No results. Weird. Any point on doing it on all the drive and not just the home directory?Verena
I doubt it. I mean, if you want to assure yourself, and you have a lot of time, and you're not worried about overstressing the drive (probably not a big deal unless you have an old drive), then it couldn't hurt. But I would be very surprised if something outside your home directory is responsible for this. Already the behavior you're seeing is quite odd. Personally I would run strace -e trace=file git ... to see which files the command accesses and then focus on those, although I would do so with the understanding that it's unlikely to give the solution.Politesse
Or it might be time to contact github support.Politesse
@DavidZ There's a good chance I'll do that if I wont find a solution. Would you mind pasting your comments into an answer? Although it didn't solve my problem there's some great info here.Verena
Well, all I've posted is ways to get diagnostic information, it doesn't really constitute an answer. So I don't think it should be posted as one. (That being said, if you'd like to make my comments into an answer and post it yourself, that's definitely allowed.)Politesse
D
9

In addition to everything mentioned in the question and @gturri suggestions in the comments, the next step is to check whether git or the os are caching your credentials.

Check the keyring on your OSX / Linux / cygwin and also check if git config [--global] credential.helper has been set.

Dasteel answered 27/12, 2013 at 7:42 Comment(4)
Great advice. The git command returned error: key does not contain a section: [--global] but I did find my old username in my keychain under github.com. Does git command line can access that? I had no idea. I'll report back if that was the problem.Verena
The brackets just indicate that the argument is optional. Try git config --global credential.helper. In any case, if you remove your old user from the keychain, git won't be able to find it.Dasteel
Nothing happens. After taking a second look on my keychain, the github accounts are listed under kind: Internet password so I don't think that's it.Verena
Third look a charm. After I took another look in my keychain I noticed that the github item gave access to something called git-credential-osxkeychain so I'm guessing that keychain entry was in did the problem.. I'll know for sure after I'll push something.Verena
M
8

you should check your remote:

git remote --verbose

If it says

origin  [email protected]:OLD-USER-NAME/project.git (fetch)
origin  [email protected]:OLD-USER-NAME/project.git (push)

then your can fix it doing

git remote set-url origin [email protected]:MYUSERNAME/project.git
Massengale answered 24/12, 2013 at 22:27 Comment(3)
it says origin https://github.com/MYUSERNAME/project.git (fetch) origin https://github.com/MYUSERNAME/project.git (push)Verena
Then it wasn't the correct guess... Another attempt: try the ssh url rather than the https one, ie [email protected]:user/project.git rather then https://github.com/user/project.git. I'm not totally convinced, but I often had less issues with this urlMassengale
I'll try it on my next push. I'm just very curious from where git fetches the OLD-USER-NAME string. I couldn't find it anywhere on my system.Verena
C
5

I was having the same issue as the OP, and I'm not sure if he reported back, but the OSX keychain entry was my problem. After removing it, git push would prompt me for my user name and password.

Corkwood answered 13/1, 2014 at 10:0 Comment(1)
That was in did the problem. Forgot to accept the right answer above.Verena
C
0

So, I ran env GIT_TRACE_CURL=true git clone https://github.com/user/private-repo-path and found that it was sending an old username.

Then I tried all the different options in here. Finally, after researching I figured the issue was that old user and password were saved in .netrc file on my Mac.

Cyclotron answered 19/1, 2019 at 5:53 Comment(0)
F
0

git remote set-url origin "https://[email protected]/new_username/github-repository-name.git" It worked for me

Fanlight answered 27/10, 2021 at 14:19 Comment(0)
E
0

The way I solved this by deleting ssh key from my old account.

Esophagus answered 30/9, 2023 at 8:52 Comment(0)
B
0

I deleted ssh key, checked keychain, but nothing worked. Then came across one of the below ans, but it has password authentication based approach. Since password authentication is deprecated, you can do this (You need to ensure that you have your public ssh key saved in your github account):

git remote set-url origin "[email protected]:<username>/<repository>.git"
Boger answered 17/11, 2023 at 8:19 Comment(0)
V
-2

I was facing the same issue on July 15th, 2024.

The issue was that I was logged in with my old GitHub account in VS Code. I was able to fix the issue by signing out and signing in with my new one.

Voyeurism answered 15/7 at 15:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.