I have a weird situation with GitLab. I am working with an enterprise edition hosted by my institution. There is <url>/groupA/projectA
and <url>/groupB/projectB
. Both projects use the default permission sets for reporter, developer, maintainer, etc. In both projects, I am a developer. I use ssh authentication for both. When I do git remote -v
locally in each project, the only difference in the output is git@<url>:groupA/projectA
vs. git@<url>:groupB/projectB
.
Now the issue: everything works fine for project A. For project B, I can clone and pull without issue. I can also create branches, commits, and merge requests in the browser. However, creating a branch locally and pushing it results in the following message:
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.
Please make sure you have the correct access rights
and the repository exists.
I’m really at a loss here. I tried creating a fresh set of ssh keys and replacing the old one. The same behavior occurs: I can work fine with project A but cannot push to project B. The owner of project B has double checked all the settings and sees nothing that should prevent me from pushing. ssh git@<url>
gives the expected message:
PTY allocation request failed on channel 0
Welcome to GitLab, <username>!
Connection to <url> closed.
Any suggestions are welcome. I’m a very experienced Git and GitLab user and this is the first time I’ve encountered this. No suggestions on other pages have solved the problem yet, unfortunately.
Of course, right after posting this I finally found a solution I missed on another post: Unable to push to Gitlab, You are not allowed to push code to this project
The actual solution that worked for me was to create a second key and then do what James C said in his comment. Copied here for convenience:
I had something similar happen but I was trying to add a second gitlab account to my system. I had two ssh keys and tried to create an ssh config that used the second key. For some reason, even though it did try to use the key when I tested with ssh -Tvvv [email protected], it kept logging me in with the wrong identity. I ended up finding a solution on gitlab’s documentation page and did this to make it work: git config core.sshCommand “ssh -o IdentitiesOnly=yes -i ~/.ssh/private-key-filename-for-this-repository -F /dev/null” –
James C
CommentedJul 7, 2020 at 20:10
Edit
To further expound on what was happening (I didn’t understand this until it was fixed): I used to work at this institution under @username1
; I no longer work there, but work with them as a collaborator under @username2
. It turns out the ssh keys I’m using are associated with @username1
, which was a member of projectA
but not projectB
. So even though I can’t even login to the web interface using @username1
anymore, it was still authenticating me as @username1
over ssh. I think projectB
is set to be sufficiently public that it meant I could pull as @username1
and edit things in the web interfaces as @username2
, but could not push as @username1
. This is probably a very niche circumstance, but I wanted to share my findings to help some other confused soul in the future!