git_config: Get and set Git configuration variables

Description Usage Arguments Details Value Functions References Examples

Description

git_config and convenience wrappers git_config_global and git_config_local can be used to get or set Git configuration. All rely on git2r::config().

Usage

1
2
3
4
5
git_config(..., where = c("de_facto", "local", "global"), repo = ".")

git_config_global(..., repo = ".")

git_config_local(..., repo = ".")

Arguments

...

The Git configuration variables to get or set. If unspecified, all are returned, i.e. the output should match the result of git config --list.

where

Specifies which variables. The default, de_facto, applies only to a query and requests the variables in force, i.e. where local repo variables override global user-level variables, when both are defined. local or global narrows the scope to the associated configuration file: for local, .git/config in the targetted repo, and for global, ~/.gitconfig in user's home directory. When setting, if where is unspecified, the local configuration is modified.

repo

Path to a Git repo. If unspecified, current working directory is checked to see if it is or is inside a Git repo.

Details

Variables can be listed by specifying the names as strings or in a unnamed list or vector of strings. Don't specify anything if you want to see them all. Non-existent variables will return value NULL.

Variables can be set by specifying them as arguments in variable = value form or as a named list. To unset a variable, i.e. git config --unset, specify NULL as the value.

When variables are set, the previous values are returned in an invisible named list, analogous to par or setwd. Such a list can be passed back in to git_config_local or git_config_global to restore the previous configuration.

Consult the git-config man page for a long yet non-comprehensive list of variables.

For future GitHub happiness, it is highly recommended that you set user.email to an email address that is associated with your GitHub account: https://help.github.com/articles/setting-your-email-in-git/.

Value

A named list of Git configuration variables, with class githug_list for pretty-printing purposes.

Functions

References

Getting Started - First-Time Git Setup from the Pro Git book by Scott Chacon and Ben Straub

Customizing Git - Git Configuration from the Pro Git book by Scott Chacon and Ben Straub

git-config man page

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
## see git config currently in effect, based on working directory
git_config()         # local > global, same as git_config(where = "de_facto")
git_config_local()   #                 same as git_config(where = "local")
git_config_global()  #                 same as git_config(where = "global")

## set and get global config
## Not run: 
## set and list global config
git_config_global(user.name = "thelma", user.email = "thelma@example.org")
git_config_global("user.name", "user.email")

## End(Not run)

## specify a Git repo
repo <- git_init(tempfile("githug-config-example-"))
git_config_local(repo = repo)

## switch working directory to the repo
owd <- setwd(repo)

## set local variables for current repo
git_config_local(user.name = "louise", user.email = "louise@example.org")

## get specific local variables, including a non-existent one
git_config_local("user.name", "color.branch", "user.email")

## set local variables, then restore
ocfg <- git_config_local(user.name = "oops", user.email = "oops@example.org")
git_config_local("user.name", "user.email")
git_config_local(ocfg)
git_config_local("user.name", "user.email")

## set a custom variable
ocfg <- git_config_local(githug.lol = "wut")
git_config_local("githug.lol")

setwd(owd)

jennybc/githug documentation built on May 19, 2019, 5:05 a.m.