Git Configure Multiple User
https://www.youtube.com/watch?v=KO4cMC-NrxM
generate 2 SSH keys for 2 github accounts , use different email ids for different accounts
list them
Goto Profile > Settings & add key in github.com
This discrepancy happens because of the way Git separates who wrote the code (metadata) from who uploaded the code (GitHub account).
Why the names don't match
Local Git Config vs. GitHub Account: When you commit code on your computer, Git attaches the
user.nameanduser.emailstored in your local settings to that commit. It doesn't matter which GitHub account you use to push the code; GitHub simply reads the "Author" and "Committer" tags already embedded in the files.Why the name appears twice: GitHub shows "Name and Name" when the Author and the Committer fields are both present but GitHub isn't 100% sure they are the same verified GitHub user. This often happens if the email used in the local config isn't verified on the GitHub account.
The "Contributors" Sidebar: That sidebar only counts GitHub accounts with verified email addresses that match the commits. If the "Initial commit" was made with an email address not linked to the
xyzaccount, GitHub doesn't "count" that person as a contributor in the sidebar, even if their name shows up in the history.
How to Correct It
You need to do two things: fix your settings for the future and fix the past (the initial commit).
1. Fix Future Commits
Check your current local settings and update them to match the GitHub account you want to use.
# Check current settings
git config user.name
git config user.email
# Update to the correct identity
git config user.name "XYZ"
git config user.email "your-github-email@example.com"
2. Fix the Initial Commit
Since you want to change a commit that has already been pushed, you have to "rewrite history." Because it is the Initial Commit, use the following steps:
Amend the commit: This changes the author and name of the very last commit you made.
Bashgit commit --amend --author="XYZ ABC <your-github-email@example.com>" --no-editForce Push: Since you modified a commit that is already on GitHub, a standard push will be rejected. You must force it (use caution if others are working on this repo):
Bashgit push origin main --force


Comments
Post a Comment