568

While configuring git I ran these two commands:

git config --global user.name "My Name"

git config --global user.email "myemail@example.com"

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?

DennisLi
  • 3,915
  • 6
  • 30
  • 66
Jebin Philipose
  • 8,043
  • 4
  • 9
  • 14

13 Answers13

728

The command git config --list will list the settings. There you should also find user.name and user.email.

Bakudan
  • 19,134
  • 9
  • 53
  • 73
Rob
  • 7,320
  • 2
  • 10
  • 9
  • 17
    This command only shows the global settings not the one applicable for the repository you're currently in. E.g. overwriting the user.email in the repository will still show the `git config --global user.email` setting when using `git config --list`. – manuelwaldner Mar 22 '21 at 09:53
  • @manuelwaldner Then what's the correct way to see `user.name` for the repository we're currently in? – starriet May 02 '23 at 08:20
  • 2
    @starriet just use `git config user.name` in this case, see the answer of @jebin-philipose below. – manuelwaldner May 02 '23 at 12:03
226

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.

Josh Correia
  • 3,807
  • 3
  • 33
  • 50
Jebin Philipose
  • 8,043
  • 4
  • 9
  • 14
  • This not only shows the stuff we want to see, but it shows the _local_ config, _not_ global config. As @manuelwaldner mentioned in another comment. – starriet May 02 '23 at 14:05
144

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 need sudo)
  • 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 get user.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

kgf3JfUtW
  • 13,702
  • 10
  • 57
  • 80
  • 2
    Thanks for answering and explaining it in detail. – Jebin Philipose Oct 28 '17 at 14:50
  • 2
    @sam I'm inside the local repo, set the username and email. But git push is still using global name. Why is that? – CKM Sep 29 '19 at 14:05
  • This is a more complete answer as it is critical in many scenarios (e.g. having multiple users for different repos) to understand the separation between global and local configurations – lkisac Dec 28 '21 at 13:43
66

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 "your_email@example.com"

Check user name

git config user.name

Check user email

git config user.email
Akshay Pawar
  • 784
  • 1
  • 7
  • 11
45

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 "your@email.com"

List/see all configuration

git config --list
Srikrushna
  • 4,366
  • 2
  • 39
  • 46
  • For more have a look on the official document : https://help.github.com/en/github/using-git/setting-your-username-in-git – Srikrushna Apr 24 '20 at 04:49
21

The simplest way to know the already configured git (user name & email) is to type:

$ git config -l

That will display the previously configured information. In order to update it, you should use the command

$ git config --global user.email "example@email.com"
$ git config --global user.name "your_userName"

And If you want to do it for a single Project use can use

$ git config --local user.email "example@email.com"
$ git config --local user.name "your_userName"

You can also check: [1]: https://git-scm.com/docs/git-config

Youssef smail
  • 211
  • 2
  • 2
20

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)

yourold@email.com
youroldgoodname

Now For set new values

git config --global user.email yournew@email.com
git config --global user.name yournewgoodname

For current workspace or project
just remove --global from all above commands/lines

Hassan Saeed
  • 6,326
  • 1
  • 39
  • 37
11

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.

Eugene
  • 10,627
  • 5
  • 49
  • 67
  • 1
    Why not `git config --get user.name`? Is --get a newer argument? – Kevin Murray Mar 04 '22 at 18:38
  • 1
    @KevinMurray Thanks for commenting it out. I just didn't know the existence of `--git`. Your comment could be a leaner way to get `user.name` or other attribute. – Eugene Mar 06 '22 at 08:27
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
Kanish
  • 273
  • 4
  • 10
6

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>"

nakli_batman
  • 481
  • 8
  • 4
2

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"
Derrick
  • 3,669
  • 5
  • 35
  • 50
0

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 <jm.yuan@outlook.com>
Date:   Tue Jun 15 14:08:26 2021 +0800

    Parallel model dump for trees. (#7040)
HAltos
  • 701
  • 7
  • 6
-3

To change username globally type -

git config --global user.name "your_name"

To change email globally type -

git config --global user.email "your_email"

To change username locally type -

git config --local user.name "your_name"

To change email locally type -

git config --local user.email "your_email"
Rishabh Jain
  • 15
  • 1
  • 2