{"id":14069070,"url":"https://github.com/ropensci/git2r","last_synced_at":"2025-05-14T20:09:30.090Z","repository":{"id":12819030,"uuid":"15494155","full_name":"ropensci/git2r","owner":"ropensci","description":"R bindings to the libgit2 library","archived":false,"fork":false,"pushed_at":"2025-03-29T22:45:17.000Z","size":12010,"stargazers_count":218,"open_issues_count":96,"forks_count":61,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-04-04T00:05:48.915Z","etag":null,"topics":["git","git-client","libgit2","libgit2-library","r","r-package","rstats"],"latest_commit_sha":null,"homepage":"https://docs.ropensci.org/git2r","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ropensci.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-12-28T15:06:53.000Z","updated_at":"2025-03-29T22:45:21.000Z","dependencies_parsed_at":"2023-12-21T13:01:07.215Z","dependency_job_id":"edce3016-d4e1-4ea2-851e-66de47d328f9","html_url":"https://github.com/ropensci/git2r","commit_stats":{"total_commits":2684,"total_committers":30,"mean_commits":89.46666666666667,"dds":0.0469448584202683,"last_synced_commit":"fe6f069b9dcf380c506e1ed6182a64255f78df22"},"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fgit2r","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fgit2r/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fgit2r/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fgit2r/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ropensci","download_url":"https://codeload.github.com/ropensci/git2r/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248351649,"owners_count":21089318,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["git","git-client","libgit2","libgit2-library","r","r-package","rstats"],"created_at":"2024-08-13T07:06:35.192Z","updated_at":"2025-04-11T06:18:55.074Z","avatar_url":"https://github.com/ropensci.png","language":"R","readme":"[![R-CMD-check](https://github.com/ropensci/git2r/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ropensci/git2r/actions/workflows/R-CMD-check.yaml)\n[![CRAN status](https://www.r-pkg.org/badges/version/git2r)](https://cran.r-project.org/package=git2r)\n[![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/last-month/git2r)](https://cran.r-project.org/package=git2r)\n[![Coverage Status](https://coveralls.io/repos/github/ropensci/git2r/badge.svg?branch=master)](https://coveralls.io/github/ropensci/git2r?branch=master)\n\n# Introduction\n\nThe `git2r` package gives you programmatic access to Git repositories\nfrom R. Internally the package uses the libgit2 library which is a\npure C implementation of the Git core methods. For more information\nabout libgit2, check out libgit2's website\n[(http://libgit2.github.com)](http://libgit2.github.com).\n\nSuggestions, bugs, forks and pull requests are appreciated. Get in\ntouch.\n\n## Installation\n\nTo install the version available on CRAN:\n\n```coffee\ninstall.packages(\"git2r\")\n```\n\nTo install the development version of `git2r`, it's easiest to use the\ndevtools package:\n\n```coffee\n# install.packages(\"remotes\")\nlibrary(remotes)\ninstall_github(\"ropensci/git2r\")\n```\n\n## Usage\n\n### Repository\n\nThe central object in the `git2r` package is the S3 class\n`git_repository`. The following three methods can instantiate a\nrepository; `init`, `repository` and `clone`.\n\n#### Create a new repository\n\nCreate a new repository in a temporary directory using `init`\n\n```coffee\nlibrary(git2r)\n```\n\n```\n#\u003e Loading required package: methods\n```\n\n```coffee\n\n## Create a temporary directory to hold the repository\npath \u003c- tempfile(pattern=\"git2r-\")\ndir.create(path)\n\n## Initialize the repository\nrepo \u003c- init(path)\n\n## Display a brief summary of the new repository\nrepo\n```\n\n```\n#\u003e Local:    /tmp/Rtmp7CXPlx/git2r-1ae2305c0e8d/\n#\u003e Head:     nothing commited (yet)\n```\n\n```coffee\n\n## Check if repository is bare\nis_bare(repo)\n```\n\n```\n#\u003e [1] FALSE\n```\n\n```coffee\n\n## Check if repository is empty\nis_empty(repo)\n```\n\n```\n#\u003e [1] TRUE\n```\n\n#### Create a new bare repository\n\n```coffee\n## Create a temporary directory to hold the repository\npath \u003c- tempfile(pattern=\"git2r-\")\ndir.create(path)\n\n## Initialize the repository\nrepo \u003c- init(path, bare=TRUE)\n\n## Check if repository is bare\nis_bare(repo)\n```\n\n```\n#\u003e [1] TRUE\n```\n\n#### Clone a repository\n\n```coffee\n## Create a temporary directory to hold the repository\npath \u003c- file.path(tempfile(pattern=\"git2r-\"), \"git2r\")\ndir.create(path, recursive=TRUE)\n\n## Clone the git2r repository\nrepo \u003c- clone(\"https://github.com/ropensci/git2r\", path)\n```\n\n```\n#\u003e cloning into '/tmp/Rtmp7CXPlx/git2r-1ae27d811539/git2r'...\n#\u003e Receiving objects:   1% (24/2329),   12 kb\n#\u003e Receiving objects:  11% (257/2329),   60 kb\n#\u003e Receiving objects:  21% (490/2329),  100 kb\n#\u003e Receiving objects:  31% (722/2329),  125 kb\n#\u003e Receiving objects:  41% (955/2329),  237 kb\n#\u003e Receiving objects:  51% (1188/2329),  574 kb\n#\u003e Receiving objects:  61% (1421/2329), 1014 kb\n#\u003e Receiving objects:  71% (1654/2329), 1350 kb\n#\u003e Receiving objects:  81% (1887/2329), 1733 kb\n#\u003e Receiving objects:  91% (2120/2329), 2614 kb\n#\u003e Receiving objects: 100% (2329/2329), 2641 kb, done.\n```\n\n```coffee\n\n## Summary of repository\nsummary(repo)\n```\n\n```\n#\u003e Remote:   @ origin (https://github.com/ropensci/git2r)\n#\u003e Local:    master /tmp/Rtmp7CXPlx/git2r-1ae27d811539/git2r/\n#\u003e\n#\u003e Branches:          1\n#\u003e Tags:              0\n#\u003e Commits:         320\n#\u003e Contributors:      3\n#\u003e Ignored files:     0\n#\u003e Untracked files:   0\n#\u003e Unstaged files:    0\n#\u003e Staged files:      0\n```\n\n```coffee\n\n## List all references in repository\nreferences(repo)\n```\n\n```\n#\u003e $`refs/heads/master`\n#\u003e [6fb440] master\n#\u003e\n#\u003e $`refs/remotes/origin/master`\n#\u003e [6fb440] origin/master\n```\n\n```coffee\n\n## List all branches in repository\nbranches(repo)\n```\n\n```\n#\u003e [[1]]\n#\u003e [6fb440] (Local) (HEAD) master\n#\u003e\n#\u003e [[2]]\n#\u003e [6fb440] (origin @ https://github.com/ropensci/git2r) master\n```\n\n#### Open an existing repository\n\n```coffee\n## Open an existing repository\nrepo \u003c- repository(path)\n\n## Workdir of repository\nworkdir(repo)\n```\n\n```\n#\u003e [1] \"/tmp/Rtmp7CXPlx/git2r-1ae27d811539/git2r/\"\n```\n\n```coffee\n\n## List all commits in repository\ncommits(repo)[[1]] # Truncated here for readability\n```\n\n```\n#\u003e Commit:  6fb440133765e80649de8d714eaea17b114bd0a7\n#\u003e Author:  Stefan Widgren \u003cstefan.widgren@gmail.com\u003e\n#\u003e When:    2014-04-22 21:43:19\n#\u003e Summary: Fixed clone progress to end line with newline\n```\n\n```coffee\n\n## Get HEAD of repository\nrepository_head(repo)\n```\n\n```\n#\u003e [6fb440] (Local) (HEAD) master\n```\n\n```coffee\n\n## Check if HEAD is head\nis_head(repository_head(repo))\n```\n\n```\n#\u003e [1] TRUE\n```\n\n```coffee\n\n## Check if HEAD is local\nis_local(repository_head(repo))\n```\n\n```\n#\u003e [1] TRUE\n```\n\n```coffee\n\n## List all tags in repository\ntags(repo)\n```\n\n```\n#\u003e list()\n```\n\n### Configuration\n\n```coffee\nconfig(repo, user.name=\"Git2r Readme\", user.email=\"git2r.readme@example.org\")\n\n## Display configuration\nconfig(repo)\n```\n\n```\n#\u003e global:\n#\u003e         core.autocrlf=input\n#\u003e local:\n#\u003e         branch.master.merge=refs/heads/master\n#\u003e         branch.master.remote=origin\n#\u003e         core.bare=false\n#\u003e         core.filemode=true\n#\u003e         core.logallrefupdates=true\n#\u003e         core.repositoryformatversion=0\n#\u003e         remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*\n#\u003e         remote.origin.url=https://github.com/ropensci/git2r\n#\u003e         user.email=git2r.readme@example.org\n#\u003e         user.name=Git2r Readme\n```\n\n### Commit\n\n```coffee\n## Create a new file\nwriteLines(\"Hello world!\", file.path(path, \"test.txt\"))\n\n## Add file and commit\nadd(repo, \"test.txt\")\ncommit(repo, \"Commit message\")\n```\n\n```\n#\u003e Commit:  0a6af48cedf43208bde34230662280514e0956eb\n#\u003e Author:  Git2r Readme \u003cgit2r.readme@example.org\u003e\n#\u003e When:    2014-04-22 21:44:57\n#\u003e Summary: Commit message\n```\n\n# License\n\nThe `git2r` package is licensed under the GPLv2.\n\n---\n\n[![](http://ropensci.org/public_images/github_footer.png)](http://ropensci.org)\n","funding_links":[],"categories":["R","Other Tools","Table of Contents"],"sub_categories":["Import Data"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fropensci%2Fgit2r","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fropensci%2Fgit2r","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fropensci%2Fgit2r/lists"}