How to know the git username and email saved during configuration?
Solution 1
The command git config --list
will list the settings. There you should also find user.name
and user.email
.
Solution 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
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
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
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
Jebin Philipose
Updated on July 08, 2022Comments
-
Jebin Philipose almost 2 years
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 thegit 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?