Git Config: Setting Up Git

Updated · 12 min read
easyGit 2.53gitconfigsetupgitconfiginterview

When you get a new phone, you set it up once: your name, your language, your ringtone. After that it works the way you like, and you rarely open the settings again.

Git is the same. Every commit you make is signed with a name and an email address, so Git needs to know who you are before your first commit. The command for this, and for every other setting, is git config.

In this lesson, you will set up Git on a new computer with four commands, see where Git keeps your settings, and learn how one repository can have settings of its own.

Tell Git Who You Are

Set your name and your email address. Use your own in place of Navika's:

Terminal
git config --global user.name "Navika Anamaneni"
git config --global user.email navika@example.com
git config --global user.name
Output
Navika Anamaneni

How it works

  1. git config --global user.name "Navika Anamaneni" saves the setting user.name. The name has a space in it, so it needs quotation marks.
  2. The second command saves user.email in the same way.
  3. git config --global user.name with no value reads the setting back. Git prints Navika Anamaneni.
  4. --global means "for me, in every repository on this computer". You set it once.

The first two commands print nothing. In Git, as in most terminal programs, silence means the command worked.

Set the Default Branch Name

Every new repository starts with one branch. Here is what Git 2.53 says when you create a repository before choosing that branch's name:

Terminal
git init demo
Output
Initialized empty Git repository in /home/navika/projects/demo/.git/
hint: Using 'master' as the name for the initial branch. This default branch name
hint: will change to "main" in Git 3.0. To configure the initial branch name
hint: to use in all of your new repositories, which will suppress this warning,
hint: call:
hint:
hint: 	git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: 	git branch -m <name>
hint:
hint: Disable this message with "git config set advice.defaultBranchName false"

Git 2.53 still uses the old name, master. GitHub, GitLab and Bitbucket all name the first branch main, and Git plans to do the same in version 3.0. Follow the hint and set it now, so your repositories match the websites and this course:

Terminal
rm -rf demo
git config --global init.defaultBranch main
git config --global init.defaultBranch
Output
main

rm -rf demo deletes the test repository. From now on, every repository you create starts on main, and the hint doesn't appear again.

Choose Your Editor

Sometimes Git needs you to write more than one line, for example a long commit message. It then opens a text editor and waits until you save and close the file. Tell Git which editor to open:

Terminal
git config --global core.editor "code --wait"
git config --global --list
Output
user.name=Navika Anamaneni
user.email=navika@example.com
init.defaultbranch=main
core.editor=code --wait

code --wait is Visual Studio Code. The --wait part tells Git to pause until you close the file. git config --global --list then lists all four of your global settings. (Git shows setting names in lowercase here. They are not case-sensitive.)

EditorValue for core.editor
Visual Studio Code"code --wait"
Nano (simple, runs in the terminal)nano
Notepad (Windows)notepad
Sublime Text"subl -n -w"
Vimvim

Where Git Keeps Your Settings

There is nothing hidden about these settings. --global writes them to a plain text file named .gitconfig in your home folder. The ~ in the command below is a short way to write "my home folder":

Terminal
cat ~/.gitconfig
Output
[user]
	name = Navika Anamaneni
	email = navika@example.com
[init]
	defaultBranch = main
[core]
	editor = code --wait

A setting such as user.name is stored as name inside a section called [user]. You can open this file in any editor and change it by hand, or run git config --global --edit to open it in the editor you chose.

The Three Config Levels

Git reads its settings from three places. Each level covers less than the one before it, and the most specific level wins.

System, global and local: the most specific level wins
LevelOptionStored inApplies to
System--systemA file in Git's installation folderEvery user on this computer
Global--global.gitconfig in your home folderYou, in all your repositories
Local--local, or no option.git/config inside the repositoryThat one repository

You will use global for almost everything. Local is for the exceptions. Suppose Navika wants her school email address on the commits of one project and her usual address everywhere else.

A local setting belongs to a repository, so it can't be set outside one:

Terminal
git config user.email navika@school.example
Output
fatal: not in a git directory

Git stopped, because there is no repository here to hold the setting. Create a practice repository and try again inside it:

Terminal
mkdir git-practice
cd git-practice
git init
Output
Initialized empty Git repository in /home/navika/projects/git-practice/.git/
Terminal
git config user.email navika@school.example
git config user.email
Output
navika@school.example

Inside git-practice, the email is now the school address. Navika's global setting is untouched, and both values still exist. --show-origin shows where each one comes from:

Terminal
git config --show-origin --get-all user.email
Output
file:/home/navika/.gitconfig	navika@example.com
file:.git/config	navika@school.example

Git read the global file first and the repository's own file second. The second value replaced the first, so commits in this repository use navika@school.example. Every other repository still uses navika@example.com.

Line Endings at a Glance

Windows ends each line of a text file with two invisible characters, called CRLF. macOS and Linux use one, called LF. When a team mixes these systems, Git can report that every line of a file changed although nobody touched it. One setting prevents this:

Shell
git config --global core.autocrlf input

With these values, the files inside the repository always use LF, and Windows users still get CRLF in their working files. The Git for Windows installer sets true for you if you kept its default answer. The full story has its own lesson later in the course.

Reading, Changing and Removing Settings

Git 2.46 added a second way to write git config commands, with a word such as set or get after config. Both forms do the same thing. Most articles and answers online use the older form, so you need to be able to read both.

TaskWorks on every versionGit 2.46 and later
Set a valuegit config --global user.name "Navika"git config set --global user.name "Navika"
Read one valuegit config user.namegit config get user.name
List all valuesgit config --listgit config list
Remove a valuegit config --global --unset core.editorgit config unset --global core.editor
Open the file in your editorgit config --global --editgit config edit --global

Here is the newer form on Git 2.53:

Terminal
git config get user.name
git config list --global
Output
Navika Anamaneni
user.name=Navika Anamaneni
user.email=navika@example.com
init.defaultbranch=main
core.editor=code --wait

To change a setting, set it again with the new value. The old value is replaced.

Common Mistakes

Forgetting --global. Without it, the setting is local. Inside a repository, your name is saved for that repository only, and your next project has no name. Outside a repository, you get fatal: not in a git directory, as you saw above.

Mistyping the setting's name. Git accepts any name without complaint. git config --global user.nmae "Navika" saves a setting called user.nmae that nothing ever reads. If a setting seems to have no effect, run git config --global --list and check the spelling. Remove the wrong one with --unset.

Treating the email as a login. user.email doesn't sign you in anywhere and proves nothing about who you are. Signing in to GitHub happens separately, when you first push.

Using a work email in personal projects, or the reverse. The email is stored in every commit forever. Set your usual address globally and the other one locally, in the repositories that need it.

Expecting old commits to change. A new name or email applies to commits you make from now on. Commits you already made keep the name they were created with.

Interview Corner

What are the levels of Git configuration, and which one wins?

There are three main levels. System (--system) applies to every user on the machine. Global (--global) applies to one user and is stored in ~/.gitconfig. Local (--local, the default) applies to one repository and is stored in .git/config. Git reads them in that order, so the most specific level wins: local overrides global, and global overrides system. A fourth level, --worktree, is more specific still.

How do you use a different email address for one repository?

Run git config user.email other@example.com inside that repository, without --global. It writes to the repository's .git/config and overrides the global value there only.

How can you see every setting and where it comes from?

git config --list --show-origin prints each setting with the file it was read from. git config --list --show-scope prints the level (system, global or local) for each one.

Is user.name the same as your GitHub username?

No. user.name is the display name written into each commit, such as "Navika Anamaneni". Hosting services match commits to an account by the email address, and you sign in to them separately with a token or an SSH key.

Practice

Challenge: check which email a commit gets. You are still inside git-practice, where the local email is the school address. Create a file named notes.txt, commit it with the message Add practice notes, and look at the commit with git log.

What does Git print? Before you open the solution, decide which email address appears on the Author: line.

Show solution
Terminal
echo "My practice notes" > notes.txt
git add notes.txt
git commit -m "Add practice notes"
git log
Output
[main (root-commit) 5b18670] Add practice notes
 1 file changed, 1 insertion(+)
 create mode 100644 notes.txt
commit 5b186702665f98d45ff28357d8ba9991c9db4a3f (HEAD -> main)
Author: Navika Anamaneni <navika@school.example>
Date:   Mon Jan 5 10:32:00 2026 -0600
 
    Add practice notes

The author is navika@school.example: the local value won. The name comes from the global level, because this repository has no name of its own. The branch is main, which shows that init.defaultBranch is working.

Checkpoint: explain every line. Run the command below and say, for each line, which level it comes from.

Terminal
git config --list --show-origin
Output
file:/home/navika/.gitconfig	user.name=Navika Anamaneni
file:/home/navika/.gitconfig	user.email=navika@example.com
file:/home/navika/.gitconfig	init.defaultbranch=main
file:/home/navika/.gitconfig	core.editor=code --wait
file:.git/config	core.repositoryformatversion=0
file:.git/config	core.filemode=true
file:.git/config	core.bare=false
file:.git/config	core.logallrefupdates=true
file:.git/config	core.ignorecase=true
file:.git/config	core.precomposeunicode=true
file:.git/config	user.email=navika@school.example

The first four lines are your global settings. The lines from .git/config are local. Git wrote the core. lines itself when it created the repository, and the last one is the email you set. This output is from macOS. On Windows and Linux, a few of the core. lines are different, and you may also see system-level lines at the top.

Clean up. A practice repository is disposable. Deleting the folder deletes the repository, and your global settings stay:

Terminal
cd ..
rm -rf git-practice

Create a new one whenever you want to try something risky. Nothing you do in a practice repository can harm a real project.

Quick check: Git config

4 questions
1What does --global mean in git config --global user.name "Navika"?
2user.email is navika@example.com globally and navika@school.example locally. Which one does a commit in that repository use?
3Where does git config user.email navika@school.example (with no option) save the setting?
4Why set init.defaultBranch to main?

Key Takeaways

Quick reference

CommandIt is used to
git config --global user.name "Your Name"Set the name written on your commits
git config --global user.email you@example.comSet the email written on your commits
git config --global init.defaultBranch mainStart new repositories on main
git config --global core.editor "code --wait"Choose the editor Git opens
git config user.email other@example.comSet a value for the current repository only
git config --global --listList your global settings
git config --list --show-originList every setting with the file it comes from
git config --global --unset <name>Remove a setting
git config --global --editOpen the global file in your editor

Was this tutorial helpful?

Lesson 6 of 106