Back to Blog
Lesson 3 of the Git & GitHub: Git & GitHub from Zero course
GitJuly 14, 20264 min read

Configuring User Identity: Essential Git Setup for Beginners

Learn how to set your global user name and email in Git. Properly configuring your user identity is essential for accurate attribution in project history.

gitgit-configversion-controlterminalsetup

Previously in this course, we covered the foundational concepts of version control in Introduction to Version Control and ensured your machine was ready to run Git commands in Git Installation: Set Up Your Terminal for Version Control.

Now that Git is installed, we need to tell it who you are. Every commit you create in Git is "signed" with your identity. If you skip this step, Git won't know who made the changes, making it impossible for collaborators to know who to credit (or blame) for specific lines of code.

Why Git Identity Matters

In a distributed system, every contributor has their own local repository. When you commit your work, Git bundles a "snapshot" of your files along with metadata: the date, a commit message, and, crucially, your identity.

Without a configured identity, Git might try to guess your name based on your computer's system username, which is often unhelpful (e.g., user@macbook-pro). By explicitly setting your user.name and user.email, you ensure professional, accurate attribution across any project you work on.

The git config Command

We use the git config command to manage settings. You can set configurations at three different levels, but for your primary identity, we use the --global flag. This applies your settings to every repository on your current machine.

Setting Your Global Identity

Open your terminal and run the following commands, replacing the placeholders with your actual information.

Bash
# Set your display name
git config --global user.name "Your Name"

# Set your email address
git config --global user.email "your.email@example.com"

Note: Use the email address associated with your GitHub account so that your commits are correctly linked to your profile once we start pushing code to the cloud.

Verifying Your Setup

After running the commands, it is best practice to verify that the changes were saved correctly. You can list all your global configurations using the --list flag:

Bash
git config --global --list

You should see an output similar to this:

TEXT
user.name=Your Name
user.email=your.email@example.com

Hands-on Exercise

Let’s confirm your environment is ready. Follow these steps:

  1. Open your terminal or command prompt.
  2. Run the git config --global user.name command with your preferred name.
  3. Run the git config --global user.email command with your primary email.
  4. Run git config --global --list to verify the output matches what you entered.
  5. If you made a mistake (e.g., a typo in your email), simply run the command again with the correct value; Git will overwrite the old setting.

Common Pitfalls

  • Using the wrong email: If you use a personal email for work projects or vice-versa, you might find your contributions don't show up in your GitHub "contribution graph." Stick to the email you use for your primary GitHub account.
  • Forgetting the --global flag: If you omit --global, the configuration is only applied to the current directory (if you are already inside a repository). If you aren't in a repository, the command will fail. Always use --global for your primary identity.
  • Case sensitivity: While user.name is flexible, user.email is often treated as case-sensitive by some platforms. It is safest to use lowercase for your email address.

Frequently Asked Questions

Q: Can I have different identities for different projects? A: Yes. If you work on a private project that requires a different email, navigate to that specific project folder in your terminal and run git config user.email "work@email.com" without the --global flag. This creates a "local" override that only applies to that specific repository.

Q: Where is this information stored? A: Git stores global configurations in a hidden file in your home directory called .gitconfig. You can view it by running cat ~/.gitconfig in your terminal.

Q: Does changing this affect my past commits? A: No. Your identity is baked into the commit object at the moment you create it. Changing your git config only affects future commits.

Recap

Properly configuring your identity is the final step in preparing your local development environment. By setting your user.name and user.email globally, you ensure that every line of code you write is correctly attributed to you. You’ve now moved past the installation phase and are ready to start interacting with the Git lifecycle.

Up next: We will create our first project folder and initialize it as a repository using git init.

Similar Posts