873

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?

1
  • 29
    git config --list Commented Oct 6, 2021 at 0:28

15 Answers 15

1073

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

Sign up to request clarification or add additional context in comments.

3 Comments

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 Then what's the correct way to see user.name for the repository we're currently in?
@starriet just use git config user.name in this case, see the answer of @jebin-philipose below.
390

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.

2 Comments

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차주녕 it doesn't specifically show the local config - it shows whatever option is active for the current repository according to the config hierarchy (system/global/local/worktree). So if you have a local email it will show that and if not then it will show your global one and if not the system one (for example)
185

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

3 Comments

@sam I'm inside the local repo, set the username and email. But git push is still using global name. Why is that?
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
"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." I believe you got this mixed up. The last line should read: "Then, when you run git config user.name outside of the git repo directory, it gives foo. However, when you really commit something, the associated value is bar."
88

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

Comments

51

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

1 Comment

For more have a look on the official document : help.github.com/en/github/using-git/…
40

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 "[email protected]"
$ 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 "[email protected]"
$ git config --local user.name "your_userName"

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

Comments

26

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

Comments

25

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

Comments

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.

2 Comments

Why not git config --get user.name? Is --get a newer argument?
@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.
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

Comments

6

Add to ~/.gitconfig

[alias]
  whoami = config --get user.username

Usage:

git whoami

->

someusername

2 Comments

I really like this but I also wanted the email listed: whoami = "!echo \"$(git config user.name) ($(git config user.email))\""
You need to change user.name to user.username; I had the same issue
4

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"

Comments

1

If are not getting any answer after running

git config --global user.email
git config --global user.name

then this means that currently there is no user email/name set for git, so for that, first you have to set a email or user using the commands below

git config --global user.email [email protected]
git config --global user.name user_name

make sure you replace the [email protected] with your github account email and the user_name with your github account username

and now if you try to run the initial command after setting the user or email value, you will see a value getting printed in your terminal

Comments

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 <[email protected]>
Date:   Tue Jun 15 14:08:26 2021 +0800

    Parallel model dump for trees. (#7040)

Comments

0

You can edit the settings of the user, global, core using the command git config global -e

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.