How to set important Git config global properties

How to set important Git config global properties

Setting Important Global Git Configurations

Git allows you to configure global settings that apply to all repositories on your system. These settings include user information, default branches, alias shortcuts, and more.

1. Check the Current Git Configuration

To see your global settings, run:

git config --global --list

📌 This displays all configured global properties.

2. Set Essential Git Configurations

🔹 Set Your Name & Email (Required for Commits)

Every Git commit requires a name and email:

git config --global user.name "Your Name" git config --global user.email "your.email@example.com"

🔹 Verify:

git config --global user.name git config --global user.email

🔹 Set Default Branch Name

By default, Git creates new repositories with a branch called master. To change it to main:

git config --global init.defaultBranch main

📌 New repositories will start with main instead of master.

🔹 Enable Colorized Output (Easier to Read)

git config --global color.ui auto

📌 Git will now display colored output for better visibility.

🔹 Configure Default Text Editor

Set your preferred editor for Git commit messages:

git config --global core.editor "code --wait"

📌 This sets VS Code as your Git editor. Replace with:

  • "nano" for Nano
  • "vim" for Vim
  • "subl -n -w" for Sublime Text

🔹 Set Up a Global .gitignore

To prevent certain files from being tracked across all repositories:

git config --global core.excludesfile ~/.gitignore_global

Then create and edit the ignore file:

touch ~/.gitignore_global nano ~/.gitignore_global

Add common ignores like:

.DS_Store node_modules/ *.log

🔹 Set Up a Default Merge Tool

To resolve conflicts more easily, set a merge tool:

git config --global merge.tool vimdiff # or "code" for VS Code

🔹 Enable Auto-Correction for Mistyped Commands

If you mistype a Git command, Git will auto-correct it:

git config --global help.autocorrect 1

📌 Git will suggest the closest matching command.

🔹 Cache Your SSH Credentials

If using SSH authentication, avoid repeated passphrase prompts:

git config --global credential.helper cache

📌 This temporarily stores your SSH credentials.

3. Reset Global Git Configurations

If you need to reset a global property:

git config --global --unset <property>

For example, to remove the global editor setting:

git config --global --unset core.editor

🔹 Conclusion

Setting up Git configurations properly ensures a smoother workflow and prevents common issues. With these settings, you’ll be able to work efficiently and avoid unnecessary setup for each new repository.

Do you need help configuring something specific? Let me know! 🚀

Souy Soeng

Souy Soeng

Our website teaches and reads PHP, Framework Laravel, and how to download Admin template sample source code free. Thank you for being so supportive!

Github

Post a Comment

CAN FEEDBACK
close