63

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 "your_email@youremail.com"

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 = git@github.com:freeenergy/my-project.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[user]
    name = my name
    email = myEmail.com
Alex Borsody
  • 1,908
  • 9
  • 40
  • 74

8 Answers8

74

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 = me@mydomain.com

(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.

Bob Gilmore
  • 12,608
  • 13
  • 46
  • 53
  • 1
    interesting, my config file does not have this, despite running the command $ git config --global user.name – Alex Borsody Nov 27 '11 at 15:41
  • 4
    Check which `.config` files you have. There are three available [--system, --global or --file] and are searched in a particular order for inclusion of your author details. It's worth checking them all out. – Philip Oakley Nov 27 '11 at 23:10
  • 2
    in case you don't have any `~/.gitconfig`file, make one, or just use `$ git config --global user.name "You Name"` and `git config --global user.email johndoe@example.com` so git will create one for you. – Yar Oct 08 '15 at 18:41
  • 4
    Useful flag for `git config` : `-e` or `--edit`: Opens an editor to modify the specified config file; either --system, --global, or repository (default). – andrybak Oct 18 '15 at 11:08
40

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 "me@here.com"

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.

Ethan Mick
  • 9,517
  • 14
  • 58
  • 74
  • 3
    I stumbled upon this answer, and was impressed ... this is an excellent explanation, thank you, "The past is history" was very helpful. – Philip Tenn Sep 20 '13 at 21:07
  • 2
    Other tricks are to use ```git config --get-regexp 'user*'``` to see the current user settings, followed by ```git config --global user.name "My Name"```. – tgharold Oct 26 '15 at 19:01
  • ..or you can rebase to squash some commits you just pushed and force push again, if no one has worked on your branch yet. Or you have to use github.com script to do this and force push again. – WesternGun Jan 15 '19 at 13:34
23

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 = anna.kowalska@wp.pl
Ania
  • 231
  • 2
  • 2
  • 1
    No idea why my commits became "Unknown", but this method fixed it. Trying to set it with user.name and user.email in Git Bash did not solve it. Thanks – Arne H. Bitubekk Apr 08 '15 at 06:58
3

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"
Mohamed Reda
  • 1,207
  • 13
  • 21
2

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="your-old-email@example.com"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="your-correct-email@example.com"
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!

Mene
  • 3,739
  • 21
  • 40
2

Run you command line this way.

git init
git config user.name "someone"
git config user.email "someone@someplace.com"
git add *
git commit -m "some init msg"

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

endo.anaconda
  • 2,449
  • 4
  • 29
  • 55
0

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.

WesternGun
  • 11,303
  • 6
  • 88
  • 157
0

In my case there were lots of garbage in my .gitconfig file

git config --global --edit

This shows your content inside your .gitglobal and you get the abbility to edit your name and email manualy.

Marcel Zebrowski
  • 947
  • 10
  • 17