20

I am having this weird issue where I cloned a repository with my credentials (my_correct@email.adress). But I can not push the changes because I always receive this message:

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

The issue is that when I check the global and the repository users I find it is my_correct@email.adress:

Global (below confirms my correct address):

git config  --global user.email
git config  --global user.name

Repository (below confirms my correct address):

git config  user.email
git config   user.name

What should I do and what is the reason behind this mysterious mystery?

6 Answers 6

27

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

1
  • 2
    not working for me cause i have multiple commits
    – dermoritz
    Jul 1, 2021 at 8:23
16

In my case there 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.

6

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.

2
  • 3
    AFAIK reverting does not remove the commits from your local branch, i.e. you will still be pushing someone else's commits... maybe you meant resetting the branch BEFORE that unwanted commit, then applying a patch with all the commits you want Feb 5, 2021 at 16:03
  • 1
    Yes, you are right, I meant reset, not revert! I've edited it.
    – Balint
    Jul 1, 2021 at 9:19
4

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].

1

You can disable the pushing restrictions so that you don't need to go through all the commits and change the email.

enter image description here

0

I couldn't find the solution here because all of my .gitconfig's have the correct and authorized emails to push to upstream. In my team, I've found out a logical solution for this, and the reason we can't find the correct solution seems like because of gitlab's misleading error message. The problem is not about our current commit's author in general. We encounter cases where a branch deleted in the origin couldn't be updated in local. So the solution that worked for me and many of my colleagues is below:

git remote update origin --prune

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.