-1

I have all the settings configured in a way that appears correct, but git is still defaulting to an incorrect username.

I have the following set in git config:

alias.hist=log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=git@github.com:CORRECT_USER/project
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
user.email=ID+CORRECT_USER@users.noreply.github.com
user.name=CORRECT_USER

And it looks good.

My /.ssh/config also has:

Host github.com-CORRECT_USER
    HostName github.com
    User CORRECT_USER
    IdentityFile ~/.ssh/CORRECT_USER_KEY

So it looks good, too.

However, when I...

git push 

I get:

ERROR: Permission to  denied to TOTALLY_DIFFERENT_WRONG_USERNAME.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

What is happening that git is trying to push the right repo, with the right username, and the right ssh/config using the TOTALLY_DIFFERENT_WRONG_USERNAME? Where would that be set and how can I unset it?

Mittenchops
  • 18,633
  • 33
  • 128
  • 246

1 Answers1

1

Running:

$ ssh -Tv git@github.com

Will show which identity your ./ssh/config is actually connecting with in this repository.

In this case, it looks like it ran:

debug1: /etc/ssh/ssh_config line 19: Applying options for *

And went with your default username, which is TOTALLY_DIFFERENT_WRONG_USERNAME.

You can create different configs like so:

# user1
Host github.com
    HostName github.com
    User user1

# user2
Host github.com
    HostName github.com
    User user2
Mittenchops
  • 18,633
  • 33
  • 128
  • 246