Get or set Git options, as git config does on the command line. Global
settings affect all of a user's Git operations (git config --global),
whereas local settings are scoped to a specific repository (git config --local). When both exist, local options always win. Four functions address
the four possible combinations of getting vs setting and global vs. local.
| local | global | |
| get | git_config() | git_config_global() |
| set | git_config_set() | git_config_global_set() |
Usage
git_config(repo = ".")
git_config_global()
git_config_set(name, value, repo = ".")
git_config_global_set(name, value)Arguments
- repo
The path to the git repository. If the directory is not a repository, parent directories are considered (see git_find). To disable this search, provide the filepath protected with
I(). When using this parameter, always explicitly call by name (i.e.repo =) because future versions of gert may have additional parameters.- name
Name of the option to set
- value
Value to set. Must be a string, logical, number or
NULL(to unset).
Value
git_config(): adata.frameof the Git options "in force" in the context ofrepo, one row per option. Thelevelcolumn reveals whether the option is determined from global or local config.git_config_global(): adata.frame, as forgit_config(), except only for global Git options.git_config_set(),git_config_global_set(): The previous value ofnamein local or global config, respectively. If this option was previously unset, returnsNULL. Returns invisibly.
Note
All entries in the name column are automatically normalised to
lowercase (see
https://libgit2.org/libgit2/#HEAD/type/git_config_entry for details).
See also
Other git:
git_archive,
git_branch(),
git_commit(),
git_diff(),
git_fetch(),
git_ignore,
git_merge(),
git_rebase(),
git_remote,
git_repo,
git_reset(),
git_signature(),
git_stash,
git_tag
Examples
# Set and inspect a local, custom Git option
r <- file.path(tempdir(), "gert-demo")
git_init(r)
previous <- git_config_set("aaa.bbb", "ccc", repo = r)
previous
#> NULL
cfg <- git_config(repo = r)
subset(cfg, level == "local")
#> # A tibble: 5 × 3
#> name value level
#> <chr> <chr> <chr>
#> 1 core.bare false local
#> 2 core.repositoryformatversion 0 local
#> 3 core.filemode true local
#> 4 core.logallrefupdates true local
#> 5 aaa.bbb ccc local
cfg$value[cfg$name == "aaa.bbb"]
#> [1] "ccc"
previous <- git_config_set("aaa.bbb", NULL, repo = r)
previous
#> [1] "ccc"
cfg <- git_config(repo = r)
subset(cfg, level == "local")
#> # A tibble: 4 × 3
#> name value level
#> <chr> <chr> <chr>
#> 1 core.bare false local
#> 2 core.repositoryformatversion 0 local
#> 3 core.filemode true local
#> 4 core.logallrefupdates true local
cfg$value[cfg$name == "aaa.bbb"]
#> character(0)
unlink(r, recursive = TRUE)
if (FALSE) { # \dontrun{
# Set global Git options
git_config_global_set("user.name", "Your Name")
git_config_global_set("user.email", "your@email.com")
git_config_global()
} # }
