Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/r-lib/gert
Simple git client for R
https://github.com/r-lib/gert
Last synced: 19 days ago
JSON representation
Simple git client for R
- Host: GitHub
- URL: https://github.com/r-lib/gert
- Owner: r-lib
- License: other
- Created: 2018-10-19T09:11:55.000Z (about 6 years ago)
- Default Branch: main
- Last Pushed: 2024-11-02T08:55:27.000Z (about 1 month ago)
- Last Synced: 2024-11-16T22:02:18.755Z (26 days ago)
- Language: C
- Homepage: https://docs.ropensci.org/gert/
- Size: 24.5 MB
- Stars: 150
- Watchers: 9
- Forks: 32
- Open Issues: 64
-
Metadata Files:
- Readme: README.md
- Changelog: NEWS
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - r-lib/gert - Simple git client for R (C)
README
# gert
*This package is a joint effort from [rOpenSci](https://ropensci.org/) and the [Tidyverse](https://www.tidyverse.org/) team.*
> Simple Git Client for R
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
![runiverse-name](https://ropensci.r-universe.dev/badges/:name)
![runiverse-package](https://ropensci.r-universe.dev/badges/gert)
![cran-badge](https://www.r-pkg.org/badges/version/gert)
[![R-CMD-check](https://github.com/r-lib/gert/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/gert/actions/workflows/R-CMD-check.yaml)Simple git client for R based on 'libgit2' with support for SSH and
HTTPS remotes. All functions in gert use basic R data types (such as vectors
and data-frames) for their arguments and return values. User credentials are
shared with command line 'git' through the git-credential store and ssh keys
stored on disk or ssh-agent. On Linux, a somewhat recent version of 'libgit2'
is required; we provide a PPA for older Ubuntu LTS versions.## Installation
```r
# To install the latest version
install.packages("gert", repos = c(
ropensci = 'https://ropensci.r-universe.dev',
CRAN = 'https://cloud.r-project.org'))
# To install the CRAN release:
install.packages("gert")
```On Linux you need to install libgit2:
- Debian: [libgit2-dev](https://packages.debian.org/buster/libgit2-dev)
- Fedora / CentOS: [libgit2-devel](https://src.fedoraproject.org/rpms/libgit2)
- Arch Linux [libgit2](https://archlinux.org/packages/extra/x86_64/libgit2)
If no suitable version of libgit2 is found, the package automatically tries to download a static build.## Documentation:
- homepage: https://docs.ropensci.org/gert
- slides: https://jeroen.github.io/gert2019/#1## Hello world
Some basic commands to get started with gert:
``` r
library(gert)
repo <- git_clone("https://github.com/r-lib/gert")
setwd("gert")# Show some info
git_log(max = 10)# Create a branch
git_branch_create("mybranch", checkout = TRUE)# Commit things
writeLines("Lorem ipsum dolor sit amet", 'test.txt')
git_add('test.txt')
git_commit("Adding a file", author = "jerry ")
git_log(max = 10)# Merge it in master
git_branch_checkout("master")
git_merge("mybranch")
git_branch_delete("mybranch")# Remove the commit
git_reset_hard("HEAD^")
```## Should I use HTTPS or SSH remotes?
On most platforms, gert supports both HTTPS or SSH remotes. If you don't have any preference, the safest choice is __HTTPS remotes using a PAT as the password__. This is what I use myself as well. HTTPS remotes have the following benefits:
- Your credentials are safely stored by your OS, accessible both to gert and command line `git`.
- Https works on any network. However the ssh protocol requires port 22, which is often blocked on public wifi networks.
- You can authenticate over https using the same GITHUB_PAT that you use for the GitHub API.
- libgit2 supports https on all platforms (SSH support depends on libssh2 availability).
Again: no need to use your Github master password in gert/git. Instead [generate a personal access token](https://github.com/settings/tokens/new) and enter this as the password when pushing/pulling from https remotes. This works both with gert and with the git command line, even when you have 2FA enabled (which you should).Ninja tip: use `credentials::set_github_pat()` to automatically set the `GITHUB_PAT` environment variable in your R session using the value stored in your git credential store. This is a safer way to store your PAT than hardcoding it in your `.Renviron`.
## Differences with `git2r`
Gert is based on [libgit2](https://libgit2.org/), just like the rOpenSci package [git2r](https://docs.ropensci.org/git2r/). Both are good packages. The well established git2r has been on CRAN since 2015, is actively maintained by Stefan Widgren, and is widely used. Gert was started in 2019, and takes a fresh approach based on more recent APIs in libgit2 and lessons learned from using git2r. Some of the main differences:
### Simplicity
Gert is focused on high-level functions that shield the end-user from the complexity of libgit2. Functions in gert use standard R data types (such as vectors and data-frames) for their arguments and return values, which should be easy to work with for R users/packages. The target repository is either inferred from current working directory or is specified as a filepath. Branches and remotes are referred to by name, much like command line `git`. None of the functions in gert expose any externalptr types to the user.
```
> gert::git_log(max=6)
# A tibble: 6 x 6
commit author time files merge message
*
1 6f39ba6dae890d679970c0f8bf03… Jeroen Ooms library(gert)
Linking to libgit2 v1.0.0, ssh support: YES
Global config: /Users/jeroen/.gitconfig
Default user: Jeroen Ooms library(credentials)
Found git version 2.24.3 (Apple Git-128)
Supported HTTPS credential helpers: cache, store
Found OpenSSH_8.1p1, LibreSSL 2.7.3
Default SSH key: /Users/jeroen/.ssh/id_rsa
```One limitation that remains is that libgit2 does not support `ssh-agent` on Windows. This is [unlikely to change](https://github.com/libgit2/libgit2/issues/4958) because ssh-agent uses unix-sockets which do not exist in native Windows software.
### The libgit2 dependency
If you use Windows or macOS and you install gert from CRAN, it comes with "batteries included". Gert brings in prebuilt versions of external dependencies, like libgit2 and the 3rd party libraries needed to support SSH and TLS (for HTTPS). This approach guarantees that gert uses libraries that are properly configured for your operating system.
The git2r package takes another approach by bundling the libgit2 source code in the R package, and automatically building libgit2 on-the-fly when the R package is compiled. This is mostly for historical reasons, because until recently, libgit2 was not available on every Linux system.
However the problem is that configuring and building libgit2 is complicated (like most system libraries) and requires several platform-specific flags and system dependencies. As a result, git2r is sometimes installed with missing functionality, depending on what was detected during compilation. On macOS for example, some git2r users have SSH support but others do not. Weird problems due to missing libgit2 features turn out to be very persistent, and have caused a lot of frustration. For this reason, gert does not bundle and compile the libgit2 source, but instead always links to system libraries.
We provide prebuilt versions of libgit2 for Windows, MacOS and Linux-x86_64 that are automatically downloaded upon installation. Alternatively on some platforms you can build gert against the system version of libgit2, e.g.:
* [libgit2-dev](https://packages.ubuntu.com/focal/libgit2-dev) on Debian/Ubuntu
* [libgit2-devel](https://src.fedoraproject.org/rpms/libgit2) on Fedora
* [libgit2](https://archlinux.org/packages/extra/x86_64/libgit2) on Arch Linux
* [Homebrew libgit2](https://github.com/Homebrew/homebrew-core/blob/master/Formula/lib/libgit2.rb) on macOS
* [rtools40 libgit2](https://github.com/r-windows/rtools-packages/blob/master/mingw-w64-libgit2/PKGBUILD) on Windows