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.
bash1$ 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.
bash1$ 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.
bash1$ 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:
bash1$ git config --global core.pager "delta"
If you prefer basic less with good defaults:
bash1$ 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.
bash1$ 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:
bash1$ 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:
bash1$ git config --global --list2user.name=Ada Lovelace3user.email=ada@example.com4init.defaultBranch=main5commit.gpgsign=true6core.pager=delta7rerere.enabled=true8alias.st=status -sb9...
Configuration Levels
Git has three configuration levels:
| Level | Flag | File Location | Scope |
|---|---|---|---|
| System | --system | /etc/gitconfig | All users on machine |
| Global | --global | ~/.gitconfig | All your repositories |
| Local | --local | .git/config | Single repository |
Local settings override global, which override system. You can check where a setting comes from:
bash1$ git config --show-origin user.email2file:/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.