Lesson

Git Config

10 min reading
Free Course

Git Config: Setting Identity, Editor, and Repository Defaults

Running git config sets your author identity, preferred text editor, and default branch name before you record your first commit. Every Git commit embeds your configured name and email address permanently into project history.

Setting Your Author Name and Email

Before making any commit, tell Git who you are. Use the --global flag so these settings apply to every repository under your user account:

git config --global user.name "Amina Rahman"
git config --global user.email "amina@example.com"

If you work on personal and company projects on the same laptop, keep your personal email global and override the email inside your work repository without --global:

git config user.email "amina@company.com"

Setting the Default Branch and Editor

Modern hosting platforms expect main as the default branch name for new repositories. Configure Git to use main automatically whenever you run git init, and pick an editor you are comfortable closing:

git config --global init.defaultBranch main
git config --global core.editor "code --wait"

Understanding Configuration Scopes

Git reads settings from three levels, where narrower scopes override broader ones:

Scope Flag File Location Best Used For
System --system /etc/gitconfig Machine-wide IT defaults
Global --global ~/.gitconfig Personal name, email, aliases
Local --local .git/config Project-specific email or hooks

To inspect all active settings and see which file defines each value, run:

git config --list --show-origin

To delete a setting you no longer want, pass --unset:

git config --global --unset core.editor

Common Configuration Mistakes

Using a different email address in Git than the one verified on your GitHub account causes your commits to show no profile avatar or contribution credit. Check git config user.email inside your project folder if commits appear unlinked.

Also avoid configuring a GUI editor without the --wait flag. Without --wait, Git finishes immediately with an empty commit message instead of pausing while you type.

Frequently Asked Questions

Where does Git store my global configuration file?

Git stores global settings in a plain-text file named .gitconfig inside your home directory (~/.gitconfig on macOS/Linux or C:\Users\<name>\.gitconfig on Windows). You can edit it with git config or any text editor.

Can I change the author email after making a commit?

Changing git config user.email only affects future commits. To fix the author on the very last unpushed commit, run git commit --amend --reset-author --no-edit.

Why does git config --list show duplicate keys?

When the same key exists in both global and local config files, --list prints both lines in load order. The final value printed at the bottom is the one Git actually uses for the current repository.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol
Git Topic Hub

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum