0
0
Gitdevops~5 mins

Git configuration (user.name, user.email) - Commands & Configuration

Choose your learning style9 modes available
Introduction
Git needs to know who you are to record your name and email in each change you make. Setting your user name and email ensures your work is properly credited.
When you install Git for the first time on your computer and want to identify yourself.
When you start working on a new project and want your commits to show your correct name and email.
When you use multiple computers and want to set your identity on each one.
When you want to change your email or name for future commits.
When you want to use a different identity for a specific project.
Commands
This command sets your full name globally on your computer for all Git projects. It tells Git to use "Alice Johnson" as your name in commits.
Terminal
git config --global user.name "Alice Johnson"
Expected OutputExpected
No output (command runs silently)
--global - Sets the configuration for all repositories on your computer.
This command sets your email address globally on your computer for all Git projects. It tells Git to use this email in commits.
Terminal
git config --global user.email "alice.johnson@example.com"
Expected OutputExpected
No output (command runs silently)
--global - Sets the configuration for all repositories on your computer.
This command shows all your current Git settings, including your user name and email, so you can verify they are set correctly.
Terminal
git config --list
Expected OutputExpected
user.name=Alice Johnson user.email=alice.johnson@example.com ...
This command sets your user name only for the current Git project, overriding the global setting.
Terminal
git config user.name "Bob Smith"
Expected OutputExpected
No output (command runs silently)
This command sets your email only for the current Git project, overriding the global setting.
Terminal
git config user.email "bob.smith@example.com"
Expected OutputExpected
No output (command runs silently)
Key Concept

If you remember nothing else, remember: setting user.name and user.email tells Git who made each change.

Common Mistakes
Not setting user.name and user.email before making commits.
Git will use default or empty values, so your commits won't show your identity.
Always run git config --global user.name and git config --global user.email before committing.
Using --global when you want to set identity only for one project.
Your global settings will override project-specific needs and cause confusion.
Omit --global to set user.name and user.email only for the current repository.
Typing the commands without quotes around names or emails with spaces.
Git will misinterpret the command and fail to set the value correctly.
Always put your name and email inside double quotes if they contain spaces.
Summary
Set your user.name and user.email globally to identify yourself in all Git commits.
Use git config --list to check your current Git configuration.
Override global settings per project by running git config without --global.