48

I'm having problems trying to link my commits to my GitHub account. Commits are being reported on GitHub the way my picture shows. The values user.name and user.email are correct, any other ideas to check?

Thanks in advance

Commit example

La-comadreja
  • 5,627
  • 11
  • 36
  • 64
Charlyzzz
  • 590
  • 1
  • 4
  • 8
  • I am having the same issue but unlike the OP's tag, which implies that the commits are coming from Eclipse, I am making the commits via the command line. My Github photo (same as my StackOverflow photo) is not appearing on the commits and they are also not appearing on my "Contribution activity". I'm not sure how to fix this and any help would be appreciated. – La-comadreja Oct 14 '14 at 17:42
  • 1
    @La-comadreja What protocol are you using to push to github.com? In case you don't know, please run `git remote -v` and report what it looks like ([git protocols](https://gist.github.com/grawity/4392747#protocols-to-choose-from-when-cloning)). – Dennis van der Schagt Oct 14 '14 at 18:03
  • Here is the result for git remote -v: origin git@github.com:/La-comadreja/git_test.git (fetch) origin git@github.com:/La-comadreja/git_test.git (push) – La-comadreja Oct 14 '14 at 18:12

8 Answers8

81

Even though your settings might look correct, this error implies that something in the user.email field is incorrect, which gives Github the wrong information about who the committer is. A small typo could throw the whole thing off. The fix is in the third step, and the first two steps help identify what the problem is.

First, run git config -l to check your settings and make sure that you don't have something unexpected in there. Run git log and take note of how the Author field looks. It should be in the format of Author: Your-Name <your-github-email@example.com>. The part within the brackets is the important part as far as Github is concerned.

Second, if you've been able to commit something successfully in the past, open that repo and run git log to find the commit where everything worked properly. Check that Author field against the one that isn't working and see if there is a difference.

Third, if there is a difference, switch back to the repo at issue and run git config --global user.email correct-email@example.com.

If the problem persists, check your Github email settings and make sure that the email address that you are using is added to your account.

See this help article for more information.

stvnrlly
  • 893
  • 5
  • 6
  • Thanks. I've changed email on Github as well, so it should be the same. As for Username, "Author" is my personal name when I type "git log", but my Github Username when I look at the same commit on git. So it seems something funny is going on with "user.name" – La-comadreja Oct 14 '14 at 19:06
  • I've just tested this. I could fill in whatever I want for `user.name` and it still works, but if I change `user.email` to something else I observe the same behavior as @user3610070 and @La-comadreja. – Dennis van der Schagt Oct 14 '14 at 19:26
  • By the way - I just updated my email address on Github and my user.email is the same as this new email, I believe. – La-comadreja Oct 14 '14 at 19:59
  • 1
    You can set the `global` flag with the `git config` commands to change the respective settings for all repositories (if not overridden by specific repository settings) like this `git config --global user.email "test@example.com"`. Changes to `user.name` and `user.email` will only apply to new commits. – Dennis van der Schagt Oct 14 '14 at 20:42
  • 1
    Thanks, @dennisschagt, those are all good points. I'm updating my answer to reflect those suggestions. – stvnrlly Oct 14 '14 at 21:18
  • Hey I followed each and every step given by you but still the commits are shown not by my github id but someone else's github ID. Why is it so ? – Sagar Barapatre Jul 02 '21 at 02:42
  • 1
    After running `git config -l` look towards the top of the output and you will see `user.email=`. This is probably where the problem lies. You may have something automatically set by your computer. So run the `git config` command above and you'll be on your merry way :) – Anthony Avila Oct 04 '22 at 10:08
8

I had a similar issue and stvnrlly's response was useful. In my case when running:

git config --global user.email

the CL would spit out "email@email.com" which is wrong as it should display the email address without the "". So in my case the set-up was not properly done.

Josh Correia
  • 3,807
  • 3
  • 33
  • 50
Roger G
  • 181
  • 2
  • 2
4

I also came across this issue today, but in my case, the commits were pretty old and I found the issue after committing using erroneous details for a week. So this answer is for when you find your older commits are not linked to your GitHub. First correct your git config settings as has been mentioned already.

Now, to modify your commit history follow these steps:

  1. Go to your working directory and clone your repo
$ cd working_dir
$ git clone --bare https://github.com/user/repo.git
  1. Go to the cloned directory
$ cd repo.git
  1. Your commits might be unlinked to your original GitHub due to various reasons, i.e. incorrect/old email, incorrect/old username, etc. Also, your commit and/or authorship details might be incorrect. I list down different steps for different cases.

    3.1 Incorrect email linked

    If commit details are incorrect:

    Paste the following code in your command line.

    git filter-branch --env-filter '
    OLD_EMAIL="old@email.com"
    CORRECT_NAME="correct-username"
    CORRECT_EMAIL="correct@email.com"
    if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
    then
      export GIT_COMMITTER_NAME="$CORRECT_NAME"
      export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
    fi
    ' --tag-name-filter cat -- --branches --tags
    

    If author details are incorrect:

    Paste the following code in your command line.

    git filter-branch --env-filter '
    OLD_EMAIL="old@email.com"
    CORRECT_NAME="correct-username"
    CORRECT_EMAIL="correct@email.com"
    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
    

    Here, replace OLD_EMAIL with your old email address, CORRECT_NAME with your current username, and CORRECT_EMAIL with your current correct email address.

    You can check your old email address(es) using the command: git log --pretty="format:%ae"

    3.2. Wrong username linked

    If commit details are incorrect:

    Paste the following code in your command line.

    git filter-branch --env-filter '
    OLD_NAME="old-username"
    CORRECT_NAME="correct-username"
    CORRECT_EMAIL="correct@email.com"
    if [ "$GIT_COMMITTER_NAME" = "$OLD_NAME" ]
    then
      export GIT_COMMITTER_NAME="$CORRECT_NAME"
      export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
    fi
    ' --tag-name-filter cat -- --branches --tags
    

    If author details are incorrect:

    Paste the following code in your command line.

    git filter-branch --env-filter '
    OLD_NAME="old-username"
    CORRECT_NAME="correct-username"
    CORRECT_EMAIL="correct@email.com"
    if [ "$GIT_AUTHOR_NAME" = "$OLD_NAME" ]
    then
      export GIT_AUTHOR_NAME="$CORRECT_NAME"
      export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
    fi
    ' --tag-name-filter cat -- --branches --tags
    

    Here, replace OLD_NAME with your old name/username appearing on commits, CORRECT_NAME with your current username, and CORRECT_EMAIL with your current correct email address.

    Your output should look something like this:

    Rewrite c9ef481aca2cbeac930da8b1250c7f81ac779372 (19/20) (2 seconds passed, remaining 0 predicted)
    Ref 'refs/heads/main' was rewritten
    

    If your output looks like this, move to step 4.

  2. Push the modified history to your original repository.

$ git push --force --tags origin 'refs/heads/*'

Your output should look something like this:

Username for 'https://github.com': user
Password for 'https://user@github.com':
Enumerating objects: 96, done.
Counting objects: 100% (96/96), done.
Delta compression using up to 40 threads
Compressing objects: 100% (48/48), done.
Writing objects: 100% (94/94), 852.67 KiB | 42.63 MiB/s, done.
Total 94 (delta 41), reused 77 (delta 40)
remote: Resolving deltas: 100% (41/41), done.
To https://github.com/user/repo.git
 + 4777199...1f210c5 main -> main (forced update)
  1. Get out of the cloned repository directory and delete it.
$ cd ..
$ rm -rf repo.git
  1. Your updates should now reflect on your commit history!
Muhammad Tariq
  • 3,318
  • 5
  • 38
  • 42
  • Does this still work? It did not work for me. Also, pro tip make sure you enter the commands exactly. I tried to be smart and didn't set the CORRECT_NAME parameter because I didn't need to change my username, but that ended up giving me a fatal: empty ident name error – Some Guy Apr 19 '23 at 05:13
2

If you received your e-mail address from gmail, and in "." If there is a sign, like me, you may have encountered such trouble. For example, if your original e-mail address is test.code@gmail.com and you have registered as testcode@gmail.com when you register with github, you are very likely to encounter this error.

As a solution; you need to link both email addresses to your github account.

Maifee Ul Asad
  • 3,992
  • 6
  • 38
  • 86
Muhammet Can TONBUL
  • 3,217
  • 3
  • 25
  • 37
1

Here are the exact steps of how I solved the problem.

(1) The user.name field in my ~/.gitconfig file did not need to match what I had on Github. However, the user.email field in ~/.gitconfig needed to be an exact, letter-by-letter match to the email field on Github.

(2) The relevant email field on Github is under "Settings" (the icon on the upper right that looks like the gear) and then, rather than resetting the email in "Your Profile" (this aspect of the instructions is what confused me), I needed to actually click on the section of Settings called "Emails" and add the new email address I had in user.email. I followed the instructions on Github to verify this email address. I did not need to make this email address "primary" to fully synchronize my computer with my Github account.

File paths and names are standard for Mac OS X. Thanks @stvnrlly, I used the general gist of your answer.

La-comadreja
  • 5,627
  • 11
  • 36
  • 64
1

As far as I know, you need 3 configuration, to commits get linked to your account :

  • user.email
  • user.name
  • user.username

user.email : here goes your email, that you have used to create your account or currently linked to your account. Not xyz@github.com, but xyz@gmail.com

user.name | user.username : you need both, and both should have the same value. It is available in your account's url, profile everywhere.

How to set these values:

git config --global user.email "xyz@gmail.com"
git config --global user.name xyz
git config --global user.username xyz

Check these values have been set or not:

git config --global --list
Maifee Ul Asad
  • 3,992
  • 6
  • 38
  • 86
0

I just added my work email to the secondary GitHub email

-2

You have to get the reference for the remote repo first.

git remote add origin https://github.com/yourGithubAccount/yourRepo.git

then do git push -u origin master.

Deke
  • 4,451
  • 4
  • 44
  • 65