Day 11: gert

A minimal Git client for R, the beauty of gert lies in the fact that it gets user credentials through your command-line git credentials store.

Published

December 11, 2022

Let me be honest from the jump: if all goes according to plan, many users will never interact with gert (Ooms 2022b) directly. If you follow the distilled wisdom of Jenny Bryan’s Happy Git and GitHub for the useR (Bryan 2022) (most specifically, the chapter on introducing yourself to Git), you’ll interact with Git and GitHub by way of the usethis package (Wickham, Bryan, and Barrett 2022), which uses gert under the hood1.

  • 1 See the usethis vignette Managing Git(Hub) Credentials for details.

  • A bit about gert

    gert is based on the C library, libgit2, which has pre-built versions provided by gert for Mac, Windows, and Linux-x86_642. Luckily, gert’s high-level functions shield the user from libgit2’s complexities by using standard R data types for arguments and return values. For example, git_config_global_set() takes name-value pairs as arguments, and git_config_global() returns a data.frame of your global Git options.

  • 2 See the libgit2 dependency section of gert’s README for details.

  • git_config_global_set("user.name", "Sterling Archer")
    git_config_global_set("user.email", "archer@phrasing.co")
    git_config_global()
    #>                name               value     level
    #> 1 credential.helper               cache    global
    #> 2         user.name     Sterling Archer    global
    #> 3        user.email  archer@phrasing.co    global

    If you’ve introduced yourself to Git3, gert is able to do automatic authentication using its close companion, the credentials package (Ooms 2022a).

  • 3 It doesn’t matter how you did this, whether set up directly through command-line git or by way of a helper R package (e.g. gert, or usethis).

  • The overall goal for auth is that gert should successfully discover credentials whenever that would also be true for command line git.

    That’s right, gert automatically picks up on credentials stored on your OS keychain, and, if it doesn’t find anything, it will prompt you to enter your credentials using askpass (Ooms 2019).4

  • 4 gert, credentials, and askpass are all authored by Jeroen Ooms, and work together pretty darn seamlessly.

  • Learn more

    In addition to its README, gert has a helpful introductory vignette to help you get started.

    If you want to learn more, and like lots of pictures, check out author Jeroen Ooms’ slide deck, gert: A minimal git client for R.

    References

    Bryan, Jenny. 2022. Happy Git and GitHub for the useR. https://happygitwithr.com/.
    Ooms, Jeroen. 2019. askpass: Safe Password Entry for R, Git, and SSH. https://CRAN.R-project.org/package=askpass.
    ———. 2022a. credentials: Tools for Managing SSH and Git Credentials. https://docs.ropensci.org/credentials/.
    ———. 2022b. gert: Simple Git Client for R. https://CRAN.R-project.org/package=gert.
    Wickham, Hadley, Jennifer Bryan, and Malcolm Barrett. 2022. usethis: Automate Package and Project Setup. https://usethis.r-lib.org.