The difference between local and global Git configuration lies in the scope and application of the settings:
Local Configuration
- Scope: Local configuration applies only to a specific Git repository.
- Location: The settings are stored in the
.git/configfile within the repository directory. - Usage: Local configurations are used to customize settings that are relevant only to that particular project, such as repository-specific user information, remote repository URLs, or merge strategies.
- Command: You can set local configurations using the command:
git config --local <key> <value> - Example: Setting a specific user email for a project:
git config --local user.email "project@example.com"
Global Configuration
- Scope: Global configuration applies to all repositories for the current user on the system.
- Location: The settings are stored in the user's home directory, typically in a file named
.gitconfigor.config/git/config. - Usage: Global configurations are used for settings that should be consistent across all projects, such as user name, email, and default editor.
- Command: You can set global configurations using the command:
git config --global <key> <value> - Example: Setting a global user email:
git config --global user.email "user@example.com"
Summary
- Local config is specific to a single repository and overrides global settings for that repository.
- Global config applies to all repositories for the user and provides a default configuration that can be used across multiple projects.
This distinction allows for flexibility in managing Git settings, enabling users to customize their environment according to their needs at both the project and user levels.
