'How to know the git username and email saved during configuration?
While configuring git
I ran these two commands:
git config --global user.name "My Name"
git config --global user.email "[email protected]"
However, I doubt whether I made a typo or not. So, is there any command to know the name and email which git
saved during configuration? Obviously, I can know that using the git log
command by looking at the commit history. But for that I have to make commits, right? Can I know that with the help of command line?
Solution 1:[1]
The command git config --list
will list the settings. There you should also find user.name
and user.email
.
Solution 2:[2]
Considering what @Robert said, I tried to play around with the config
command and it seems that there is a direct way to know both the name and email.
To know the username, type:
git config user.name
To know the email, type:
git config user.email
These two output just the name and email respectively and one doesn't need to look through the whole list. Comes in handy.
Solution 3:[3]
Inside your git repository directory, run git config user.name
.
Why is running this command within your git repo directory important?
If you are outside of a git repository, git config user.name
gives you the value of user.name
at global level. When you make a commit, the associated user name is read at local level.
Although unlikely, let's say user.name
is defined as foo
at global level, but bar
at local level. Then, when you run git config user.name
outside of the git repo directory, it gives bar
. However, when you really commits something, the associated value is foo
.
Git config variables can be stored in 3 different levels. Each level overrides values in the previous level.
1. System level (applied to every user on the system and all their repositories)
- to view,
git config --list --system
(may needsudo
) - to set,
git config --system color.ui true
- to edit system config file,
git config --edit --system
2. Global level (values specific personally to you, the user. )
- to view,
git config --list --global
- to set,
git config --global user.name xyz
- to edit global config file,
git config --edit --global
3. Repository level (specific to that single repository)
- to view,
git config --list --local
- to set,
git config --local core.ignorecase true
(--local
optional) - to edit repository config file,
git config --edit --local
(--local
optional)
How to view all settings?
- Run
git config --list
, showing system, global, and (if inside a repository) local configs - Run
git config --list --show-origin
, also shows the origin file of each config item
How to read one particular config?
- Run
git config user.name
to getuser.name
, for example. - You may also specify options
--system
,--global
,--local
to read that value at a particular level.
Reference: 1.6 Getting Started - First-Time Git Setup
Solution 4:[4]
List all variables set in the config file, along with their values.
git config --list
If you are new to git then use the following commands to set a user name and email address.
Set user name
git config --global user.name "your Name"
Set user email
git config --global user.email "[email protected]"
Check user name
git config user.name
Check user email
git config user.email
Solution 5:[5]
If you want to check or set the user name and email you can use the below command
Check user name
git config user.name
Set user name
git config user.name "your_name"
Check your email
git config user.email
Set/change your email
git config user.email "[email protected]"
List/see all configuration
git config --list
Solution 6:[6]
Set Global / All projects
first get and confirm the old values:
git config --global user.email
git config --global user.name
Output: (if git new installation then the output will show empty)
[email protected]
youroldgoodname
Now For set new values
git config --global user.email [email protected]
git config --global user.name yournewgoodname
For current workspace or project
just remove --global from all above commands/lines
Solution 7:[7]
Sometimes above solutions doesn't work in macbook to get username n password.
IDK why?, here i got another solution.
$ git credential-osxkeychain get
host=github.com
protocol=https
this will revert username and password
Solution 8:[8]
Add my two cents here. If you want to get user.name or user.email only without verbose output.
On liunx, type git config --list | grep user.name
.
On windows, type git config --list | findstr user.name
.
This will give you user.name only.
Solution 9:[9]
To view git configuration type -
git config --list
To change username globally type -
git config --global user.name "your_name"
To change email globally type -
git config --global user.email "your_email"
Solution 10:[10]
All good discussion here. Just want to add one point here: in many tool/app, there is a concept of user id to uniquely identify a user. The user id is usually a single word (with no embedded space), or in some cases an email address. So I came to this topic with the question: does git has another field called user id? If not, what does git uses as a unique way to identify a user?
So far, from reading the answers here, and searching through the web, I cannot find any mention of user id in git. a. So I have to conclude that there is no such field as user id. b. User name is unlikely to be a good candidate, as folks can have the same name, and the name is free form. c. Then the only remaining logical choice is the email address, or email address + user name?
Indeed, one can see both from the git log of say xgboost source code:
commit 5c2d7a18c92b445ba897d4b0b4859508ae720883 (HEAD -> master, origin/master, origin/HEAD)
Author: Jiaming Yuan <[email protected]>
Date: Tue Jun 15 14:08:26 2021 +0800
Parallel model dump for trees. (#7040)
Solution 11:[11]
First Check If you already have the name and email in git configuration:-
To Check,
The username:-
git config --global user.name
The email
git config --global user.email
If it is already set, and you want to change or If it is not set and you want to add the username and email in the git configuration :-
To set:-
The Username :-
git config --global user.name "<your_username>"
The Email :-
git config --global user.email "<your_email>"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow