Open In App

How to Setup Git Using Git Config?

Last Updated : 11 Mar, 2025
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

Git is a powerful version control system that helps developers manage their code efficiently. To use Git effectively, you need to configure it properly using the git config command. This setup ensures that Git recognizes your identity, preferred settings, and workflow preferences.

How the git configuration works

  • Git settings are stored in different configuration files at system, global, and local levels, defining how Git behaves.
  • Local configurations take priority over global configurations, and global configurations override system configurations.
  • Git provides the git config command to set and modify various settings related to user identity, repository behavior, and preferences.
  • The git config –list command allows users to see currently applied settings from all configuration levels.
  • Users can create aliases, define default branches, and set up preferences to enhance workflow efficiency and usability.

Steps To Setup Git using Git Config

Step 1: Install git

The first thing you have to do is install git in your system to proceed further. Follow these articles according to your system.

Step 2: Check for git version

Now, if you have successfully installed Git, you can verify and check its version using the following command.

git --version

Step 3: Set global username

Set your name for all repositories using the command

git config --global user.name 'username'
Screenshot-2025-03-03-103913

Set global username

Step 4: Set global email

Set your email for all repositories by using the command

git config --global user.email 'user email'
Screenshot-2025-03-03-104043

Set global email

Step 5: Set local username and email

Set your name for the current repository before that you have to initialize a empty git repository. And then set the username and email.

git init
git config --local user.name 'username' 
git config --local user.email 'email'

Screenshot-2025-03-03-104629

Set local username

Screenshot-2025-03-03-104856

Set local email

Step 6: Configuring the Default Branch Name

By default, Git used to initialize repositories with the master branch. You can change this to main or any preferred name.

git config --global init.defaultBranch main
Screenshot-2025-03-03-105843

Set default branch name

Step 7: Create an alias for a command

Git aliases allow you to shorten commonly used commands. Allowing git st instead of git status to work the same

Screenshot-2025-03-03-110545

Create an alias for a command

Step 8: View all configurations

Shows all Git settings that have been made by the current user

git config --list
Screenshot-2025-03-03-110748

View all configurations

Step 9: Removing or Resetting Configurations

If you need to remove or reset any configurations, use:

git config --global --unset user.email

Or reset all settings to default:

rm ~/.gitconfig  # For Linux/Mac
del %USERPROFILE%\.gitconfig # For Windows

Conclusion

Setting up Git using git config is essential for a smooth version control experience. By properly configuring your identity, editor, branch naming, and other preferences, you ensure an efficient and productive workflow. Master these configurations to make Git work seamlessly for you!



Next Article

Similar Reads

three90RightbarBannerImg