Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/gertPublic

Simple git client for R

License

NotificationsYou must be signed in to change notification settings

r-lib/gert

Repository files navigation

This package is a joint effort fromrOpenSci and theTidyverse team.

Simple Git Client for R

Project Status: Active – The project has reached a stable, usable state and is being actively developed.runiverse-nameruniverse-packagecran-badgeR-CMD-check

Simple git client for R based on 'libgit2' with support for SSH andHTTPS remotes. All functions in gert use basic R data types (such as vectorsand data-frames) for their arguments and return values. User credentials areshared with command line 'git' through the git-credential store and ssh keysstored 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

# To install the latest versioninstall.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:

If no suitable version of libgit2 is found, the package automatically tries to download a static build.

Documentation:

Hello world

Some basic commands to get started with gert:

library(gert)repo<- git_clone("https://github.com/r-lib/gert")setwd("gert")# Show some infogit_log(max=10)# Create a branchgit_branch_create("mybranch",checkout=TRUE)# Commit thingswriteLines("Lorem ipsum dolor sit amet",'test.txt')git_add('test.txt')git_commit("Adding a file",author="jerry <jerry@gmail.com>")git_log(max=10)# Merge it in mastergit_branch_checkout("master")git_merge("mybranch")git_branch_delete("mybranch")# Remove the commitgit_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 isHTTPS 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 linegit.
  • 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. Insteadgenerate a personal access token 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: usecredentials::set_github_pat() to automatically set theGITHUB_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 withgit2r

Gert is based onlibgit2, just like the rOpenSci packagegit2r. 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 linegit. 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             * <chr>                         <chr>                     <dttm>              <int> <lgl> <chr>               1 6f39ba6dae890d679970c0f8bf03… Jeroen Ooms <jeroenooms@… 2020-06-16 01:16:33    17 FALSE "Add some family ta…2 c023c407a0f0bfa3955576bc3551… Jeroen Ooms <jeroenooms@… 2020-06-16 01:06:38     1 FALSE "Check for matching…3 24234060ea8e54c73ddd0bce90ff… Jeroen Ooms <jeroenooms@… 2020-06-15 13:17:57     1 FALSE "Update fedora link…4 e60b0fbad129f470a2f7065063fa… Jeroen Ooms <jeroenooms@… 2020-06-15 13:05:45     4 FALSE "Tweak docs and rea…5 629420ddccbab51c1e78f472bf06… Jeroen Ooms <jeroenooms@… 2020-06-15 12:14:25     1 FALSE "More tests\n"      6 a62ce14eb887e183ad0a3cf0e22c… Jeroen Ooms <jeroenooms@… 2020-06-15 12:06:41     1 FALSE "Fix unit test\n"

For R users who are familiar with thegit command line, gert should be mostly self-explanatory, and generally "just work".

Automatic authentication

The overall goal for auth is that gert should successfully discover credentials whenever that would also be true for command linegit. And, should that fail, there is a way to debug it.

To authenticate with a remote in git2r, you often need to manually pass your credentials in every call to, e.g.,git2r::clone(). This is always the case for an https remote and is often the case even for an ssh remote. This creates special challenges for those new togit or for indirect use of git2r.

In gert, authentication is done automatically using thecredentials package. This package calls out to the local OS credential store which is also used by thegit command line. Therefore gert will automatically pick up on https credentials that are safely stored in your OS keychain.

If no credentials are available from the store, gert will try to authenticate using yourGITHUB_PAT (if set) for GitHub https remotes. If none of that works, it safely prompts the user for credentials usingaskpass. Together, these methods should make https authentication "just work" in any scenario, without having to manually provide passwords in R.

Authentication with ssh remotes is a bit more complicated, but gert will again try to make this as smooth as possible. First of all, gert will tell you if SSH is supported when attaching the package (this will be the case on all modern systems):

> library(gert)Linkingtolibgit2v1.0.0,sshsupport:YESGlobalconfig:/Users/jeroen/.gitconfigDefaultuser:JeroenOoms<jeroenooms@gmail.com

On Mac/Linux, gert first tries to authenticate using credentials from yourssh-agent. If that doesn't work it will look for a suitable ssh key on your system (usuallyid_rsa), and if it is protected with a passphrase, gert will safely prompt the user for the passphrase usingaskpass.If the user does not have an SSH key yet, thecredentials package makes it easy to set that up.

> library(credentials)Foundgitversion2.24.3 (AppleGit-128)SupportedHTTPScredentialhelpers:cache,storeFoundOpenSSH_8.1p1,LibreSSL2.7.3DefaultSSHkey:/Users/jeroen/.ssh/id_rsa

One limitation that remains is that libgit2 does not supportssh-agent on Windows. This isunlikely to change 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.:

About

Simple git client for R

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp