Home > Net >  How does GitHub decide which account made a commit. Does it have to do with personal access tokens?
How does GitHub decide which account made a commit. Does it have to do with personal access tokens?

Time:01-16

I am relatively new to git. I have been using the same computer and own two different GitHub accounts. Let's call it old one and new one. I used old one long time ago and now when I tried to commit changes to the repository of my new account, it shows the commit changes are made by my old one.

I tried to change that by using this command:

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

Now after visual studio code asked me for my personal access token, whenever I commit, it shows that my new account is making those changes. Also, I can swap between these two accounts by simply using the command above. My questions are:

  1. How come GitHub knows that it is in fact me committing changes using two different accounts not some random guys, is it because of the personal access token that cached on my computer?
  2. If the personal access tokens are cached on my computer, where can I locate it and possibly delete or modify them?

CodePudding user response:

Commit authorship is tracked by git, not GitHub

If you run git log, you will see an email address associated with each commit. This data is "burned" into the commit. Changing it requires redoing the commits (rewriting history) which results in new commit hashes.

The email address value used for the commit is the value currently set for user.email in your git config, which by the way you can set globally (git config --global) or locally per repo (git config --local).

GitHub maps the email address on commits to GitHub accounts.

This is just GitHub trying to link the email addresses on commits to GitHub user profiles so that people can discover other things the author has done.

  • Related