git config --global user.name "YOUR FULL NAME"
git config --global user.email "YOUR EMAIL ADDRESS"
Setting up Git and GitHub
Learning Objectives
- Installing git
- Setting up GitHub
- Connecting to GitHub with SSH
Installing Git
Install git:
- Windows: http://git-scm.com/download/win.
- OS X: http://git-scm.com/download/mac.
- Debian/Ubuntu:
sudo apt-get install git-core
. - Other Linux distros: http://git-scm.com/download/linux.
Create an account on GitHub: https://github.com/
- A free plan is fine. Use the same email address you used above.
- When you choose your username, remember that you might use this for professional purposes. So I would recommend something related to your name (e.g. my handle is “dcgerard”). I would recommend against something like “david_awesome_david_yolo_hahaha”.
Tell git your name and email address. Open up a terminal and type:
If you are worried about email privacy, then use “<username>@users.noreply.github.com” as your email address (where you have replaced <username> with your GitHub username), then follow the instructions here to make your email address private on GitHub.
- Choose your favorite editor to be your default
Nano (a simple text editor):
git config --global core.editor "nano -w"
Notepad (Windows only):
git config --global core.editor "c:/Windows/System32/notepad.exe"
Emacs (for the brave) if it is already installed:
git config --global core.editor "emacs"
HTML Authentication
SSH Authentication
To integrate GitHub (the website) with git (the command-line program), you have to set up the proper authorization.
If you can already integrate with GitHub through the command line then you can skip the rest of these notes. If you are not sure, then please continue.
GitHub now requires you to use either Personal Access Tokens or SSH Keys for interfacing. For this class, we’ll use SSH Keys since its implementation is slightly easier.
An alternative setup using personal access tokens can be found here.
SSH uses what’s called a key pair where GitHub has a “public key” (a very long publicly known password) and you have on your computer a “private key” (a very long privately known password).
Think about the public key as a padlock, and the private key as the key. You have to use to private key to unlock the public key.
You need to generate a new private key, and go through the below steps, for each computer for which you intend to use git.
Generate Key Pair on R Studio
- R Studio makes it easy to generate a key pair.
Check to see if you already have an SSH key pair by running the following in R
file.exists("~/.ssh/id_rsa.pub")
It will return
FALSE
if you do not have a key pair.Open up Tools > Global Options… > Git/SVN.
If you do not have an SSH key pair, then click on “Create SSH Key…” and follow the prompts.
Click on “View public key”
Copy the entire text that shows up. This is your public key.
Go to Add Public Key to GitHub to continue authentication setup.
Generate Key Pair on the Terminal
- If the R Studio pipeline does not work, then try generating your key pair on the terminal with the following instructions.
Check for existing SSH Keys
In the terminal run
ls -al ~/.ssh
This will say something like “ls: cannot access ‘/c/Users/Vlad Dracula/.ssh’: No such file or directory” if you don’t have any public/private key pairs.
This will list out files names like “id_rsa.pub”, “id_ecdsa.pub”, or “id_ed25519.pub” if you do have a public/private key pair.
Generate a new SSH key
If you do have an SSH key, go to the next section (“Add an SSH key to the ssh-agent”)
If you don’t have an SSH key, follow the below steps.
In the terminal, run
ssh-keygen -t ed25519 -C "your_email@example.com"
Press enter if prompted where to save the key to accept the default location.
At the prompt, type a password that you can remember.
Add an SSH key to the ssh-agent
In the terminal, run the following to start the ssh-agent in the background.
eval "$(ssh-agent -s)"
In the terminal, run the following to add your SSH private key to the ssh-agent:
::: {.cell layout-align="center"}
```{.bash .cell-code}
ssh-add ~/.ssh/id_ed25519
```
:::
Copy Public Key
Run the following in the terminal to show the contents of “id_ed25519.pub”.
cat ~/.ssh/id_ed25519.pub
Highlight the output using your mouse and copy the contents.
Add Public Key to GitHub
On GitHub, in the upper right corner, click on your profile photo and click on “Settings”
On the left sidebar, click on “SSH and GPG keys”
Click on “New SSH key”
In the title field, choose a descriptive title, like “Personal Laptop”.
Paste your key into the “Key” field.
Click “Add SSH key” and confirm your GitHub password.
Test to see if it worked
Enter the following in the terminal:
ssh -T git@github.com
Type “yes” if prompted to continue connecting.
You are successful if you see something like
Hi dcgerard! You've successfully authenticated, but GitHub does not provide shell access.