4

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?

4 Answers 4

11

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
  • 1
    not working for me cause i have multiple commits
    – dermoritz
    Jul 1, 2021 at 8:23
7

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.

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

3

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
  • 2
    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
  • Yes, you are right, I meant reset, not revert! I've edited it.
    – Balint
    Jul 1, 2021 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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