Git Configuration Levels
Git configuration settings can be managed at different levels to provide flexibility and control over how Git behaves. These levels are:
- System Level: Configuration settings applied at the system level affect all users and repositories on a given machine.
- Global Level: Configuration settings applied at the global level affect the current user across all repositories on the machine.
- Local Level: Configuration settings applied at the local level affect only the specific repository.
Let's explore each level in detail:
System Level Configuration
System-level configuration settings are stored in the /etc/gitconfig
file. These settings apply to all users and repositories on the machine. To set a system-level configuration, you can use the git config --system
command:
git config --system user.name "John Doe"
git config --system user.email "[email protected]"
This will set the user.name
and user.email
configuration options for all users and repositories on the system.
Global Level Configuration
Global-level configuration settings are stored in the ~/.gitconfig
file (or %USERPROFILE%\.gitconfig
on Windows). These settings affect the current user across all repositories on the machine. To set a global-level configuration, you can use the git config --global
command:
git config --global user.name "Jane Doe"
git config --global user.email "[email protected]"
This will set the user.name
and user.email
configuration options for the current user across all repositories.
Local Level Configuration
Local-level configuration settings are stored in the .git/config
file within a specific repository. These settings only affect the repository they are set in. To set a local-level configuration, you can use the git config
command without any additional options:
git config user.name "Project Team Member"
git config user.email "[email protected]"
This will set the user.name
and user.email
configuration options for the current repository only.