I have this new project which I’ve set up locally.
However, when I was pushing the initial code to the project, I got this error:
$ git push --set-upstream origin main --verbose
Pushing to gitlab.com:learning-repositories-x/godot/dodge-the-creeps.git
remote:
remote: ========================================================================
remote:
remote: ERROR: You are not allowed to push code to this project.
remote:
remote: ========================================================================
remote:
fatal: Could not read from remote repository.
I checked git log
and confirmed that the commit is made by my Personal Gitlab account.
I also checked my ~/.ssh/config
, which shows:
Host gitlab.com
Hostname gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/path-to-key
Host <some-work-username>.gitlab.com
Hostname gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/path-to-key-2
Debugging via ssh -v git@gitlab.com
, I saw that it connected to Gitlab via my work account, AND that it tried several other SSH keys I have (le gasp!!!).
This StackOverflow answer pointed me to the right direction:
Basically, I needed to add IdentitiesOnly yes
to get it to only use the defined IdentityFile
.