Git author Unknown

GitGithub

Git Problem Overview


my author name in all my commits is coming up as unknown https://github.com/freeenergy/Teacher-Login-Validation-Module

did this

$ git config --global user.name "Firstname Lastname"Sets the name of the user for all git instances on the system
$ git config --global user.email "[email protected]"

but still the author/committer name shows [unknown]

not knowing what I was doing I experimented with setting $ GIT_AUTHOR_NAME="my name" and it changed my name to my username [freeenergy] (I.E. my issue was fixed.) But when I switched back to my other computer the issue was the same.

my config file now looks like this but is still committing as [unknown]

[core]
	repositoryformatversion = 0
	filemode = false
	bare = false
	logallrefupdates = true
	symlinks = false
	ignorecase = true
	hideDotFiles = dotGitOnly
[remote "origin"]
	url = [email protected]:freeenergy/my-project.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[user]
    name = my name
    email = myEmail.com

Git Solutions


Solution 1 - Git

Even better than running git config, you can edit your ~/.gitconfig file directly. Look and see if there's a section for [user] with the relevant information. For example, my ~/.gitconfig has this...

[user]
	name = Bob Gilmore
	email = [email protected]

(There's no space in front of the [user], and single tabs in front of the name and email labels)

If it doesn't have those set properly, just go ahead and edit the .gitconfig file by hand.

Solution 2 - Git

I was having the issue of Github not properly linking my commits to my account. If you believe your email is correct, you should ensure that email is also in the Github settings for your account, as per this help page. The last section of caching is also good to note.

Copied in case of a catastrophic event in which Github goes down or ceases to exist.

Why are my commits linked to the wrong user?

GitHub uses the email saved in a commit's header to link the commit to a GitHub user. If you find your commits are being blamed on another user, or not linked to a user at all, you should check your settings.

Good to know: commit blame does not grant access to a repo. If you are seeing commits blamed on a user you do not know, don't worry. The user does not have access to your repo unless you've explicitly added them as a collaborator on that repo or to a team that has access to the repo.

Make them match

In order for GitHub to properly blame you for your commits, make sure your git email setting is correct and matches an email attached to your account.

Configuring git

To check your git setting, run this command:

$ git config user.email
# you@there.com

If this email is not correct, you can change the global setting:

$ git config --global user.email "[email protected]"

Good to know: if you work on multiple machines, you will need to check this setting on each one.

Attach the email to your GitHub account

If your email is not attached to your GitHub account you will need to add it for your future commits to be blamed correctly.

  1. Go to your Account Settings
  2. Click "Emails"
  3. Click "Add another email address"
  4. Enter the email address and click "Add"

The past is history

If you used an invalid email, or an email that's already attached to another account, then your previous commits will not be blamed correctly. While git does allow you to modify the repo's history and correct this, it is strongly discouraged to change commits which you've pushed to a remote repo.

In the case where your previous commits used the correct email, after you add the email to your account they will start to link. However, it may take some time for the old data to fall out of the server's cache before this happens.

Moving forward, if your settings match then all your new commits will be blamed on you and linked to your account.

Solution 3 - Git

I had to change the repository config file. Run from repository path :

> git config --local -e 

and add the whole section :

[user]
	name = Anna Kowalska
	email = [email protected]

Solution 4 - Git

In case you did already push your commits with a wrong user, you can rewrite the history using this script from github:

#!/bin/sh

git filter-branch --env-filter '
OLD_EMAIL="[email protected]"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="[email protected]"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_COMMITTER_NAME="$CORRECT_NAME"
    export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_AUTHOR_NAME="$CORRECT_NAME"
    export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags

Be aware of the effects a history rewrite has! If you are on a private branch you will propably be fine. On branches that are shared with other users you will need to coordinate with every other user and do a fetch on each clone. You need to decide if it's worth the effort. Have a backup!

Solution 5 - Git

Run you command line this way.

git init
git config user.name "someone"
git config user.email "[email protected]"
git add *
git commit -m "some init msg"

It works very fine for me when I encounter the same issue

Solution 6 - Git

I just found my recent push is with author "Unknown".

What I just did was to reset the last commit by git reset --mixed HEAD~1 and add, commit, and push -f by git-bash. Push by GitKraken always mess this up, but git-bash does it well. My suggestion is always check the author before push with git log.

Solution 7 - Git

I just solve it with this

git config --global user.email {my email}
git config --global user.name {my name}

you shouldn't put your email or your name inside "" or {}, for example:

git config --global user.name mohamed reda

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlex BorsodyView Question on Stackoverflow
Solution 1 - GitBob GilmoreView Answer on Stackoverflow
Solution 2 - GitEthan MickView Answer on Stackoverflow
Solution 3 - GitAniaView Answer on Stackoverflow
Solution 4 - GitMeneView Answer on Stackoverflow
Solution 5 - GitSulaimon OkikiolaView Answer on Stackoverflow
Solution 6 - GitWesternGunView Answer on Stackoverflow
Solution 7 - GitMohamed RedaView Answer on Stackoverflow