GitLab: You cannot push commits for . You can only push commits that were committed with one of your own verified emails

Solution 1:

I was able to fix the same issue using this git command:

git commit --amend --reset-author --no-edit

I initially tried to commit with the wrong email but even after setting user.name and user.email in git config --global to the correct one, I kept getting the same "You cannot push commits for..." error above.

The solution was resetting the author in git - then the push was accepted to Gitlab.

For reference: https://github.com/git-tips/tips#revert-undo-a-commit-by-creating-a-new-commit

Solution 2:

In My Case there was a restriction was a Committer restriction in project on gitlab. "Users can only push commits to this repository that were committed with one of their own verified emails." since i configured SSH also with my machine, so my user email was updated in git global file with my machine's address, hence remote was not allowing to PUSH.

you can find this at- gitlab-> settings -> Repository -> Push Rules ; just disable this commit restriction and it will work.

Solution 3:

You need to ask an administrator for the repo you cloned your project from to remove the committer restrictions from the push rules on your repo. See [Enabling push rules][1][https://docs.gitlab.com/ee/push_rules/push_rules.html#enabling-push-rules].

Solution 4:

git commit --amend --reset-author --no-edit only changes author in the last commit, if you have multiple commits, you still won't able to push.

Check it with git log, and reset every commit with the improper author and commit again.