Git Config

Divya Srinivasan

 Configure Git

Before you start using Git, you need to tell it who you are.
This is important because every Git commit you make will include this information, helping track who made each change.

Username

This name will appear on all your commits. Set it with:

Example:

git config --global user.name "Your Name"

Email Address

Your email is linked to your Git commits. Set it like this:

Example:

git config --global user.email "you@example.com"
Replace the example email with your own.

Why Configure Git?

Git uses your name and email address to tag your commits, helping track who made which changes.
If you don’t set these details now, Git will ask for them the first time you make a commit.
By configuring them, you’ve completed the essential setup needed to start using Git right away.
You can now move on to the next chapter.

Viewing Your Git Configuration

You can check all your current Git settings by running:

Example: 

Show All Settings
git config --list
You’ll see output similar to this:
csharp
user.name=Your Name
user.email=you@example.com
core.editor=code --wait
alias.st=status
init.defaultbranch=main

Example: 

Check a Specific Setting
git config user.name

Output:


Your Name

Example: 

Check a Specific Setting
git config user.name

Output:

Your Name
This command shows the current value set for user.name in your Git configuration.

Default Branch Name

You can set the default name for the first branch created in all new repositories (e.g., use main instead of master):

Example:

 Change Default Branch Name
git config --global init.defaultBranch main
This way, whenever you run git init, your repository will start with a branch named main.

Configuration Levels

Git supports three levels of configuration:
System (applies to all users on the system):

git config --system
Global (applies to the current user):
git config --global
Local (applies only to the current repository):
git config --local
Order of precedence:
Local (current repository)
Global (current user)
System (all users)
This hierarchy allows you to customize Git settings differently for each repository, user, or system-wide. For instance, you might set a different default branch name or commit email for a specific repository without affecting others.

Example:

 Set a Local Configuration
Local settings affect only the current repository.
git config user.name "Project Name"

Example:

 Set a Global Configuration
Global settings apply to all repositories for the current user.
git config --global user.name "Global Name"

Example:

 Set a System Configuration
System settings apply to all repositories for all users on the system.
git config --system user.name "System Name"














Tags
Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send