Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions book/01-introduction/sections/first-time-setup.asc
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,25 @@ You can also change them at any time by running through the commands again.
Git comes with a tool called `git config` that lets you get and set configuration variables that control all aspects of how Git looks and operates.(((git commands, config)))
These variables can be stored in three different places:

1. `/etc/gitconfig` file: Contains values applied to every user on the system and all their repositories.
1. `/etc/gitconfig` (/usr/local/etc/gitconfig on Debian): Contains values applied to every user on the system and all their repositories.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utterly false, Debian is no different:

$ sudo /usr/bin/git config --system --add foo.bar foo
$ cat /etc/gitconfig 
[foo]
        bar = foo

If you pass the option `--system` to `git config`, it reads and writes from this file specifically.
(Because this is a system configuration file, you would need administrative or superuser privilege to make changes to it.)
2. `~/.gitconfig` or `~/.config/git/config` file: Values specific personally to you, the user.
2. `~/.gitconfig` or `~/.config/git/config` (note ~ is root's home dir): Contains values specific personally to you, the user.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only if the current user is root (which should not happen), otherwise, it's current user's home dir.

You can make Git read and write to this file specifically by passing the `--global` option, and this affects _all_ of the repositories you work with on your system.
3. `config` file in the Git directory (that is, `.git/config`) of whatever repository you're currently using: Specific to that single repository.
3. `config` file in the Git directory (that is, `.git/config`) of whatever repository you're currently using: Contains values specific to that repository.
You can force Git to read from and write to this file with the `--local` option, but that is in fact the default.
(Unsurprisingly, you need to be located somewhere in a Git repository for this option to work properly.)

Each level overrides values in the previous level, so values in `.git/config` trump those in `/etc/gitconfig`.

On Windows systems, Git looks for the `.gitconfig` file in the `$HOME` directory (`C:\Users\$USER` for most people).
You can view all of your settings and where they are coming from using:

[source,console]
----
$sudo git config --list --show-origin
Copy link
Contributor

@aollier aollier Mar 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git config need not to be run with su privileges.

----
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


*Windows:* Git looks for the `.gitconfig` file in the `$HOME` directory (`C:\Users\$USER` for most people).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as for Linux users, so I guess it's useless to specify the case of Windows.

It also still looks for `/etc/gitconfig`, although it's relative to the MSys root, which is wherever you decide to install Git on your Windows system when you run the installer.
If you are using version 2.x or later of Git for Windows, there is also a system-level config file at
`C:\Documents and Settings\All Users\Application Data\Git\config` on Windows XP, and in `C:\ProgramData\Git\config` on Windows Vista and newer.
Expand Down