greennhills.com causes mean pain

git config email

Terminal window showing git config commands with email set

Git config email sets the email address associated with your commits in Git repositories. This email appears in commit history and links your work to your identity across platforms like GitHub, GitLab, and Bitbucket.

When you run git commit, Git uses the email configured via git config email to label who made each change. Without a valid email, commits may lack attribution or fail verification in systems that require signed commits.

The command git config --global user.email "[email protected]" sets the email for all repositories on your machine. Use git config --local user.email to override it in a single project.

How git config email works

Git stores user identity settings in configuration files. The global settings live in ~/.gitconfig (on Linux/macOS) or %USERPROFILE%\.gitconfig (on Windows). Local settings are stored in .git/config within each repository.

When you create a commit, Git checks for user.email in this order: local config > global config > no setting. If none is found, Git warns you and uses a default email format: "user@hostname" based on your system username and hostname.

For example, if your username is jsmith and your computer name is macbook.local, Git defaults to [email protected]. This often results in unverified or incorrect attribution, especially on shared machines.

Types of git config email settings

Git supports two scopes for email configuration: global and local. Global applies to all repositories. Local overrides global settings for a specific project.

Scope Command File Location Use Case
Global git config --global user.email "[email protected]" ~/.gitconfig Personal email for all projects
Local git config --local user.email "[email protected]" .git/config Work email for a specific repo

Using both allows flexibility. For example, you might use your personal email globally but switch to your company email locally when contributing to a team project.

Some developers use multiple identities. You can configure different emails per repository by setting --local in each one. This avoids confusion when working across personal and professional projects.

Common mistakes and fixes

A frequent error is assuming that git config email applies everywhere. It doesn't. A local setting in one repository won't affect another unless explicitly set.

Another issue is mismatched email addresses. If your Git email differs from your GitHub or GitLab account email, your contributions won't appear under your profile. GitHub shows "Contributions" only when the commit email matches the verified email on your account.

For example, if you commit with [email protected] but your GitHub account is linked to [email protected], the commit shows as "unknown contributor." To fix this, either update your Git config or verify the email in your account settings.

Git doesn't validate email syntax. Typo errors like [email protected] go unnoticed until you see a failed push or missing contribution. Always double-check spelling.

Real-world example: Fixing a missing contribution

I once worked on a documentation project where my commits weren't showing up in the GitHub contribution graph. After checking, I found that my git config email was set to [email protected] instead of [email protected].

Running git config --global user.email "[email protected]" resolved it. Within 15 minutes, GitHub updated the contribution calendar. The fix took less than a minute, but the delay had caused confusion during a sprint review.

This highlights why correct email setup matters. Even small errors impact visibility and collaboration.

What git config email is not

git config email does not authenticate you on remote servers. It's not a login credential. It doesn't grant access to private repos or trigger CI/CD pipelines.

It also doesn't replace SSH keys or personal access tokens. These are required for authentication when pushing to remotes. Git config email only labels your changes.

Some assume that setting git config email automatically verifies ownership. It doesn't. Platforms like GitHub still require you to confirm your email in the account settings. Without confirmation, your commits may be marked as unverified.

Best practices

Always set a valid, verified email. Use the same email across all repositories if you want consistent attribution. If you work across teams, consider using a dedicated work email.

Check your current settings with git config --get user.email. Run this in any repository to see which email Git will use for the next commit.

For new projects, set your email early. Run git config --global user.email "[email protected]" once after installing Git. This prevents issues later.

When switching between personal and work projects, use --local to avoid accidental misattribution. This keeps your identity clear and reduces merge conflicts due to conflicting authors.

Next steps

Verify your email in your GitHub or GitLab profile. Go to Settings > Emails and confirm the address used in git config email. Add it if missing.

Once set, your commits will appear correctly in pull requests, issue trackers, and contribution graphs. The difference is immediate and visible.

Use git config email to ensure your work is credited. It's a small step with lasting impact on your development record.