-
Notifications
You must be signed in to change notification settings - Fork 27
git
git is a software system to help us build, manage and share a repository of documents. git applications run as command-line tools on macos, Windows and linux, but there are many graphical user interfaces (GUIs) to make using the tools easier. Collections of documents are organized into repositories, and git is used to manage those documents for you.
github is a vendor of cloud-based services to host your git repositories. There are competitors to github including bitbucket and gitlab. We’ll use github for this course.
This document is a barebones manual for creating a github account, installing git (if you don’t have it already), and then connecting your computer and your RStudio installation to github.
repos
If you already have an account with github you can skip to the git section.
Follow the registration menu at github. Keep in mind that this is a public venue that you may use for years to come; be sure to choose an appropriate username, photo and other information with that in mind.
Like any password, keep these credentials in a secure place (like a password manager).
git software must be installed on your machine. Open a terminal on you computer.
Type the following in the terminal.
git --versionIf you get a meaningful response then skip to either Connect to GitHub with SSH or Connect to GitHub with Personal Access Token. If not then you need to install git. A meaningful response might look like this…
git version 2.39.5 (Apple Git-154)Select the appropriate link for accessing the software to download and install git.
Once you have it installed, set your global identity… name and email will suffice. These can be changed later. Of course, please use the name and email associated with your github account.
git config --global user.name "Jane Doe"
git config --global user.email janedoe@example.comThe easiest way to connect your account with the GitHub server is to use ssh key exchange.
Use the email address you used to create your GitHub account. You’ll be
asked a number of questions to each of which please accept the default
by pressing return/enter. Enter this at a Terminal.
ssh-keygen -t ed25519 -C "your_email@example.com"
This will generate two files in a hidden directory within your home directory. One file is intended to be hidden, and the other is to share with other accounts, like github.
Below we print the contents of the public part of the key.
more .ssh/id_ed25519.pub
Select the entire line that is output and copy it.
Use your browser to navigate to your github account, and open the
settings menu. Then open the SSH and GPG keys menu option in the left
hand column. Select the big green New SSH key button. Provide a
meaningful name for the key (like “ColbyForecasting”), and paste your
copied key into the space provided.
At this point you have github account, and you have installed and configured git. Here we set up a Personal Access Token (PAT) This is like passing credentials, so that git can move documents securely between the cloud and your computer.
Invoke R (or RStudio) and then do the following…
1. Install usethis package
In R…
install.packages("usethis")In R type…
usethis::create_github_token()This should bring you to a webpage with some options for generating the token.
You will need to provide a reasonable purpose for the token plus a duration - 60 days should be fine. Accept the defaults on which elements of the github offereings to permit.
Tokens are similar to passwords, so please store the token securely. If you have a password manager then use that. If you use a little notebook then use that.
Finally, we provide RStudio with a copy of that token.
In R type the command below and follow the menu that appears in the console.
gitcreds::gitcreds_set()In theory that is it! It shouldn’t matter is you used SSH or PAT, you should be able clone, push and pull between your account and GitHub.