-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetting_started.qmd
More file actions
293 lines (165 loc) · 7.71 KB
/
Copy pathgetting_started.qmd
File metadata and controls
293 lines (165 loc) · 7.71 KB
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
---
title: "Getting Started with GitHub"
author: "Jon Bryant"
format:
revealjs:
footer: "[https://github.com/PWD-MARS/github](https://github.com/PWD-MARS/github)"
auto-stretch: false
embed-resources: true
editor: visual
---
## Agenda
- Why Git/GitHub?
- Git Basics
- Workflow
- Next Steps
- Resources
- Q&A
## Why Git/GitHub
We already have tools for tracking changes and collaboration for text-based documents. Why do we need version control solutions like GitHub?
{fig-align="center" width="535"}
## Why Git/GitHub
::: incremental
- Changes in one line of code can drastically impact other areas in non-obvious ways.
- We want to have a historical record of changes to provide insight for others and our future selves.
- We want to be able to prototype portions of our code without impacting what is already working in production.
- We need more than one person to be able to work on a document at once.
- Easily rollback changes if something breaks.
:::
## Mostly we want to avoid
::: {layout="[[-1], [1], [-1]]"}
{fig-align="center" width="600"}
:::
## Git
{fig-align="center" width="207"}
- Open source software for managing software projects
- Very low level - Only available through CLI (i.e. Terminal)
- Provide core functions (tracking changes, commits, pull/push, etc)
## GitHub
{fig-align="center"}
- Web-based platform built on top of Git with an easier to use interface, collaboration and issue tracking system, etc.
- Widely used across the industry
- A single source of truth
## Git Basics
::: {style="font-size: 0.8em;"}
There's a few key concepts that are important for being successful with Git:
Repository
: A centralized folder/directory where all of your code lives for a given project and is tracked by Git.
Commit
: A snapshot of all the files in a repository
Pull
: Pull changes from the server (remote) that are missing locally.
Push
: Push changes (the commit) that exist locally but not on the server (remote)
:::
## Repo(sitory)
Repos are a folder/directory that is being tracked by Git.
- I would suggest creating the repo first in GitHub and then cloning it locally.
- Cloning makes a local copy of the repo.
- While you can go from existing project to GitHub, it's more work so I generally don't suggest it.
## Repo - Create
{fig-align="center" width="512"}
I recommend creating private repos to start with as public are generally accessible to...well, the public.
## Repo - Clone
Click on the Code button to copy the repo's URL

## Repo - Create using Version Control
For RStudio users, I recommend creating a new project using Version Control. We only have to do this once per repo (per machine).
{fig-align="center" width="523"}
# Demo
## Commit
After we make changes to files in a local repo that Git is tracking, we can commit those changes.
- [A commit is a snapshot of everything in the local repo that has changed since the last commit.]{style="font-size: 0.8em;"}
- [We want to make commits around logical units of change as they should tell a story of how the project has developed.]{style="font-size: 0.8em;"}
- [There is no prescribed amount of work or frequency regarding when to commit, but when enough work has been done that it's worth it to capture that snapshot in time.]{style="font-size: 0.8em;"}
## Commit - Changes

## Commit - UI
{fig-align="center" width="700"}
## Commit - Message
{fig-align="center" width="357"}
- First line \<50 characters, followed by a space, then additional details if necessary
- If you're writing a lot then the commit is too big/infrequent, too verbose, or some of the details should live elsewhere (comments, issues, etc).
## Not all files should be tracked
Sometimes, there are files within a directory that we don't want git to track:
- Large files
- Sensitive files
- Package/Library-related files
## `.gitignore`
::: {style="font-size: 0.8em;"}
When we create a new project in RStudio using version control (in our case GitHub), it automatically creates a `.gitignore` file with a few key files that don't need to be tracked by git.
You can add files to `gitignore` manually or most IDEs will have a UI interface to add them to `.gitignore`
{fig-align="center"}
:::
## `.gitignore` example
These files won't be tracked by Git nor will they show up in GitHub
{fig-align="center" width="412"}
## Pull/Push
People usually say "Push/Pull", but I'm being very specific in ordering it as Pull/Push. We always want to pull before we push.
As a reminder:
Pull
: Pull changes from the server (remote) that are missing locally.
Push
: Push changes (the commit) that exist locally but not on the server (remote)
## Why Pull before Push?
What happens in the following scenario:
::: incremental
1. Jon clones a repo to work on Feature A
2. Farshad clones the repo to fix Bug B
3. Farshad is a coding wizard and pushes the fix for Bug B the same day
4. Two days later, Jon finishes Feature A and wants to push it to the remote.
:::
## Merge conflict
::: incremental
If Farshad's fix for Bug B changes the code enough that it now conflicts with code of my new feature, I will get denied because of these conflicts.
- This means I need to go back, pull the changes from the remote, make sure my code works properly still for Feature A, and then push it to the remote.
- This doesn't necessarily happen often but it's always a best practice to avoid this by just pulling before pushing.
:::
## Pull/Push
::: {layout="[[-1], [1], [-1]]"}
{fig-align="center"}
:::
# Demo
## What we covered today
::: center
- Why Git/GitHub
- Basics of Git
- The complete workflow from start to finish
- Create/Clone Repositories
- Commits
- Pull/Push
:::
# Next Time
## Issues
GitHub issues are a great way of keeping track of new features, bugs, and other tasks associated to our projects
- Space to add more context to the code that is index-able for others and our future selves
- Assign to individuals, tag, etc
- Link issues to commit
##
{fig-align="center" width="850"}
## Issues
::: {style="font-size: 0.8em;"}
In the process of creating this presentation, I created an issue for the Posit/Quarto team:
:::
{fig-align="center" width="800"}
## Branches
::: {layout="[[-0.5], [0.5], [-0.5]]"}
{fig-align="center" width="743"}
:::
## Branches
GitHub is all about branches. We have haven't discussed it yet but so far we've been working only in the repo's `main` branch. When working on a feature or bug, we can create a branch and then merge it back to main when we're done
{fig-align="center" width="592"}
## Projects
Projects are based on Issues, which makes it easier to manage our work
{fig-align="center" width="700"}
## Pages
{fig-align="center" width="825"}
## Resources
::: {layout="[[-0.5], [0.5], [-0.5]]"}
- [Happy Git and GitHub for the useR](https://happygitwithr.com/ "GitHub + RStudio")
- [GitHub Learning Pathways](https://resources.github.com/learn/pathways/)
- [Git Pro book (free)](https://git-scm.com/book/en/v2)
- [Google](www.google.com)
- [MARS team](https://www.youtube.com/watch?v=dQw4w9WgXcQ)
:::
# Q&A