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