Git Config: Setting Up Git
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:
git config --global user.name "Navika Anamaneni"
git config --global user.email navika@example.com
git config --global user.nameNavika AnamaneniHow it works
git config --global user.name "Navika Anamaneni"saves the settinguser.name. The name has a space in it, so it needs quotation marks.- The second command saves
user.emailin the same way. git config --global user.namewith no value reads the setting back. Git printsNavika Anamaneni.--globalmeans "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:
git init demoInitialized 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:
rm -rf demo
git config --global init.defaultBranch main
git config --global init.defaultBranchmainrm -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:
git config --global core.editor "code --wait"
git config --global --listuser.name=Navika Anamaneni
user.email=navika@example.com
init.defaultbranch=main
core.editor=code --waitcode --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.)
| Editor | Value for core.editor |
|---|---|
| Visual Studio Code | "code --wait" |
| Nano (simple, runs in the terminal) | nano |
| Notepad (Windows) | notepad |
| Sublime Text | "subl -n -w" |
| Vim | vim |
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":
cat ~/.gitconfig[user]
name = Navika Anamaneni
email = navika@example.com
[init]
defaultBranch = main
[core]
editor = code --waitA 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.
| Level | Option | Stored in | Applies to |
|---|---|---|---|
| System | --system | A file in Git's installation folder | Every user on this computer |
| Global | --global | .gitconfig in your home folder | You, in all your repositories |
| Local | --local, or no option | .git/config inside the repository | That 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:
git config user.email navika@school.examplefatal: not in a git directoryGit stopped, because there is no repository here to hold the setting. Create a practice repository and try again inside it:
mkdir git-practice
cd git-practice
git initInitialized empty Git repository in /home/navika/projects/git-practice/.git/git config user.email navika@school.example
git config user.emailnavika@school.exampleInside 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:
git config --show-origin --get-all user.emailfile:/home/navika/.gitconfig navika@example.com
file:.git/config navika@school.exampleGit 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:
git config --global core.autocrlf inputgit config --global core.autocrlf trueWith 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.
| Task | Works on every version | Git 2.46 and later |
|---|---|---|
| Set a value | git config --global user.name "Navika" | git config set --global user.name "Navika" |
| Read one value | git config user.name | git config get user.name |
| List all values | git config --list | git config list |
| Remove a value | git config --global --unset core.editor | git config unset --global core.editor |
| Open the file in your editor | git config --global --edit | git config edit --global |
Here is the newer form on Git 2.53:
git config get user.name
git config list --globalNavika Anamaneni
user.name=Navika Anamaneni
user.email=navika@example.com
init.defaultbranch=main
core.editor=code --waitTo 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
echo "My practice notes" > notes.txt
git add notes.txt
git commit -m "Add practice notes"
git log[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 notesThe 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.
git config --list --show-originfile:/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.exampleThe 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:
cd ..
rm -rf git-practiceCreate a new one whenever you want to try something risky. Nothing you do in a practice repository can harm a real project.
Key Takeaways
Quick reference
| Command | It is used to |
|---|---|
git config --global user.name "Your Name" | Set the name written on your commits |
git config --global user.email you@example.com | Set the email written on your commits |
git config --global init.defaultBranch main | Start new repositories on main |
git config --global core.editor "code --wait" | Choose the editor Git opens |
git config user.email other@example.com | Set a value for the current repository only |
git config --global --list | List your global settings |
git config --list --show-origin | List every setting with the file it comes from |
git config --global --unset <name> | Remove a setting |
git config --global --edit | Open the global file in your editor |
Was this tutorial helpful?