Git Foundations / Start Here

Configure Git for your first repository

Lesson 3 of 33. Open to read. No account needed.

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 .gitconfig in your home folder.
  • Local: applies to one repository. It is stored in .git/config inside that repository.

Three configuration scopes stacked from most to least specific: local for one repository, global for your user account and system for every user. A local user.email of asha.rao@work.example overrides the global asha@example.com, so commits in that repository use the local address while other repositories use the global one.

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 code command 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.

  1. Look at what is already set, so you do not overwrite settings you rely on:

    git config --global --list
    

    On a new installation this may print nothing, or report that the file does not exist yet. Both are fine.

  2. 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 nano
    

    Use "code --wait" instead of nano if you chose VS Code.

  3. Read them back:

    git config --global --get user.name
    git config --global --get user.email
    git config --global --get init.defaultBranch
    git var GIT_EDITOR
    

    Illustrative output:

    Asha Rao
    asha@example.com
    main
    nano
    
  4. Open your global settings file in the editor to prove Git can start it:

    git config --global --edit
    

    Your 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 seeLikely causeNext step
Step 3 prints nothing for one settingA typo in its name, or the command did not rungit config --global --list, then fix with --unset and set it again
error: key does not contain a sectionThe setting name lacks its first part, such as user.Type the full name, for example user.name
error: cannot run nanoThe editor is not installed or not on the pathInstall it, or set another editor
git var GIT_EDITOR shows a different editorAn environment variable overrides core.editorUse that editor, or remove the variable from your shell setup
VS Code opens but Git continues at once--wait was left outSet 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.

References

Study this course with an account

Course access adds revision notes, the Quick Reference, saved progress, bookmarks and your own notes.

INR 99 plus 18% GST. 90 days of online access. No auto-renewal.

See course access

This website is operated by VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED, operating as Vectametric.

Corporate Identity Number (CIN): U85499KA2026OPC229822. GSTIN: 29AAMCV8281D1ZS. Registered office: RS NO/38/2A/1 BASTAND, ROAD MAHANTESH NAGAR, Ramdurg, Ramdurg, Belgaum- 591123, Karnataka.

Queries and grievances: Prajval Honnungar, Grievance Officer and Data Protection Contact.

Telephone: +91 94800 09310. Support: support@vectametric.com. Grievances: support@vectametric.com.

Copyright 2026 VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED. All rights reserved.

Vectametric home · Roadmaps · Vecta IT Exams · Vecta Government Exams · Vecta Banking & Finance Exams · Vecta Entrance Exams · About us · Contact · Privacy Policy · Terms and Conditions · No-Refund Policy