Package: git2r 0.35.0.9000

Stefan Widgren

git2r: Provides Access to Git Repositories

Interface to the 'libgit2' library, which is a pure C implementation of the 'Git' core methods. Provides access to 'Git' repositories to extract data and running some basic 'Git' commands.

Authors:Stefan Widgren [aut, cre], Gabor Csardi [ctb], Gregory Jefferis [ctb], Jennifer Bryan [ctb], Jeroen Ooms [ctb], Jim Hester [ctb], John Blischak [ctb], Karthik Ram [ctb], Peter Carbonetto [ctb], Scott Chamberlain [ctb], Thomas Rosendal [ctb]

git2r_0.35.0.9000.tar.gz
git2r_0.35.0.9000.zip(r-4.5)git2r_0.35.0.9000.zip(r-4.4)git2r_0.35.0.9000.zip(r-4.3)
git2r_0.35.0.9000.tgz(r-4.5-x86_64)git2r_0.35.0.9000.tgz(r-4.5-arm64)git2r_0.35.0.9000.tgz(r-4.4-x86_64)git2r_0.35.0.9000.tgz(r-4.4-arm64)git2r_0.35.0.9000.tgz(r-4.3-x86_64)git2r_0.35.0.9000.tgz(r-4.3-arm64)
git2r_0.35.0.9000.tar.gz(r-4.5-noble)git2r_0.35.0.9000.tar.gz(r-4.4-noble)
git2r_0.35.0.9000.tgz(r-4.4-emscripten)git2r_0.35.0.9000.tgz(r-4.3-emscripten)
git2r.pdf |git2r.html
git2r/json (API)
NEWS

# Install 'git2r' in R:
install.packages('git2r', repos = c('https://ropensci.r-universe.dev', 'https://cloud.r-project.org'))

Bug tracker:https://github.com/ropensci/git2r/issues96 issues

Pkgdown site:https://docs.ropensci.org

Uses libs:
  • libgit2– Low-level Git library

On CRAN:git2r-0.35.0(2024-10-20)

Conda:

gitgit-clientlibgit2libgit2-library

13.86 score 218 stars 49 packages 836 scripts 77k downloads 4 mentions 99 exports 0 dependencies

Last updated 5 days agofrom:0020779188 (on main). Checks:9 OK, 3 ERROR. Indexed: yes.

TargetResultLatest binary
Doc / VignettesOKMar 04 2025
R-4.5-win-x86_64ERRORMar 04 2025
R-4.5-mac-x86_64OKMar 04 2025
R-4.5-mac-aarch64OKMar 04 2025
R-4.5-linux-x86_64OKMar 04 2025
R-4.4-win-x86_64ERRORMar 04 2025
R-4.4-mac-x86_64OKMar 04 2025
R-4.4-mac-aarch64OKMar 04 2025
R-4.4-linux-x86_64OKMar 04 2025
R-4.3-win-x86_64ERRORMar 04 2025
R-4.3-mac-x86_64OKMar 04 2025
R-4.3-mac-aarch64OKMar 04 2025

Exports:addahead_behindas.data.frameblameblob_createbranch_createbranch_deletebranch_get_upstreambranch_remote_namebranch_remote_urlbranch_renamebranch_set_upstreambranch_targetbranchesbundle_r_packagecheckoutclonecommitcommitsconfigcontentcontributionscred_envcred_ssh_keycred_tokencred_user_passdefault_signaturedescendant_ofdiffdiscover_repositoryfetchfetch_headsgit_config_fileshashhashfileheadin_repositoryindex_remove_bypathinitis_bareis_binaryis_blobis_branchis_commitis_detachedis_emptyis_headis_localis_mergeis_shallowis_tagis_treelast_commitlibgit2_featureslibgit2_versionlookuplookup_commitls_treemergemerge_basenote_createnote_default_refnote_removenotesodb_blobsodb_objectsparentspullpunch_cardpushreferencesreflogremote_addremote_lsremote_removeremote_renameremote_set_urlremote_urlremotesrepositoryrepository_headresetrevparse_singlerm_fileshassh_pathssl_cert_locationsstashstash_applystash_dropstash_liststash_popstatustagtag_deletetagstreewhenworkdir

Dependencies:

Citation

To cite package ‘git2r’ in publications use:

Widgren S (2025). git2r: Provides Access to Git Repositories. R package version 0.35.0.9000, , https://github.com/ropensci/git2r.

Corresponding BibTeX entry:

  @Manual{,
    title = {git2r: Provides Access to Git Repositories},
    author = {Stefan Widgren},
    year = {2025},
    note = {R package version 0.35.0.9000, },
    url = {https://github.com/ropensci/git2r},
  }

Readme and manuals

Introduction

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:

# install.packages("remotes")
library(remotes)
# install_github("ropensci/git2r")
install.packages("git2r", repos = c('https://ropensci.r-universe.dev', 'https://cloud.r-project.org'))

Usage

Repository

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
#> Local:    /tmp/Rtmp7CXPlx/git2r-1ae2305c0e8d/
#> Head:     nothing commited (yet)

## Check if repository is bare
is_bare(repo)
#> [1] FALSE

## Check if repository is empty
is_empty(repo)
#> [1] TRUE
Create a new bare repository
## 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)
#> cloning into '/tmp/Rtmp7CXPlx/git2r-1ae27d811539/git2r'...
#> Receiving objects:   1% (24/2329),   12 kb
#> Receiving objects:  11% (257/2329),   60 kb
#> Receiving objects:  21% (490/2329),  100 kb
#> Receiving objects:  31% (722/2329),  125 kb
#> Receiving objects:  41% (955/2329),  237 kb
#> Receiving objects:  51% (1188/2329),  574 kb
#> Receiving objects:  61% (1421/2329), 1014 kb
#> Receiving objects:  71% (1654/2329), 1350 kb
#> Receiving objects:  81% (1887/2329), 1733 kb
#> Receiving objects:  91% (2120/2329), 2614 kb
#> Receiving objects: 100% (2329/2329), 2641 kb, done.

## Summary of repository
summary(repo)
#> Remote:   @ origin (https://github.com/ropensci/git2r)
#> Local:    master /tmp/Rtmp7CXPlx/git2r-1ae27d811539/git2r/
#>
#> Branches:          1
#> Tags:              0
#> Commits:         320
#> Contributors:      3
#> Ignored files:     0
#> Untracked files:   0
#> Unstaged files:    0
#> Staged files:      0

## List all references in repository
references(repo)
#> $`refs/heads/master`
#> [6fb440] master
#>
#> $`refs/remotes/origin/master`
#> [6fb440] origin/master

## List all branches in repository
branches(repo)
#> [[1]]
#> [6fb440] (Local) (HEAD) master
#>
#> [[2]]
#> [6fb440] (origin @ https://github.com/ropensci/git2r) master
Open an existing repository
## Open an existing repository
repo <- repository(path)

## Workdir of repository
workdir(repo)
#> [1] "/tmp/Rtmp7CXPlx/git2r-1ae27d811539/git2r/"

## 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))
#> [1] TRUE

## List all tags in repository
tags(repo)
#> list()
Configuration
config(repo, user.name="Git2r Readme", user.email="git2r.readme@example.org")

## Display configuration
config(repo)
#> global:
#>         core.autocrlf=input
#> local:
#>         branch.master.merge=refs/heads/master
#>         branch.master.remote=origin
#>         core.bare=false
#>         core.filemode=true
#>         core.logallrefupdates=true
#>         core.repositoryformatversion=0
#>         remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
#>         remote.origin.url=https://github.com/ropensci/git2r
#>         user.email=git2r.readme@example.org
#>         user.name=Git2r Readme
Commit
## Create a new file
writeLines("Hello world!", file.path(path, "test.txt"))

## Add file and commit
add(repo, "test.txt")
commit(repo, "Commit message")
#> Commit:  0a6af48cedf43208bde34230662280514e0956eb
#> Author:  Git2r Readme <git2r.readme@example.org>
#> When:    2014-04-22 21:44:57
#> Summary: Commit message

License

The git2r package is licensed under the GPLv2.


Help Manual

Help pageTopics
Extract object from tree[.git_tree
Add file(s) to indexadd
Ahead Behindahead_behind
Coerce Git repository to a 'data.frame'as.data.frame.git_repository
Coerce entries in a git_tree to a 'data.frame'as.data.frame.git_tree
Coerce entries in a git_tree to a list of entry objectsas.list.git_tree
Get blame for fileblame
Create blob from file on diskblob_create
Create a branchbranch_create
Delete a branchbranch_delete
Get remote tracking branchbranch_get_upstream
Remote name of a branchbranch_remote_name
Remote url of a branchbranch_remote_url
Rename a branchbranch_rename
Set remote tracking branchbranch_set_upstream
Get target (sha) pointed to by a branchbranch_target
Branchesbranches
Bundle bare repo of packagebundle_r_package
Checkoutcheckout
Clone a remote repositoryclone
Commitcommit
Commitscommits
Configconfig
Content of blobcontent
Contributionscontributions
Create a new environmental credential objectcred_env
Create a new passphrase-protected ssh key credential objectcred_ssh_key
Create a new personal access token credential objectcred_token
Create a new plain-text username and password credential objectcred_user_pass
Get the signaturedefault_signature
Descendantdescendant_of
Changes between commits, trees, working tree, etc.diff.git_repository diff.git_tree
Find path to repository for any filediscover_repository
Fetch new data and update tipsfetch
Get updated heads during the last fetch.fetch_heads
Locate the path to configuration filesgit_config_files
Timeas.character.git_time as.POSIXct.git_time format.git_time git_time print.git_time
git2r: R bindings to the libgit2 librarygit2r-package git2r
Determine the sha from a blob stringhash
Determine the sha from a blob in a filehashfile
Get HEAD for a repositoryhead.git_repository
Determine if a directory is in a git repositoryin_repository
Remove an index entry corresponding to a file on diskindex_remove_bypath
Init a repositoryinit
Check if repository is bareis_bare
Is blob binaryis_binary
Check if object is S3 class git_blobis_blob
Check if object is 'git_branch'is_branch
Check if object is a git_commit objectis_commit
Check if HEAD of repository is detachedis_detached
Check if repository is emptyis_empty
Check if branch is headis_head
Check if branch is localis_local
Is mergeis_merge
Determine if the repository is a shallow cloneis_shallow
Check if object is a git_tag objectis_tag
Check if object is S3 class git_treeis_tree
Last commitlast_commit
Size in bytes of the contents of a bloblength.git_blob
Number of files in git_diff objectlength.git_diff
Number of entries in treelength.git_tree
Compile time options for libgit2.libgit2_features
Version of the libgit2 librarylibgit2_version
Lookuplookup
Lookup the commit related to a git objectlookup_commit lookup_commit.git_branch lookup_commit.git_commit lookup_commit.git_reference lookup_commit.git_tag
List the contents of a tree objectls_tree
Find a merge base between two commitsmerge_base
Merge a branch into HEADmerge.character merge.git_branch merge.git_repository
Add note for a objectnote_create
Default notes referencenote_default_ref
Remove the note for an objectnote_remove
List notesnotes
Blobs in the object databaseodb_blobs
List all objects available in the databaseodb_objects
Parentsparents
Plot commits over timeplot.git_repository
Print a reflog entryprint.git_reflog_entry
Pullpull
Punch cardpunch_card
Pushpush
Get all references that can be found in a repository.references
List and view reflog informationreflog
Add a remote to a reporemote_add
List references in a remote repositoryremote_ls
Remove a remoteremote_remove
Rename a remoteremote_rename
Set the remote's url in the configurationremote_set_url
Get the remote url for remotes in a reporemote_url
Get the configured remotes for a reporemotes
Open a repositoryrepository
Get HEAD for a repositoryrepository_head
Reset current HEAD to the specified statereset
Revparserevparse_single
Remove files from the working tree and from the indexrm_file
Get the SHA-1 of a git objectsha sha.git_blob sha.git_branch sha.git_commit sha.git_fetch_head sha.git_merge_result sha.git_note sha.git_reference sha.git_reflog_entry sha.git_tag sha.git_tree
Compose usual path to ssh keysssh_path
Set the SSL certificate-authority locationsssl_cert_locations
Stashstash
Apply stashstash_apply
Drop stashstash_drop
List stashes in repositorystash_list
Pop stashstash_pop
Statusstatus
Summary of repositorysummary.git_repository
Summary of a stashsummary.git_stash
Summary of treesummary.git_tree
Create tag targeting HEAD commit in repositorytag
Delete an existing tag referencetag_delete
Tagstags
Treetree
Whenwhen
Workdir of repositoryworkdir