]> git.ipfire.org Git - thirdparty/git.git/blob - Documentation/git-config.txt
e608d5ffef236aeb9cb958477b9e1987db85887d
[thirdparty/git.git] / Documentation / git-config.txt
1 git-config(1)
2 =============
3
4 NAME
5 ----
6 git-config - Get and set repository or global options
7
8
9 SYNOPSIS
10 --------
11 [verse]
12 'git config' [<file-option>] [--type=<type>] [--comment=<value>] [--fixed-value] [--show-origin] [--show-scope] [-z|--null] <name> [<value> [<value-pattern>]]
13 'git config' [<file-option>] [--type=<type>] [--comment=<value>] --add <name> <value>
14 'git config' [<file-option>] [--type=<type>] [--comment=<value>] [--fixed-value] --replace-all <name> <value> [<value-pattern>]
15 'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] --get <name> [<value-pattern>]
16 'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] --get-all <name> [<value-pattern>]
17 'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] [--name-only] --get-regexp <name-regex> [<value-pattern>]
18 'git config' [<file-option>] [--type=<type>] [-z|--null] --get-urlmatch <name> <URL>
19 'git config' [<file-option>] [--fixed-value] --unset <name> [<value-pattern>]
20 'git config' [<file-option>] [--fixed-value] --unset-all <name> [<value-pattern>]
21 'git config' [<file-option>] --rename-section <old-name> <new-name>
22 'git config' [<file-option>] --remove-section <name>
23 'git config' [<file-option>] [--show-origin] [--show-scope] [-z|--null] [--name-only] -l | --list
24 'git config' [<file-option>] --get-color <name> [<default>]
25 'git config' [<file-option>] --get-colorbool <name> [<stdout-is-tty>]
26 'git config' [<file-option>] -e | --edit
27
28 DESCRIPTION
29 -----------
30 You can query/set/replace/unset options with this command. The name is
31 actually the section and the key separated by a dot, and the value will be
32 escaped.
33
34 Multiple lines can be added to an option by using the `--add` option.
35 If you want to update or unset an option which can occur on multiple
36 lines, a `value-pattern` (which is an extended regular expression,
37 unless the `--fixed-value` option is given) needs to be given. Only the
38 existing values that match the pattern are updated or unset. If
39 you want to handle the lines that do *not* match the pattern, just
40 prepend a single exclamation mark in front (see also <<EXAMPLES>>),
41 but note that this only works when the `--fixed-value` option is not
42 in use.
43
44 The `--type=<type>` option instructs 'git config' to ensure that incoming and
45 outgoing values are canonicalize-able under the given <type>. If no
46 `--type=<type>` is given, no canonicalization will be performed. Callers may
47 unset an existing `--type` specifier with `--no-type`.
48
49 When reading, the values are read from the system, global and
50 repository local configuration files by default, and options
51 `--system`, `--global`, `--local`, `--worktree` and
52 `--file <filename>` can be used to tell the command to read from only
53 that location (see <<FILES>>).
54
55 When writing, the new value is written to the repository local
56 configuration file by default, and options `--system`, `--global`,
57 `--worktree`, `--file <filename>` can be used to tell the command to
58 write to that location (you can say `--local` but that is the
59 default).
60
61 This command will fail with non-zero status upon error. Some exit
62 codes are:
63
64 - The section or key is invalid (ret=1),
65 - no section or name was provided (ret=2),
66 - the config file is invalid (ret=3),
67 - the config file cannot be written (ret=4),
68 - you try to unset an option which does not exist (ret=5),
69 - you try to unset/set an option for which multiple lines match (ret=5), or
70 - you try to use an invalid regexp (ret=6).
71
72 On success, the command returns the exit code 0.
73
74 A list of all available configuration variables can be obtained using the
75 `git help --config` command.
76
77 [[OPTIONS]]
78 OPTIONS
79 -------
80
81 --replace-all::
82 Default behavior is to replace at most one line. This replaces
83 all lines matching the key (and optionally the `value-pattern`).
84
85 --add::
86 Adds a new line to the option without altering any existing
87 values. This is the same as providing '^$' as the `value-pattern`
88 in `--replace-all`.
89
90 --comment <value>::
91 Append a comment to new or modified lines. A '#' character will be
92 unconditionally prepended to the value. The value must not contain
93 linefeed characters (no multi-line comments are permitted).
94
95 --get::
96 Get the value for a given key (optionally filtered by a regex
97 matching the value). Returns error code 1 if the key was not
98 found and the last value if multiple key values were found.
99
100 --get-all::
101 Like get, but returns all values for a multi-valued key.
102
103 --get-regexp::
104 Like --get-all, but interprets the name as a regular expression and
105 writes out the key names. Regular expression matching is currently
106 case-sensitive and done against a canonicalized version of the key
107 in which section and variable names are lowercased, but subsection
108 names are not.
109
110 --get-urlmatch <name> <URL>::
111 When given a two-part <name> as <section>.<key>, the value for
112 <section>.<URL>.<key> whose <URL> part matches the best to the
113 given URL is returned (if no such key exists, the value for
114 <section>.<key> is used as a fallback). When given just the
115 <section> as name, do so for all the keys in the section and
116 list them. Returns error code 1 if no value is found.
117
118 --global::
119 For writing options: write to global `~/.gitconfig` file
120 rather than the repository `.git/config`, write to
121 `$XDG_CONFIG_HOME/git/config` file if this file exists and the
122 `~/.gitconfig` file doesn't.
123 +
124 For reading options: read only from global `~/.gitconfig` and from
125 `$XDG_CONFIG_HOME/git/config` rather than from all available files.
126 +
127 See also <<FILES>>.
128
129 --system::
130 For writing options: write to system-wide
131 `$(prefix)/etc/gitconfig` rather than the repository
132 `.git/config`.
133 +
134 For reading options: read only from system-wide `$(prefix)/etc/gitconfig`
135 rather than from all available files.
136 +
137 See also <<FILES>>.
138
139 --local::
140 For writing options: write to the repository `.git/config` file.
141 This is the default behavior.
142 +
143 For reading options: read only from the repository `.git/config` rather than
144 from all available files.
145 +
146 See also <<FILES>>.
147
148 --worktree::
149 Similar to `--local` except that `$GIT_DIR/config.worktree` is
150 read from or written to if `extensions.worktreeConfig` is
151 enabled. If not it's the same as `--local`. Note that `$GIT_DIR`
152 is equal to `$GIT_COMMON_DIR` for the main working tree, but is of
153 the form `$GIT_DIR/worktrees/<id>/` for other working trees. See
154 linkgit:git-worktree[1] to learn how to enable
155 `extensions.worktreeConfig`.
156
157 -f <config-file>::
158 --file <config-file>::
159 For writing options: write to the specified file rather than the
160 repository `.git/config`.
161 +
162 For reading options: read only from the specified file rather than from all
163 available files.
164 +
165 See also <<FILES>>.
166
167 --blob <blob>::
168 Similar to `--file` but use the given blob instead of a file. E.g.
169 you can use 'master:.gitmodules' to read values from the file
170 '.gitmodules' in the master branch. See "SPECIFYING REVISIONS"
171 section in linkgit:gitrevisions[7] for a more complete list of
172 ways to spell blob names.
173
174 --remove-section::
175 Remove the given section from the configuration file.
176
177 --rename-section::
178 Rename the given section to a new name.
179
180 --unset::
181 Remove the line matching the key from config file.
182
183 --unset-all::
184 Remove all lines matching the key from config file.
185
186 -l::
187 --list::
188 List all variables set in config file, along with their values.
189
190 --fixed-value::
191 When used with the `value-pattern` argument, treat `value-pattern` as
192 an exact string instead of a regular expression. This will restrict
193 the name/value pairs that are matched to only those where the value
194 is exactly equal to the `value-pattern`.
195
196 --type <type>::
197 'git config' will ensure that any input or output is valid under the given
198 type constraint(s), and will canonicalize outgoing values in `<type>`'s
199 canonical form.
200 +
201 Valid `<type>`'s include:
202 +
203 - 'bool': canonicalize values as either "true" or "false".
204 - 'int': canonicalize values as simple decimal numbers. An optional suffix of
205 'k', 'm', or 'g' will cause the value to be multiplied by 1024, 1048576, or
206 1073741824 upon input.
207 - 'bool-or-int': canonicalize according to either 'bool' or 'int', as described
208 above.
209 - 'path': canonicalize by expanding a leading `~` to the value of `$HOME` and
210 `~user` to the home directory for the specified user. This specifier has no
211 effect when setting the value (but you can use `git config section.variable
212 ~/` from the command line to let your shell do the expansion.)
213 - 'expiry-date': canonicalize by converting from a fixed or relative date-string
214 to a timestamp. This specifier has no effect when setting the value.
215 - 'color': When getting a value, canonicalize by converting to an ANSI color
216 escape sequence. When setting a value, a sanity-check is performed to ensure
217 that the given value is canonicalize-able as an ANSI color, but it is written
218 as-is.
219 +
220
221 --bool::
222 --int::
223 --bool-or-int::
224 --path::
225 --expiry-date::
226 Historical options for selecting a type specifier. Prefer instead `--type`
227 (see above).
228
229 --no-type::
230 Un-sets the previously set type specifier (if one was previously set). This
231 option requests that 'git config' not canonicalize the retrieved variable.
232 `--no-type` has no effect without `--type=<type>` or `--<type>`.
233
234 -z::
235 --null::
236 For all options that output values and/or keys, always
237 end values with the null character (instead of a
238 newline). Use newline instead as a delimiter between
239 key and value. This allows for secure parsing of the
240 output without getting confused e.g. by values that
241 contain line breaks.
242
243 --name-only::
244 Output only the names of config variables for `--list` or
245 `--get-regexp`.
246
247 --show-origin::
248 Augment the output of all queried config options with the
249 origin type (file, standard input, blob, command line) and
250 the actual origin (config file path, ref, or blob id if
251 applicable).
252
253 --show-scope::
254 Similar to `--show-origin` in that it augments the output of
255 all queried config options with the scope of that value
256 (worktree, local, global, system, command).
257
258 --get-colorbool <name> [<stdout-is-tty>]::
259
260 Find the color setting for `<name>` (e.g. `color.diff`) and output
261 "true" or "false". `<stdout-is-tty>` should be either "true" or
262 "false", and is taken into account when configuration says
263 "auto". If `<stdout-is-tty>` is missing, then checks the standard
264 output of the command itself, and exits with status 0 if color
265 is to be used, or exits with status 1 otherwise.
266 When the color setting for `name` is undefined, the command uses
267 `color.ui` as fallback.
268
269 --get-color <name> [<default>]::
270
271 Find the color configured for `name` (e.g. `color.diff.new`) and
272 output it as the ANSI color escape sequence to the standard
273 output. The optional `default` parameter is used instead, if
274 there is no color configured for `name`.
275 +
276 `--type=color [--default=<default>]` is preferred over `--get-color`
277 (but note that `--get-color` will omit the trailing newline printed by
278 `--type=color`).
279
280 -e::
281 --edit::
282 Opens an editor to modify the specified config file; either
283 `--system`, `--global`, or repository (default).
284
285 --[no-]includes::
286 Respect `include.*` directives in config files when looking up
287 values. Defaults to `off` when a specific file is given (e.g.,
288 using `--file`, `--global`, etc) and `on` when searching all
289 config files.
290
291 --default <value>::
292 When using `--get`, and the requested variable is not found, behave as if
293 <value> were the value assigned to the that variable.
294
295 CONFIGURATION
296 -------------
297 `pager.config` is only respected when listing configuration, i.e., when
298 using `--list` or any of the `--get-*` which may return multiple results.
299 The default is to use a pager.
300
301 [[FILES]]
302 FILES
303 -----
304
305 By default, 'git config' will read configuration options from multiple
306 files:
307
308 $(prefix)/etc/gitconfig::
309 System-wide configuration file.
310
311 $XDG_CONFIG_HOME/git/config::
312 ~/.gitconfig::
313 User-specific configuration files. When the XDG_CONFIG_HOME environment
314 variable is not set or empty, $HOME/.config/ is used as
315 $XDG_CONFIG_HOME.
316 +
317 These are also called "global" configuration files. If both files exist, both
318 files are read in the order given above.
319
320 $GIT_DIR/config::
321 Repository specific configuration file.
322
323 $GIT_DIR/config.worktree::
324 This is optional and is only searched when
325 `extensions.worktreeConfig` is present in $GIT_DIR/config.
326
327 You may also provide additional configuration parameters when running any
328 git command by using the `-c` option. See linkgit:git[1] for details.
329
330 Options will be read from all of these files that are available. If the
331 global or the system-wide configuration files are missing or unreadable they
332 will be ignored. If the repository configuration file is missing or unreadable,
333 'git config' will exit with a non-zero error code. An error message is produced
334 if the file is unreadable, but not if it is missing.
335
336 The files are read in the order given above, with last value found taking
337 precedence over values read earlier. When multiple values are taken then all
338 values of a key from all files will be used.
339
340 By default, options are only written to the repository specific
341 configuration file. Note that this also affects options like `--replace-all`
342 and `--unset`. *'git config' will only ever change one file at a time*.
343
344 You can limit which configuration sources are read from or written to by
345 specifying the path of a file with the `--file` option, or by specifying a
346 configuration scope with `--system`, `--global`, `--local`, or `--worktree`.
347 For more, see <<OPTIONS>> above.
348
349 [[SCOPES]]
350 SCOPES
351 ------
352
353 Each configuration source falls within a configuration scope. The scopes
354 are:
355
356 system::
357 $(prefix)/etc/gitconfig
358
359 global::
360 $XDG_CONFIG_HOME/git/config
361 +
362 ~/.gitconfig
363
364 local::
365 $GIT_DIR/config
366
367 worktree::
368 $GIT_DIR/config.worktree
369
370 command::
371 GIT_CONFIG_{COUNT,KEY,VALUE} environment variables (see <<ENVIRONMENT>>
372 below)
373 +
374 the `-c` option
375
376 With the exception of 'command', each scope corresponds to a command line
377 option: `--system`, `--global`, `--local`, `--worktree`.
378
379 When reading options, specifying a scope will only read options from the
380 files within that scope. When writing options, specifying a scope will write
381 to the files within that scope (instead of the repository specific
382 configuration file). See <<OPTIONS>> above for a complete description.
383
384 Most configuration options are respected regardless of the scope it is
385 defined in, but some options are only respected in certain scopes. See the
386 respective option's documentation for the full details.
387
388 Protected configuration
389 ~~~~~~~~~~~~~~~~~~~~~~~
390
391 Protected configuration refers to the 'system', 'global', and 'command' scopes.
392 For security reasons, certain options are only respected when they are
393 specified in protected configuration, and ignored otherwise.
394
395 Git treats these scopes as if they are controlled by the user or a trusted
396 administrator. This is because an attacker who controls these scopes can do
397 substantial harm without using Git, so it is assumed that the user's environment
398 protects these scopes against attackers.
399
400 [[ENVIRONMENT]]
401 ENVIRONMENT
402 -----------
403
404 GIT_CONFIG_GLOBAL::
405 GIT_CONFIG_SYSTEM::
406 Take the configuration from the given files instead from global or
407 system-level configuration. See linkgit:git[1] for details.
408
409 GIT_CONFIG_NOSYSTEM::
410 Whether to skip reading settings from the system-wide
411 $(prefix)/etc/gitconfig file. See linkgit:git[1] for details.
412
413 See also <<FILES>>.
414
415 GIT_CONFIG_COUNT::
416 GIT_CONFIG_KEY_<n>::
417 GIT_CONFIG_VALUE_<n>::
418 If GIT_CONFIG_COUNT is set to a positive number, all environment pairs
419 GIT_CONFIG_KEY_<n> and GIT_CONFIG_VALUE_<n> up to that number will be
420 added to the process's runtime configuration. The config pairs are
421 zero-indexed. Any missing key or value is treated as an error. An empty
422 GIT_CONFIG_COUNT is treated the same as GIT_CONFIG_COUNT=0, namely no
423 pairs are processed. These environment variables will override values
424 in configuration files, but will be overridden by any explicit options
425 passed via `git -c`.
426 +
427 This is useful for cases where you want to spawn multiple git commands
428 with a common configuration but cannot depend on a configuration file,
429 for example when writing scripts.
430
431 GIT_CONFIG::
432 If no `--file` option is provided to `git config`, use the file
433 given by `GIT_CONFIG` as if it were provided via `--file`. This
434 variable has no effect on other Git commands, and is mostly for
435 historical compatibility; there is generally no reason to use it
436 instead of the `--file` option.
437
438 [[EXAMPLES]]
439 EXAMPLES
440 --------
441
442 Given a .git/config like this:
443
444 ------------
445 #
446 # This is the config file, and
447 # a '#' or ';' character indicates
448 # a comment
449 #
450
451 ; core variables
452 [core]
453 ; Don't trust file modes
454 filemode = false
455
456 ; Our diff algorithm
457 [diff]
458 external = /usr/local/bin/diff-wrapper
459 renames = true
460
461 ; Proxy settings
462 [core]
463 gitproxy=proxy-command for kernel.org
464 gitproxy=default-proxy ; for all the rest
465
466 ; HTTP
467 [http]
468 sslVerify
469 [http "https://weak.example.com"]
470 sslVerify = false
471 cookieFile = /tmp/cookie.txt
472 ------------
473
474 you can set the filemode to true with
475
476 ------------
477 % git config core.filemode true
478 ------------
479
480 The hypothetical proxy command entries actually have a postfix to discern
481 what URL they apply to. Here is how to change the entry for kernel.org
482 to "ssh".
483
484 ------------
485 % git config core.gitproxy '"ssh" for kernel.org' 'for kernel.org$'
486 ------------
487
488 This makes sure that only the key/value pair for kernel.org is replaced.
489
490 To delete the entry for renames, do
491
492 ------------
493 % git config --unset diff.renames
494 ------------
495
496 If you want to delete an entry for a multivar (like core.gitproxy above),
497 you have to provide a regex matching the value of exactly one line.
498
499 To query the value for a given key, do
500
501 ------------
502 % git config --get core.filemode
503 ------------
504
505 or
506
507 ------------
508 % git config core.filemode
509 ------------
510
511 or, to query a multivar:
512
513 ------------
514 % git config --get core.gitproxy "for kernel.org$"
515 ------------
516
517 If you want to know all the values for a multivar, do:
518
519 ------------
520 % git config --get-all core.gitproxy
521 ------------
522
523 If you like to live dangerously, you can replace *all* core.gitproxy by a
524 new one with
525
526 ------------
527 % git config --replace-all core.gitproxy ssh
528 ------------
529
530 However, if you really only want to replace the line for the default proxy,
531 i.e. the one without a "for ..." postfix, do something like this:
532
533 ------------
534 % git config core.gitproxy ssh '! for '
535 ------------
536
537 To actually match only values with an exclamation mark, you have to
538
539 ------------
540 % git config section.key value '[!]'
541 ------------
542
543 To add a new proxy, without altering any of the existing ones, use
544
545 ------------
546 % git config --add core.gitproxy '"proxy-command" for example.com'
547 ------------
548
549 An example to use customized color from the configuration in your
550 script:
551
552 ------------
553 #!/bin/sh
554 WS=$(git config --get-color color.diff.whitespace "blue reverse")
555 RESET=$(git config --get-color "" "reset")
556 echo "${WS}your whitespace color or blue reverse${RESET}"
557 ------------
558
559 For URLs in `https://weak.example.com`, `http.sslVerify` is set to
560 false, while it is set to `true` for all others:
561
562 ------------
563 % git config --type=bool --get-urlmatch http.sslverify https://good.example.com
564 true
565 % git config --type=bool --get-urlmatch http.sslverify https://weak.example.com
566 false
567 % git config --get-urlmatch http https://weak.example.com
568 http.cookieFile /tmp/cookie.txt
569 http.sslverify false
570 ------------
571
572 include::config.txt[]
573
574 BUGS
575 ----
576 When using the deprecated `[section.subsection]` syntax, changing a value
577 will result in adding a multi-line key instead of a change, if the subsection
578 is given with at least one uppercase character. For example when the config
579 looks like
580
581 --------
582 [section.subsection]
583 key = value1
584 --------
585
586 and running `git config section.Subsection.key value2` will result in
587
588 --------
589 [section.subsection]
590 key = value1
591 key = value2
592 --------
593
594
595 GIT
596 ---
597 Part of the linkgit:git[1] suite