Why Git Needs a Few Settings First
Every change you record in Git, called a commit, stores who made it: an
author name and an email address. Git does not guess these. Until you set them,
recording a change stops with a message that begins Author identity unknown.
Two other choices affect every repository you create: the name of its first branch (a named line of development; branches have their own module later), and the text editor Git opens when it needs you to write a message. This lesson sets all four values once for your user account, then shows you how to check where each value comes from.
Where Git Keeps Settings
Git reads settings from three levels, called scopes:
- System: applies to every user on the computer. The installation may set values here; its file location varies by system.
- Global: applies to your user account. It is stored in a file called
.gitconfigin your home folder. - Local: applies to one repository. It is stored in
.git/configinside that repository.

When the same setting appears in more than one scope, the most specific one
wins: local overrides global, and global overrides system. In the diagram,
user.email is set globally to asha@example.com and also set locally in one
repository to asha.rao@work.example. Commits in that repository use the local
address; every other repository falls back to the global one. The system scope
does not set an email here, so it plays no part.
This lesson uses the global scope with the --global option, so the settings
apply everywhere you work. You will set a local value in a later lesson, once
you have a repository.
Your Name and Email
git config --global user.name "Asha Rao"
git config --global user.email "asha@example.com"
git config reads and writes settings. user.name and user.email are the
setting names; the quoted text is the value. Replace the example values with
your own. The quotes are needed because a name contains a space.
Both values become part of every commit you make, and anyone who can read the repository can see them. For practice on your own computer, any address works. Before you publish a repository, consider which address you are happy to make public; hosting services offer private "no-reply" addresses for this, as the optional hosting module shows.
If you already use Git, check your current settings before changing them, because they apply to all your existing repositories as well:
git config --global --list
If user.name and user.email are already set to values you use, keep them
and skip those two commands.
The First Branch Name
git config --global init.defaultBranch main
When you create a repository, Git creates a first branch for it. Unless you
choose a name, Git 2.x calls it master. The Git project has announced that
Git 3.0 will name it main instead, but has not set a release date. Setting
init.defaultBranch to main gives you the same name whichever version you
use, which keeps your results consistent with this course. Git 2.28 added this
setting, which is why the course needs 2.28 or later.
An Editor Git Can Open
When you record a change without writing its message on the command line, Git opens a text editor and waits for you to write the message, save and close the file. Choose an editor you can use:
- nano is a small editor that runs inside the terminal. The Git for Windows
installer offers it, and many macOS and Linux systems include it. Check with
nano --version. - Visual Studio Code, if it is installed and its
codecommand works in your terminal.
Set one of them:
git config --global core.editor nano
or:
git config --global core.editor "code --wait"
The --wait option matters. Without it, VS Code returns control immediately,
and Git sees an empty message before you have typed anything.
In nano, type your text, press Ctrl+O then Enter to save, and Ctrl+X to exit. If nano asks whether to save changes you did not mean to make, press N.
Git chooses an editor in a fixed order: the GIT_EDITOR environment variable,
then core.editor, then the VISUAL and EDITOR environment variables, and
finally a built-in default, usually vi. To see which editor Git will actually
use, run:
git var GIT_EDITOR
If it prints something other than your choice, an environment variable is taking priority over your setting.
Read Your Settings Back
Two commands show what Git will use:
git config --global --get user.email
git config --list --show-origin
The first prints a single value. The second lists every setting Git can see, each prefixed with the file it came from. Illustrative output, with your own home folder and values:
file:/home/asha/.gitconfig user.name=Asha Rao
file:/home/asha/.gitconfig user.email=asha@example.com
file:/home/asha/.gitconfig init.defaultbranch=main
file:/home/asha/.gitconfig core.editor=nano
Each line has two parts: where the value came from and the setting itself.
Settings from the installation may appear first, with a different file path.
Git prints setting names in lowercase, so init.defaultBranch appears as
init.defaultbranch; names are not case-sensitive.
Git does not check setting names for spelling. If you type
git config --global user.mail ..., Git stores a setting called user.mail
without complaint, and your email is still unset. Reading values back is how
you catch this. To remove a mistaken setting, use --unset:
git config --global --unset user.mail
Exercise: Configure Git
This exercise sets your identity, default branch and editor, then confirms them. It changes your global settings, which is intended: they apply to every later exercise. It creates no files other than your global configuration file.
Starting state: Git 2.28 or later and a terminal from the previous lesson.
-
Look at what is already set, so you do not overwrite settings you rely on:
git config --global --listOn a new installation this may print nothing, or report that the file does not exist yet. Both are fine.
-
Set the four values, replacing the example name and email:
git config --global user.name "Asha Rao" git config --global user.email "asha@example.com" git config --global init.defaultBranch main git config --global core.editor nanoUse
"code --wait"instead ofnanoif you chose VS Code. -
Read them back:
git config --global --get user.name git config --global --get user.email git config --global --get init.defaultBranch git var GIT_EDITORIllustrative output:
Asha Rao asha@example.com main nano -
Open your global settings file in the editor to prove Git can start it:
git config --global --editYour editor shows the settings you just made. Close it without changing anything: in nano, press Ctrl+X.
Success: step 3 prints your name, your email, main and your chosen
editor, and step 4 opens and closes the editor cleanly.
If something differs:
| What you see | Likely cause | Next step |
|---|---|---|
| Step 3 prints nothing for one setting | A typo in its name, or the command did not run | git config --global --list, then fix with --unset and set it again |
error: key does not contain a section | The setting name lacks its first part, such as user. | Type the full name, for example user.name |
error: cannot run nano | The editor is not installed or not on the path | Install it, or set another editor |
git var GIT_EDITOR shows a different editor | An environment variable overrides core.editor | Use that editor, or remove the variable from your shell setup |
| VS Code opens but Git continues at once | --wait was left out | Set core.editor to "code --wait" |
Independent task: a learner typed this and their commits still fail with
Author identity unknown:
git config --global user.mail "asha@example.com"
Without looking at the answer, use the commands from this lesson to find the mistake, remove it and set the email correctly. Then confirm the fix.
Check Your Understanding
Your global user.email is asha@example.com. Inside one repository, someone
ran git config user.email asha.rao@work.example, without --global. Which
email do commits in that repository record? Which do commits in your other
repositories record? Where is each value stored?
Answer and Reasoning
Independent task
git config --global --list
git config --global --unset user.mail
git config --global user.email "asha@example.com"
git config --global --get user.email
--list shows a user.mail entry and no user.email, which explains the
error: Git still has no email. --unset removes the misspelled setting, the
next command sets the correct one, and --get user.email printing the address
confirms the fix.
Understanding check
Commits in that repository record asha.rao@work.example. Without --global,
git config writes to the local scope, stored in that repository's
.git/config, and local overrides global. Commits in every other repository
record asha@example.com from the global scope, stored in .gitconfig in your
home folder. git config --list --show-origin, run inside the repository,
shows both entries with their files; the local one appears later in the list,
which is why it wins.