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