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@example.com' You can only push commits that were committed with one of your own verified emails
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.
git commit --amend --reset-author --no-edit
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.
If you are on SSH and want to try HTTPS,
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
push as long as above config are set up correctly.