43

git push failed with the following message:

remote: GitLab: Author '`SamLogan@logath-T460.mycompany.com`' is not a member of team

My #git config user.name and #git config user.email are set as:

#git config user.name
Sam Logan 

#git config user.email
SamLogan@mycompany.com

My hostname is logath-T460.

I am not sure why git push uses my localhostname with the Author. Any clue how to resolve this issue?

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
minil
  • 6,895
  • 16
  • 48
  • 55

3 Answers3

91

It's not git push that's using your username + hostname, it's git commit.

By default, if you did not set user.name and user.email BEFORE making a commit, git will get it from your computer name and hostname. It would also have shown you a warning like this:

Committer: user1234 <user1234@mac.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 file1.txt

When you do git push, it would just use whatever was set as the commit author and push it to the remote repo.

What I think happened, is that you already committed BEFORE you set the correct user.name and user.email settings. So those commits you're trying to push already has that invalid user details "SamLogan@logath-T460.mycompany.com" saved as the commit author.

What you need to do then is to update the author of the previous commits.

First, make sure to properly set the user.name and user.email config (--global or --local to the repo), otherwise known as your Git identity.

git config --global user.name "yourname"
git config --global user.email "yourname@youremail.com"

Set it now to the correct identity that matches the user account of your Gitlab repo.

Then use --reset-author on those commits.

  • To modify the author of only the most recent commit:
    git commit --amend --reset-author --no-edit
    
  • To modify the author of multiple past commits:
    (reference: How to amend several commits in Git to change author)
    git rebase -i HEAD~N -x "git commit --amend --reset-author --no-edit"
    
    where N is the number of previous commits you need to update. The rebase -i will show a command line editor to show you the changes, and --reset-author will use your current user.* settings. Just save and quit to apply to changes.

After that, git push should now work.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
  • 1
    Thank you. This fixed my issue. It was as simple as doing a git reset --hard HEAD and recommitting with my gitlab user. Not sure how it lost track of my id, but this fixed it. – oaklandrichie Dec 19 '20 at 00:17
  • 1
    @oaklandrichie Yeah, `git reset` would work too, but that undoes/removes the commits, which can be troublesome if you have long/complicated commit messages or you've split the commits into multiple/separate smaller ones. – Gino Mempin Dec 19 '20 at 05:22
  • 1
    Thank you, I staged changes with wrong username/email, it cased "push failed". "git commit --amend --reset-author --no-edit" - desided my problem. – Kate Apr 02 '23 at 20:56
30

I had this issue while migrating a project to a new Gitlab site. The solution that worked for me was to disable the option "Check whether author is a GitLab user" in my new project.

From Gitlab docs:

GitLab already offers protected branches, but there are cases when you need some specific rules like preventing Git tag removal or enforcing a special format for commit messages.

Push rules are essentially pre-receive Git hooks

push rule "Check whether author is a GitLab user":

Restrict commits by author (email) to existing GitLab users.

If this is your initial commit (as in my case) you might want to deactivate the GitLab user check just once and re-activate it for future commits.

The option is available from Gitlab Starter 7.10 and can be edited in the Web interface in settings/repository

enter image description here

See also: How to bypass: remote: GitLab: Author is not a member of team?

user2314737
  • 27,088
  • 20
  • 102
  • 114
  • 2
    kudos Your answer solved a problem I had for a while. Unchecking the "check whether author is a Gitlab user" actually solved it for me. This is what I needed to do, when using Project Access Tokens in Gitlab to run semantic release bot. :) – lars Jun 22 '21 at 13:24
  • you're the real MVP here... wtf was the last 30 mins of my life.. – Carl Boneri Mar 02 '23 at 23:43
0

This is because you have given wrong user details for the git config (user.name and user.email) with a pervious commit and hence it rejects the push.

Take a backup of the changes and do a hard reset as below

git config --global user.name "yourname"
git config --global user.email youremail@email.com

git reset --hard origin/<branch-name>

Now the code has been reset. Then you can restore the backed up changes and then do the commit again as below:

git add .
git commit -m "commit message"
git push

This should do a clean push without any errors.