"You are not allowed to push code to this project" error on new project

I have a free GitLab.com account where I have multiple projects that I’ve done without issues over the years.

Yesterday I created a new project and when I tried to push changes to it I got this message:

$ git push
remote: ========================================================================
remote: ERROR: You are not allowed to push code to this project.

remote: ========================================================================
fatal: Could not read from remote repository.

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

Please note:

  • I am the owner of this account, and I created the project under my user, not in a organization
  • I have owner permissions on this repo
  • There are no protected branches on the repo
  • I am using a custom (not default) SSH key
  • I am able to clone and pull changes from the repo
  • I am able to make commits using the GitLab Web IDE

Please advise on what else I can investigate.

As the message says something is preventing you to push code. You are not saying if you are pushing to main (default) branch or some feature branch so I will consider both.

Since you claim you can pull I’d look at the project configuration. I’d start in Repository → Push rules. Maybe your local git config does not match some rule you have enabled?

main branch is protected by default on each new project, check if push is not restricted.

check your local repository, if you have correct remote setup and your local branch is set to reference correct branch on remote.

My problem was eventually SSH. I have misinterpreted the SSH output when I ran my git commands.

I was only able to pull changes because my repo was public. When I made it private, I couldn’t reach the repo.

The solution was to follow the steps for SSH key in different directories (or with different names): Use SSH keys to communicate with GitLab | GitLab
And to properly set the permissions for the .ssh directory and key files.