Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git commits are not getting linked with my GitHub account

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

like image 559
Charlyzzz Avatar asked Sep 23 '14 20:09

Charlyzzz


People also ask

Why are my commits not showing up on GitHub?

Commits must be made with an email address that is connected to your account on GitHub.com, or the GitHub-provided noreply email address provided to you in your email settings, in order to appear on your contributions graph. For more information about noreply email addresses, see "Setting your commit email address."

Why are my commits linked to the wrong user?

GitHub uses the email address in the commit header to link the commit to a GitHub user. If your commits are being linked to another user, or not linked to a user at all, you may need to change your local Git configuration settings, add an email address to your account email settings, or do both.


4 Answers

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 <[email protected]>. 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 [email protected].

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.

like image 73
stvnrlly Avatar answered Oct 13 '22 03:10

stvnrlly


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

git config --global user.email 

The CL would spit "[email protected]" which is wrong as it should display the email address without the "". So in my case the set-up was not properly done. Hope it helps.

like image 32
Roger G Avatar answered Oct 13 '22 02:10

Roger G


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="[email protected]"
    CORRECT_NAME="correct-username"
    CORRECT_EMAIL="[email protected]"
    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="[email protected]"
    CORRECT_NAME="correct-username"
    CORRECT_EMAIL="[email protected]"
    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="[email protected]"
    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="[email protected]"
    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://[email protected]':
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!
like image 3
purple_monster Avatar answered Oct 13 '22 04:10

purple_monster


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.

like image 1
La-comadreja Avatar answered Oct 13 '22 03:10

La-comadreja