DEV Community

Debugging Rabbit
Debugging Rabbit

Posted on

Git User Credentials

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>
Enter fullscreen mode Exit fullscreen mode

check for the credentials list to see the default

git config --list
Enter fullscreen mode Exit fullscreen mode

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>"
Enter fullscreen mode Exit fullscreen mode

if you want to override the default and make A1 the default

git config --global user.name "<username>"
git config --global user.email "<email>"
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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)