When connecting to a repo for the first time you will need to provide git with your git config username and password. You might discover that you haven’t done so already when you try your first git push
and get a message along the lines of “fatal: Authentication failed for ‘http://stash.ds.local/scm/url/repo-name.git/'”.
The frustrating thing is that in most cases, git tells you nothing else and you’re left wondering how to resolve the issue. How can you show git config details so you know what, if anything is already set up? I’ll explain in this post how to view your git config username and email using the git config
command so that you don’t see that message anymore. I’ll also explain how to use the git config list command to see all your repo settings, and what the difference is between the git config global and local values.
Table of contents
Getting started
First of all, you need to know how to show your git config username, if it exists at all. If you find you haven’t set them yet, then you will need to know how to set your git config username and email. I’ll provide information on each of those topics in this post. So if you’re wondering “What is my current git username” or similar, read on to learn how to find it.
What is the git config command?
The git config
command is a function that’s used to get or set git configuration values on a global or local repository level. The configuration values that you get or set actually live in a git config file called .gitconfig. Because there are local, global, and system values there will be more than one .gitconfig file on your computer.
The configuration values that you get or set actually live in a git config file called .gitconfig.
What is the .gitconfig file?
It is just a text file containing the repo settings. You can change the settings by editing the text file directly but I wouldn’t advise it.
What is git config local?
You should use –local flag to get or set local repo values. That then obviously means when using it you need to be sure you are in the right repo before you use the command.
Local configuration values are stored in a file that can be found in the repository’s .git directory: .git/config
.
What is git config global?
Global level configuration is global, but bear in mind it is user-specific, meaning it is applied to an operating system user.
Global configuration values are stored in a file that is located in a user’s home directory, likely to be C:\Users\<username>\.gitconfig
on Windows.
On Windows if you want to edit the global config file then from git bash you can use this command.
notepad ~/.gitconfig
What is git config system?
System-level configuration is applied across an entire machine. This covers all users on an operating system and all repositories. The system level configuration file lives in a gitconfig
file off the system root path. $(prefix)/etc/gitconfig on Linux systems. On Windows this file can be found in C:\ProgramData\Git\config
.
What does the git config command do?
The git config command does different things depending on the flags specified. It can:
- return the whole list of config values using the
--list
flag - return the list of config values just for the level specified using the
--list
and the--local/global
flag - get a specified config value
- set a specified config value
Use git config to get local config settings
Before trying to see any local settings you need to make sure you are in the right repo. Change the current directory to the relevant directory, and then to see all the local config values use the git config
command with the --list
flag and the --local
flag :
git config --local --list
Use git config to get git config username and email
To get only the local git config username :
git config --get user.name
To get only the local git email :
git config --get user.email
If nothing is returned from either command then you haven’t set anything yet.
Use git config to see global settings
git config --global --list
The git config --list
command returns all the settings and will vary depending on your setup. What we’ll focus on here is the user.name
and user.email
values.
$ git config --list
user.name=Jane Doe
user.email=jdoe@gmail.com
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
remote.origin.url=https://url.to.remote.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.main.remote=origin
branch.main.merge=refs/heads/main
user.name=jdoe
user.email=jd@mail.com
What if nothing is returned from the git config –get command?
If you can’t see any reference of user.name
or user.email
then you haven’t set them up yet. Check the directory you’re in and whether you set the username globally or only for a single repo.
Check if it is set up globally by going to your home directory and using:
git config --global user.name
Otherwise use:
git config user.name
from your repo to see if it’s set locally. If both are empty then neither have been set.
Summary
You will now know how to use git config list to see all your local or global settings. You can also now use the --get
flag to get the git config username
and email
values from your local and global settings.