DEV Community

Cover image for GitLab: You cannot push commits for 'repo' You can only push commits that were committed with one of your own verified emails
Kyle Foo
Kyle Foo

Posted on • Updated on

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

If you are like me having multiples git accounts on sourceTree, working with multiple Version Control Provider like GitLab and Github etc. You may cloned a repo with one git account but accidentally commit something with another git account that does not have write access to the cloned repo.

Hell break loose, you're gonna get error like the following:

GitLab: You cannot push commits for 'email_without_access@mail.com' You can only push commits that were committed with one of your own verified emails
Enter fullscreen mode Exit fullscreen mode

Tried many times to re-configure your credentials on sourceTree properly but still failed to push? It is because your previous commit is done with an unverified account (without access right to the repo). In this case you need to reset the previous commit to the other author & committer with access right.

2 Steps to achieve that, here we go:

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

2) git -c user.name="Your Name" -c user.email=email_acct@with_repo_access.com commit --amend --reset-author

Go to sourceTree and view the last commit again, author and committer name should change, now click push and you are good to go :) Please note that it only works for most recent commit. If you have multiple commits with wrong committer, you may stop reading from here.

Trouble shooting:

(1) Is your git account has 2FA turned on?

If you are on 2FA, make sure you create personal access token on GitLab or GitHub and use that as password while sourceTree prompts you for password

(2) SSH or HTTPS path for remote git destination?

run git remote -v to see your remote origin path, it should display your current settings:
Alt Text

If you are on SSH and want to try HTTPS,
run git remote set-url origin https://gitlab.xxx.xxx.com/digital-office/applications-portals/mobile-application/sunshine.git

HTTPS path format works for me for both fetch and push as long as above config are set up correctly.

(3) If you are obligated to use SSH, please make sure you set them up properly, see tutorial:

GitLab: https://docs.gitlab.com/ee/ssh/#adding-an-ssh-key-to-your-gitlab-account

GitHub: https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

Latest comments (0)