Global and local
- Git course
- Beginner
- Lesson 15/80
- 4 min
Learn the difference between global and local settings.
Global and local settings
You can define Git settings at different scopes. The --global flag applies the setting to all repositories on your computer, while --local applies only to the current repository.
git config --global user.name "Ali Kaya"
git config --local user.name "Ali (Work)"Local settings always override global settings and take priority.
Location of configuration files
Global settings are stored in the ~/.gitconfig file in your user home directory. Local settings are stored in the .git/config file inside the project.
# Inside a repository, the local file is used
cat .git/configIf you set a configuration inside a repository without any flag, Git writes to the local file by default.
Practice Set global name
Set the user.name setting to "Selin Tekin" globally across all repositories and then print it with git config --global user.name.
Starter code
# Global kullanıcı adını ayarla ve ekrana yazdırSample solution
git config --global user.name "Selin Tekin"
git config --global user.nameExpected output
Selin Tekin
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What should be done to use an author name different from global settings in a specific project?
- The global setting must be deleted
- Git must be reinstalled
- The .git folder must be deleted
- Set name with --local in that repo Correct answer
Explanation: To configure a setting specific to a repository, use `--local` inside that repository; it overrides global settings.
2 Global user name
git config ____ user.name "Can Er"
git config --global user.name "Can Er"
Explanation: The `--global` flag is used to set a configuration applicable to all repositories.
3 Scopes and files
| Term | Meaning |
|---|---|
--global |
Affects all repositories |
--local |
Affects only that repository |
.git/config |
Local settings file |
~/.gitconfig |
Global settings file |