Git Config: Configure Git Settings
What is git config
?
The git config
command is used to configure Git settings, such as your username, email, default editor, and aliases. These settings help Git identify you and manage repository behavior.
Types of Git Configuration Levels
Git settings are stored in configuration files at different levels:
Level | Scope | Command |
---|---|---|
System | This applies to all users on the system | git config --system |
Global | Applies to a specific user (across all repositories) | git config --global |
Local | Applies only to a particular repository | git config --local |
By default, Git reads settings from all levels, but local settings override global settings, and global settings override system settings.
Basic Git Config Commands
1. Set Username and Email (Required for Commits)
Every commit you make will be associated with this name and email.
To verify:
2. Change the Default Text Editor
By default, Git uses Vim. You can change it to another editor:
- VS Code
- Nano
- Sublime Text
- Vim
3. Enable Colored Output
Make Git outputs more readable with colors:
4. Set Up Aliases (Shortcuts for Commands)
You can create custom shortcuts for frequently used Git commands:
To check aliases:
5. Set the Default Branch Name
New Git versions use main
instead of master
as the default branch:
6. Configure Git to Store Credentials (Avoid Login Prompts)
If you frequently push to remote repositories and want to avoid entering your username and password every time:
This will save credentials in a plain text file (not recommended for sensitive accounts).
For macOS, use:
7. View Git Configuration
To see all your Git settings:
To check a specific setting, such as the username:
8. Remove a Git Config Setting
To delete a setting, use:
To remove all global settings:
Conclusion
The git config
command allows you to customize Git behavior, making it easier to use and personalize. Whether setting up your identity, defining aliases, or changing the editor, these configurations enhance your Git experience.
Would you like more details or examples? 🚀