๐ŸŽ‰ Special Offer !    Code: GET300OFF    Flat โ‚น300 OFF on every Java Course
Grab Deal ๐Ÿš€

How to Configure Git using Global


Introduction

  • Git configuration is the process of setting up user details, preferences and behaviors for Git.
  • Git configuration helps Git know who you are and how it should work.
  • It ensures that your commits have your name and email, making it easy to track who made the changes.
  • Configuration settings are stored in Git config files at different levels:
    • System-wide (--system): Applies settings globally for all users on the computer.
    • User-specific (--global): Applies settings for a specific user account.
    • Repository-specific (--local): Applies settings only to a specific project/repository.

Steps for Git Configurations

Step 1 : Install Git & Verify Git Installation
  1. Before configuring Git, you must install Git on your system.
  2. Click Here for deep steps of Git Installation
Step 2 : Configure Git Username & Email (Mandatory)
  1. Git requires your username and email to associate commits with your identity.
  2. Set Global Username:
    git config --global user.name "Your Name"
  3. Set Global Email:
    git config --global user.email "your-email@example.com"
Step 3: Verify Your Git Configuration
  1. To check if the details are set correctly, run:
    git config --global --list
  2. Output Example:
    user.name=Your Name
    user.email=your-email@example.com
    core.editor=whatever code editor you have selected
Image showing Git Configurations
Git Check Configurations

Other Useful Configuration Related Commands

Remove only user.name and user.email settings :-
  • git config --global --unset user.name
    git config --global --unset user.email
Delete .gitconfig file :-
  • rm ~/.gitconfig
  • It will delete the .gitconfig file from C:\Users\PcName location
Configure Default Text Editor for Git :-
  • By default, Git may use Vim as the editor. If you prefer another editor, then you can use below commands:
  • git config --global core.editor "vim" - For Vim
  • git config --global core.editor "code --wait" - For VS Code
  • git config --global core.editor "notepad" - For windows notepad
Open Git Editor for Editing Configuration :-
  • git config --global --edit
  • This will open the Git global configuration file (.gitconfig) in the editor.
Set Default Git Branch Name (Recommended) :-
  • By default, Git used to create a branch named "master" for new repositories, but now it recommends using "main" instead. Set it with:
  • git config --global init.defaultBranch main
Set Up Git Caching for Credentials (Optional but Useful) :-
  • If you use GitHub and don't want to enter our password each time, enable credential caching:
  • git config --global credential.helper cache