10 minlesson

Global Git Configuration

Global Git Configuration

Before touching any repository, establish your global Git settings. These configurations apply to every repo on your machine and only need to be set once.

Why Configuration Matters

Git records your identity on every commit. Without proper configuration:

  • Your commits may not link to your GitHub profile
  • Contribution graphs won't show your work
  • Protected branches may reject unsigned commits
  • Diffs become harder to read

Essential Settings

Identity

Your name and email appear in every commit. They must match your GitHub profile for contributions to be attributed correctly.

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

Why it matters: GitHub uses your email to connect commits to your account. If the email doesn't match, your contribution graph stays empty.

Default Branch

Set main as the default branch name for new repositories.

bash
1$ git config --global init.defaultBranch main

Why it matters: Running git init creates your first branch. Without this setting, Git may create master instead of main, causing inconsistency.

Commit Signing

Enable GPG signing so commits are verified on GitHub.

bash
1$ git config --global commit.gpgsign true

Why it matters: Many organizations require verified commits. A green "Verified" badge proves you authored the commit.

Diff Pager

Set a pager for better diff readability. If you installed delta:

bash
1$ git config --global core.pager "delta"

If you prefer basic less with good defaults:

bash
1$ git config --global core.pager "less -FX"

Why it matters: The default pager can truncate colors or wrap lines poorly. A configured pager makes code reviews faster.

Safety Nets

Rerere (Reuse Recorded Resolution)

Enable rerere to remember how you resolved conflicts. Next time the same conflict appears, Git auto-resolves it.

bash
1$ git config --global rerere.enabled true

Why it matters: When rebasing long-lived branches, you often hit the same conflicts repeatedly. Rerere saves time by remembering your resolutions.

Helpful Aliases

Create shortcuts for common commands:

bash
1$ git config --global alias.st "status -sb"
2$ git config --global alias.co "checkout"
3$ git config --global alias.br "branch"
4$ git config --global alias.lg "log --oneline --graph --decorate"

Why it matters: You'll type git status hundreds of times. git st is faster.

Verify Your Configuration

After setting everything, verify your configuration:

bash
1$ git config --global --list
2user.name=Ada Lovelace
3user.email=ada@example.com
4init.defaultBranch=main
5commit.gpgsign=true
6core.pager=delta
7rerere.enabled=true
8alias.st=status -sb
9...

Configuration Levels

Git has three configuration levels:

LevelFlagFile LocationScope
System--system/etc/gitconfigAll users on machine
Global--global~/.gitconfigAll your repositories
Local--local.git/configSingle repository

Local settings override global, which override system. You can check where a setting comes from:

bash
1$ git config --show-origin user.email
2file:/home/ada/.gitconfig ada@example.com

Key Takeaway

These settings are foundational. Proper identity ensures your work is credited. Signing proves authenticity. A good pager makes reviewing changes easier. Rerere prevents repetitive conflict resolution. Set them once, benefit forever.