Version control using git and github

May 25, 2021

Watch Week 1 Session on Youtube



1. What is version control and do I need it?

2. Create a new GitHub repository





3. Working locally with git


cd /Users/your_name

mkdir Github

cd Github

pwd

/Users/your_name/Github/


3.1 Initialize new git repository


mkdir testgit

cd testgit/


pwd

/Users/your_name/Github/testgit

git init


3.2 Generate some content

touch README.md

vim README.md
---
title: COVID-19 Cases & Deaths
author: Your Name
date: May 25, 2021
---


3.3 Use R to create graphics


df <- read.csv("us.csv", header=T)

head(df)

        date cases deaths
1 2020-01-21     1      0
2 2020-01-22     1      0
3 2020-01-23     1      0
4 2020-01-24     2      0
5 2020-01-25     3      0
6 2020-01-26     5      0


dim(df)

[1] 489   3

plot(1:489, df$cases, pch=16, col='darkgreen', cex=0.5, xlab="Days (2020 & 2021)", ylab="Num. Cases", main="COVID-19 Cases in the United States")


png("covid_cases.png", width=10, height=10, units="inches", res=600)

plot(1:489, df$cases, pch=16, col='darkgreen', cex=0.5, xlab="Days (2020 & 2021)", ylab="Num. Cases", main="COVID-19 Cases in the United States")

dev.off()


3.4 Finish making changes to the repository


---
title: COVID-19 Cases & Deaths
author: Your Name
date: May 25, 2021
---

1. The following plot shows number of COVID-19 cases in the United States from January 2020 through May 2021.


<center>
<img src="covid_cases.png">
</center>


3.5 Configure git


git config user.name "YOUR_GITHUB_USERNAME"

git config user.email "YOUR_GITHUB_ASSOCIATED_EMAIL_ADDRESS"

git config --list

user.name=wyoibc
user.email=wyoinbre@gmail.com

git remote add origin https://github.com/YOUR_GITHUB_USERNAME/testgit.git

git remote -v

origin  https://github.com/wyoibc/testgit.git (fetch)
origin  https://github.com/wyoibc/testgit.git (push)


3.6 Add and commit repository content


git add .

git status

On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
    new file:   README.md
    new file:   covid_cases.png
    new file:   us.csv

git commit -m "Add a helpful message here, e.g. initial commit"

[master (root-commit) 962e188] initial commit
 3 files changed, 504 insertions(+)
 create mode 100644 README.md
 create mode 100644 covid_cases.png
 create mode 100644 us.csv


3.7 Push the repository to GitHub


git push -u origin master

Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 6 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 357.31 KiB | 9.66 MiB/s, done.
Total 5 (delta 0), reused 0 (delta 0)
To github.com:wyoibc/testgit.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.