The git2r package gives you programmatic access to Git repositories
from R. Internally the package uses the libgit2 library which is a
pure C implementation of the Git core methods. For more information
about libgit2, check out libgit2’s website
(http://libgit2.github.com).
Suggestions, bugs, forks and pull requests are appreciated. Get in
touch.
Installation
To install the version available on CRAN:
install.packages("git2r")
To install the development version of git2r, it’s easiest to use the
devtools package:
The central object in the git2r package is the S3 class
git_repository. The following three methods can instantiate a
repository; init, repository and clone.
Create a new repository
Create a new repository in a temporary directory using init
library(git2r)
#> Loading required package: methods
## Create a temporary directory to hold the repository
path <- tempfile(pattern="git2r-")
dir.create(path)
## Initialize the repository
repo <- init(path)
## Display a brief summary of the new repository
repo
## Create a temporary directory to hold the repository
path <- tempfile(pattern="git2r-")
dir.create(path)
## Initialize the repository
repo <- init(path, bare=TRUE)
## Check if repository is bare
is_bare(repo)
#> [1] TRUE
Clone a repository
## Create a temporary directory to hold the repository
path <- file.path(tempfile(pattern="git2r-"), "git2r")
dir.create(path, recursive=TRUE)
## Clone the git2r repository
repo <- clone("https://github.com/ropensci/git2r", path)
## List all commits in repository
commits(repo)[[1]] # Truncated here for readability
#> Commit: 6fb440133765e80649de8d714eaea17b114bd0a7
#> Author: Stefan Widgren <stefan.widgren@gmail.com>
#> When: 2014-04-22 21:43:19
#> Summary: Fixed clone progress to end line with newline
## Get HEAD of repository
repository_head(repo)
#> [6fb440] (Local) (HEAD) master
## Check if HEAD is head
is_head(repository_head(repo))
#> [1] TRUE
## Check if HEAD is local
is_local(repository_head(repo))
Introduction
The
git2rpackage gives you programmatic access to Git repositories from R. Internally the package uses the libgit2 library which is a pure C implementation of the Git core methods. For more information about libgit2, check out libgit2’s website (http://libgit2.github.com).Suggestions, bugs, forks and pull requests are appreciated. Get in touch.
Installation
To install the version available on CRAN:
To install the development version of
git2r, it’s easiest to use the devtools package:Usage
Repository
The central object in the
git2rpackage is the S3 classgit_repository. The following three methods can instantiate a repository;init,repositoryandclone.Create a new repository
Create a new repository in a temporary directory using
initCreate a new bare repository
Clone a repository
Open an existing repository
Configuration
Commit
License
The
git2rpackage is licensed under the GPLv2.