
Last chance! 50% off unlimited learning
Sale ends in
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()
.
git_config(..., where = c("de_facto", "local", "global"), repo = ".")
git_config_global(..., repo = ".")
git_config_local(..., repo = ".")
git
config --list
.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.githug_list
for pretty-printing purposes.
git_config_global
: Get or set global Git config, a la git config
--global
git_config_local
: Get or set local Git config, a la git config
--local
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/.
Customizing Git - Git Configuration from the Pro Git book by Scott Chacon and Ben Straub
## 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)
Run the code above in your browser using DataLab