So i always wondered why i do a git push to a certain repository but notice that i see a different user as the committer, and not the account i cloned from. so the problem is this - i clone from repo A with username A1, but while doing a git push i noticed that the commit done was from username B1, even though they all belong to me but it should be username A1 with the commit.
The issue is that the git credential on your local machine was set to global hence the terminal uses it for commits. so how to change that...
Navigate to the git directory
cd <git directory>
check for the credentials list to see the default
git config --list
here you can see the global username and email
All you need to do is to add another username in our case here the username and email of A1
git config user.name "<username>"
git config user.email "<email>"
if you want to override the default and make A1 the default
git config --global user.name "<username>"
git config --global user.email "<email>"
To switch to a different user credential, run the following commands with the desired user name and email:
git config user.name "New Name"
git config user.email "new.email@example.com"
If you want to switch to a global user credential, add the --global flag to the commands:
git config --global user.name "New Name"
git config --global user.email "new.email@example.com"
Remember that the user credential settings are stored in the .git/config file within your local repository. If you want to view or edit this file directly, you can open it with a text editor.
What does this solution solve, it can solve some ssh issues, some wrong user commit and some serious headache lol
Top comments (0)