Git Course 0%

First-time configuration

Beginner Git CLI VS Code UI IntelliJ UI ≈ 10 min

What you will learn

  • Why Git refuses to commit without a name and email, and which email to use
  • The six settings worth changing on a fresh installation and what each does
  • How to read your settings back

After this lesson you can

  • My commits carry my name and the email my GitLab or GitHub account knows
  • New repositories start on main, commit messages open in my editor, and pushes do not ask for a token every time

Why this matters

Every commit records an author. Every push needs credentials. Every new repository needs a default branch name. Git asks you for none of this at install time; it waits until the first commit fails. Ten minutes now saves the surprise later, and the settings follow you across all projects on this computer.

What happens without configuration

Terminal
$ git commit -m "test"
Author identity unknown

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'raulhung@Mac-mini.(none)')

Git even prints the fix. Do exactly that, with your own details.

The six settings

1. Identity. Use the name colleagues know you by, and the email address your GitLab or GitHub account uses, so the platform can link commits to your profile:

Terminal
$ git config --global user.name "Ana Lopez"
$ git config --global user.email "ana@northwind-trails.example"

2. Default branch name for new repositories:

Terminal
$ git config --global init.defaultBranch main

3. Editor for commit messages when you forget -m (and for a few other operations). For VS Code:

Terminal
$ git config --global core.editor "code --wait"

--wait makes Git wait until you close the editor tab. Alternatives: "nano" (simple terminal editor), "notepad++ -multiInst -notabbar -nosession -noPlugin" on Windows, or leave the default (Vim; press Esc then type :wq to save and exit).

4. Pull behaviour. Tell Git to merge when pulling (the simplest to understand; rebase comes in Section 6):

Terminal
$ git config --global pull.rebase false

5. First push of a new branch without typing -u origin branch-name every time (Git 2.37 or newer):

Terminal
$ git config --global push.autoSetupRemote true

6. Line endings. Windows uses two characters to end a line, macOS and Linux one; without this setting, every file looks fully changed to colleagues on the other system. On Windows: git config --global core.autocrlf true. On macOS and Linux: git config --global core.autocrlf input. (The Windows installer sets this if you chose "Checkout Windows-style, commit Unix-style".)

Read everything back:

Terminal
$ git config --global --list
user.name=Ana Lopez
user.email=ana@northwind-trails.example
init.defaultbranch=main
core.editor=code --wait
pull.rebase=false
push.autosetupremote=true

And now the commit works:

Terminal
$ git commit -m "test"
[main (root-commit) 10053a3] test
 1 file changed, 1 insertion(+)

Credentials

The first time you push to GitLab or GitHub over HTTPS, Git asks for a username and a personal access token (not your website password). A credential helper stores it so you are asked once:

  • macOS: Apple's Git already uses the Keychain (credential.helper=osxkeychain); nothing to do.
  • Windows: Git for Windows installs Git Credential Manager; nothing to do.
  • Linux: git config --global credential.helper libsecret if available, otherwise git config --global credential.helper store (plain-text file, acceptable on a personal machine) or cache (kept in memory for a while).

Lesson 8.4 covers what is stored where and how to remove a wrong token.

Common mistakes

  • Typing the commands with a typo in the key. git config --global user.nmae "…" fails silently (exit code 1, no message). Read back with --list.
  • Using a different email than the platform knows. Commits appear without your avatar and are not counted as yours. Add the email to your profile or change user.email.
  • Quoting. Names with spaces need quotes: "Ana Lopez".
  • Setting --global while meaning one project. Omit --global inside a repository to set a value for that repository only (lesson 3.4).

Try it yourself

Goal: configure your identity and check it appears in a commit.

  1. Run the six settings from the Terminal tab with your own name and email (and the core.autocrlf value for your system).
  2. Run git config --global --list.
  3. In the playground, make an empty commit: git commit --allow-empty -m "chore: check identity" and run git log -1.

Expected result: the --list output shows your six values; the log shows Author: Your Name <your@email>.

Show solution

If the author line shows an old name or email, the commit was made before you changed the settings; make another empty commit. Existing commits keep the identity they were made with — changing configuration never rewrites history.

Check yourself

1. Which email should user.email contain?
2. git commit opened an unfamiliar full-screen editor. What happened and what should you set?
3. What does push.autoSetupRemote true do?

Key terms

Commit main Remote