28

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?

7 Answers7

34

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

18

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.

Anurag
  • 181
7

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.

Balint
  • 171
6

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

Jeff Tian
  • 247
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

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
0

Updating email and name in history seems to be the thing to do https://stackoverflow.com/questions/750172/how-do-i-change-the-author-and-committer-name-email-for-multiple-commits

change-commits using filter-branch seemed to be a good option, but requires being applied to each branch and can get quite messy. This option didn't work for me.

Applying amend reset author across all commits did resolve for me

git rebase -r --root --exec "git commit --amend --no-edit --reset-author"