Project Cloning and git
Handling - Introduction
There three different ways to clone a remote git
project into Workbench.
- via the Workbench graphical user interhface (GUI)
- via
git
in the terminal - via
git
wrapped by an R package
All of these can either use the
- HTTP
- SSH
git
protocols.
git
Protocols
The HTTP protocol requires a username/password combination while the SSH protocol uses an SSH key pair. When using the HTTP approach, username and password are often cached for a specific period of time in a credential helper program. Users need to regularly re-authenticate with their credentials.
The SSH key pair required for authentication when using the git protocol has a private and public part. The public part lives on the remote git
hoster, e.g., GitHub and is compared against the private part, which resides on the local machine of the user. The private key is by default located at ~/.ssh/id_rsa
. This key is then offered to the remote git
hoster to authenticate the user. If it matches against a public key there, the user is granted access.
Most users are used to the HTTP approach as it is often the default option and similar to common website logins. However, using an SSH key pair is more robust and secure - and also a little bit faster. While it requires putting your public SSH key onto the respective git
hoster first, it pays back by not having to deal with authentication requests and credential caching as opposed to the HTTP approach.
GUI vs. Command Line
The following walkthroughs show the different ways to interact with git in Posit Workbench.
Git Clone via the Workbench
To clone a git repository via the Workbench GUI, follow these steps:
Git Clone via Terminal
If you prefer the command line, one can use git
directly in the terminal to issue a git clone
:
git clone git@github.com:cynkra/dm.git
The repo will be cloned into a local folder with the same name as the repo (here: “dm”).
Git Clone in R
A third way is to use R directly. There are two options in R:
- The R package {gert} which wraps the
libgit2
C library and provides an R interface togit
functionality. - The {usethis} package which also opens the cloned repo in a new project afterwards. Note that {usethis} only works with GitHub repositories!