- Get Git! (Evan Will)Excellent introductory Git guide
- Carpentries Git Novice LessonOfficial lesson materials
- Git for WindowsInstall the latest version if needed
- R and RStudioDownload and install before today
- Carpentries: Intro to R and RStudio
- Carpentries: Data Structures
Git tracks changes to your files over time. Think of it as a detailed undo history for your entire project, shared with collaborators.
Configure Git
$ git --version
$ git config --global user.name "Your Name"
$ git config --global user.email "youremail@gmail.com"
$ git config --global core.editor "nano -w"
$ git config --list # verify your settings
Create a Local Repository
$ cd ~/Desktop
$ mkdir example-repo
$ cd example-repo
$ git init # initialize a new repo
$ ls -la # notice the hidden .git folder
$ git status # always a safe first command
Never run git init inside a directory that's already a git repository. This causes confusing problems.
Three stages: Working Directory → Staging Area → Repository
Follow this order every time:
git status # check what's changed
git pull # get latest changes from remote (when applicable)
git add file.txt # stage a file (or: git add -A for everything)
git commit -m "message" # save to the repository with a message
git push # send to remote (GitHub)
Add and Commit Files
$ cp ~/Desktop/shell-lesson-data/exercise-data/alkanes/middle.sh .
$ cp ~/Desktop/shell-lesson-data/exercise-data/alkanes/*.pdb .
$ cp ~/Desktop/shell-lesson-data/exercise-data/alkanes/sorted.sh .
$ git status
$ git add -A
$ git status
$ git commit -m "added first scripts and data files"
$ touch another_file.txt
$ git status
Create a new file using any method you've learned. Add it to the repo and commit it.
$ nano sorted.sh # deliberately mess up the script
$ git add -A
$ git commit -m "added function to sorted.sh"
# Oh no — the script is broken. Revert it.
$ git checkout HEAD~1 sorted.sh # restore previous version
$ less sorted.sh
$ git status
$ git add -A
$ git commit -m "revert to old sorted.sh"
$ git log --oneline # see compact history
Not everything should be tracked. Large data files, binary outputs, and temporary files waste space and slow down your repo.
$ nano .gitignore
*.pdb
$ git status
$ git add -A
$ git commit -m "add .gitignore"
$ git rm --cached *.pdb # untrack already-tracked files
$ git commit -m "remove .pdb files from tracking"
Create your .gitignore before you start adding files. It's much harder to untrack files after the fact.
$ nano sorted.sh # make a change
$ git diff # see exactly what changed
$ git add sorted.sh
$ git commit -m "updated sorted.sh"
$ git log --oneline
Connecting to GitHub
- Go to github.com and create a new repository called
creatures_github - Edit the README in the browser and commit — this initializes the remote repo
- Clone it to your Desktop
$ cd ~/Desktop
$ git clone [repo SSH link]
$ cd creatures_github
$ cp ../example-repo/*.sh .
$ git pull # always pull before pushing
$ git add -A
$ git commit -m "added shell scripts to repo"
$ git push
- GitHub Authentication GuideToken or SSH setup if you hit authentication errors
- SSH Key Setup (GitHub Docs)Recommended for regular Git users
Git errors and concepts can be confusing at first. AI is great at explaining them in plain language.
Install R and RStudio if you haven't yet — see the link at the top of this page.
RStudio Orientation
Open RStudio. You'll see four panels: Console (bottom left), Environment (top right), Files/Plots (bottom right), and the Script editor (top left — open a new script with File → New File → R Script).
getwd() # where are you?
list.files() # what files are here?
R as a Calculator
1 + 2
10 * 5
sin(1) + 1 * 5
# Named parameters vs. positional
log(5, 10) # log base 10 of 5
log(5) # natural log (base e)
log(5, 2.71828) # same as natural log
# Logical comparisons
1 == 1
1 != 2
1 < 2
Variables
x <- 1/40 # <- is the assignment operator in R
x # print the value
pirate <- 5
PirateHat <- 1
# 1pirate <- 5 # ERROR: can't start a variable name with a number
pirate <- pirate + 1 # modify a variable
rm(pirate, PirateHat) # remove from environment
R Projects
R Projects keep your work organized. Go to File → New Project → New Directory to create one. The project sets your working directory automatically every time you open it.
# Open the Repro_workshop.Rproj file to follow along
# Create a standard project structure
dir.create("plots")
dir.create("rawdata")
dir.create("results")
# Download the gapminder dataset
download.file("https://swcarpentry.github.io/r-novice-gapminder/data/gapminder_data.csv",
"rawdata/gapminder.csv")