forked from cis-ds/course-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git04.Rmd
160 lines (120 loc) · 5.34 KB
/
git04.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
---
title: "Setup Git and GitHub"
output:
html_document:
toc: TRUE
toc_depth: 2
toc_float: TRUE
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(cache=TRUE)
```
*You only have to do this once per machine.*
# Make a repository in GitHub
* Go to [GitHub.com](https://www.github.com) and login.
* Click the green "New Repository" button
* Repository name: `myrepo`
* Public
* Check **Initialize this repository with a README**
* Click the green "Create repository" button
* Copy the HTTPS clone URL to your clipboard via the green "Clone or Download" button.
# Clone the repository to your computer
* Go to the [shell](shell.html) (one way to open: In RStudio, **Tools > Shell**).
* Determine where you are in the file directory (`pwd`). `cd` to move around. You can clone this repository wherever you want, though eventually you'll want to develop a system for storing your repos in a consistent manner. Here, I stored mine in `/Users/benjamin/Github/`.
* Clone `myrepo` from GitHub to your computer. Cloning simply downloads a copy of the repository to your computer. Remember the URL you copied? It should contain your GitHub username and the name of your practice repository. Either copy + paste the URL into your shell, or if the clipboard doesn't work retype it manually. Make sure it is accurate.
```{r engine='bash', eval=FALSE}
git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY.git
```
Your output should look like this:
```{}
benjamin-laptop:Github benjamin$ git clone https://github.com/bensoltoff/myrepo.git
Cloning into 'myrepo'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
Checking connectivity... done.
```
* Make this new repository your working directory, list its files, display the README, and get some information on its connection to GitHub.
```{r engine='bash', eval=FALSE}
cd myrepo
ls
less README.md # press [q] to quit
git remote show origin
```
This should look something like:
```{}
benjamin-laptop:Github benjamin$ cd myrepo
benjamin-laptop:myrepo benjamin$ ls
README.md
benjamin-laptop:myrepo benjamin$ less README.md
# myrepo
README.md (END)
benjamin-laptop:myrepo benjamin$ git remote show origin
* remote origin
Fetch URL: https://github.com/bensoltoff/myrepo.git
Push URL: https://github.com/bensoltoff/myrepo.git
HEAD branch: master
Remote branch:
master tracked
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)
```
# Make a local change, commit, and push
* Add a line to README and verify that Git notices the change:
```{r engine='bash', eval=FALSE}
echo "A line I wrote on my local computer" >> README.md
git status
```
```
benjamin-laptop:myrepo benjamin$ echo "A line I wrote on my local computer" >> README.md
benjamin-laptop:myrepo benjamin$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: README.md
no changes added to commit (use "git add" and/or "git commit -a")
```
* Commit this change and push to your remote repo on GitHub.
```{r engine='bash', eval=FALSE}
git add -A
git commit -m "A commit from my local computer"
git push
```
This should look like:
```{}
benjamin-laptop:myrepo benjamin$ git add -A
benjamin-laptop:myrepo benjamin$ git commit -m "A commit from my local computer"
[master 33bb99f] A commit from my local computer
1 file changed, 1 insertion(+), 1 deletion(-)
benjamin-laptop:myrepo benjamin$ git push
Counting objects: 3, done.
Writing objects: 100% (3/3), 294 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/bensoltoff/myrepo.git
d72645a..33bb99f master -> master
```
If you have never pushed a commit to GitHub, you will be challenged to enter your username and password. Do this.
# Confirm the local change propagated to the GitHub remote
* Go back to the browser. Make sure you're still viewing your `myrepo` GitHub repository.
* Refresh the page.
* You should see the new line "A line I wrote on my local computer" in the README.
* If you click on "Commits" you should see one with the message "A commit from my local computer."
# Authenticating with GitHub for each push
While the need to authenticate users is obvious (if there was no authentication, anyone could upload changes to your repository), it can be tedious to enter your username and password every time you want to push a change to GitHub. Fortunately there are a couple different options for caching your credentials which we will review [here](git07.html).
# Clean up
Since this was simply a test, there is no need to keep `myrepo`. Because we stored the repo on both our computer and GitHub, we need to remove it from both locations.
* Delete the local repository in the shell:
```{r engine='bash', eval=FALSE}
cd ..
rm -rf myrepo/
```
* Delete the repository from GitHub:
* In the browser, viewing your repository's landing page on GitHub, click on "Settings", near the bottom of the right sidebar.
* Scroll down, click on "Delete this repository", and follow the instructions
### Acknowledgments {.toc-ignore}
```{r child='_ack_stat545.Rmd'}
```