Git Configuration

Introduction

Git needs to know who you are when you create commits, and a few defaults make daily work smoother—default branch name, line endings, and your preferred editor. This chapter sets global configuration once on each machine; project-specific overrides come later.

Prerequisites

Configuration Levels

Git reads settings from three places (last wins for same key):

LevelFile locationScope
system/etc/gitconfig (Linux) or installer pathAll users on machine
global~/.gitconfigYour user account
local.git/config inside a repoSingle repository

Learning track uses --global for identity and defaults.

bash
git config --list --show-origin

Code explanation:

  • Shows each setting and which file defined it—useful when something surprises you

Identity: name and email

Every commit records author metadata:

bash
git config --global user.name "Ada Lovelace"
git config --global user.email "ada@example.com"

Code explanation:

  • Use the name you want on GitHub and at work
  • Email should match your Git hosting account if you want commit graph credit

Verify:

bash
git config --global user.name
git config --global user.email

Warning

Use a Real Email for Public Work

Commits are public in open source. Use noreply GitHub email if you want privacy: id+username@users.noreply.github.com.

Default Branch Name

New repos use main by default on modern Git:

bash
git config --global init.defaultBranch main

Avoids old master default on some legacy systems.

Choose an Editor for Commit Messages

When you run git commit without -m, Git opens an editor:

bash
git config --global core.editor "code --wait"

Examples:

EditorSetting
VS Code"code --wait"
nano"nano"
vim"vim"

Code explanation:

  • --wait tells VS Code to block until you close the tab—required for Git integration

Line Endings (Important on Windows)

bash
git config --global core.autocrlf true

On macOS / Linux:

bash
git config --global core.autocrlf input

Code explanation:

  • Windows true: checkout CRLF, commit LF—reduces “whole file changed” noise in mixed teams
  • Unix input: checkout as-is, commit LF

Helpful Defaults

bash
git config --global color.ui auto
git config --global pull.rebase false
git config --global push.default simple

Code explanation:

  • color.ui auto — colored git status and diffs when terminal supports it
  • pull.rebase falsegit pull merges (beginner-friendly default)
  • push.default simple — push current branch to matching remote branch

Teams may override pull.rebase later.

View and Change Settings

bash
git config --global --list
git config --global --unset core.editor

Edit global file directly (optional):

bash
# macOS / Linux
nano ~/.gitconfig

Example ~/.gitconfig:

ini
[user]
    name = Ada Lovelace
    email = ada@example.com
[init]
    defaultBranch = main
[core]
    editor = code --wait
    autocrlf = input
[color]
    ui = auto

Local Overrides (Preview)

Inside one repo only:

bash
cd my-project
git config local.user.email "work@company.com"

Use when personal global email differs from employer repo policy.

What Not to Put in Git Config

  • Passwords, tokens, API keys—use credential helper or SSH keys (later chapter)
  • Do not commit .gitconfig with secrets to dotfiles repo without review

Setup Checklist

  • user.name and user.email set globally
  • init.defaultBranch main
  • core.editor set to an editor you know how to exit
  • core.autocrlf appropriate for your OS
  • git config --global --list looks correct

FAQ

Forgot to configure before first commit?

Set config now; future commits use new identity—old commits keep old author unless rewritten (advanced).

Multiple GitHub accounts?

Use separate SSH keys and conditional includeIf in ~/.gitconfig—advanced topic; one account is enough for learning.

git config vs .gitconfig?

Same settings—CLI writes the file.

System config locked by IT?

Use --global only; you cannot change system level without admin.

Change name on old commits?

git rebase / filter-repo—only before sharing or with team agreement.

Where is global config on Windows?

C:\Users\<You>\.gitconfig