Installing git and getting a GitHub account
1. GitHub Account
- Go to https://github.com and register an account
- Use an appropriate (professional!) username (I recommend you use all lower case letters)
- Register for a free account. That provides more than enough resources (I have a free account, for example)
2. Installing Git
You might already have it installed, so let’s check that first
Open a
shell
orterminal
(Mac instructions, Windows instructions, Linux users, I assume you know what you are doing)Once you have a command line staring at you, type:
which git
If you get ## /usr/bin/git
, then you already have git. You are done, skip to the next section: 3. Connecting Git, GitHub, RStudio
If you get something like git: command not found
, then follow the instructions on the tabs below
You might get asked if you want to install “command line developer tools”. Yes, you want to! Click “Install” and read more below.
Option 1
We will install the XCode command line tools (not the same as Xcode)
- I assume you still have a terminal open
- Type:
xcode-select --install
- You will be prompted to accept licenses and terms… go through the usual steps
- Try the
which git
command again in your terminal. This time you should get## /usr/bin/git
Option 2
- Go to https://git-scm.com/downloads and download the installer
- Follow the installation instructions
- Try the
which git
command again in your terminal. This time you should get## /usr/bin/git
- Go to https://gitforwindows.org/ and download the installer
- Proceed with installation steps
- In “Adjusting your
PATH
environment”, make sure to select “Git from the command line and also from 3rd-party software”. Use all the other defaults. - Try the
which git
command again in your terminal. This time you should get## /usr/bin/git
Ubuntu and Debian:
sudo apt-get install git
Fedora or RedHat Linux:
sudo yum install git
3. Connecting Git, GitHub and RStudio
- In the shell, use the code below to tell your git program what’s your username. Retain the quotation marks, but replace
your_username_here
with the username you created in Step 1 above.
git config --global user.name "your_username_here"
- Then, use teh code bellow to tell git what your email is. Again, retain quotations and include the email you used to authenticate in GitHub
git config --global user.email "your@email_here.com"
- Use the code below. It should return a list where you can see your username and email are now added
git config --global --list
There are different types of shell on Windows (no idea why) and you might be in the wrong one. You want to be in a “Git Bash” shell, as opposed to Power Shell or the legacy cmd.exe command prompt. You can read more about this here, including ways to figure out which one you are using.
- Go to https://github.com/settings/tokens and click “Generate new token”.
- Select the “classic” version
- Look over the scopes and make sure “repo”, “user”, and “workflow” are ticked
- Click “Generate token” at the bottom of the page (green button)
- DO NOT CLOSE THE WINDOW - Copy the generated PAT to your clipboard or leave that browser window open and available so you can come back to copy the PAT later. The PAT will look like a bunch of random letters and numbers.
- In the RStudio console, run
install.packages("usethis")
- Then, run
gitcreds::gitcreds_set()
- Paste the PAT in response to the dialogue in the console:
: ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
? Enter password or token-> Adding new credentials...
-> Removing credentials from cache...
-> Done.
- You should be done. We’ll test things in class.