-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.qmd
542 lines (333 loc) · 9.58 KB
/
index.qmd
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
---
title: "Supercharge your research code with Git and GitHub<br>{{< fa brands git-alt >}} {{< fa brands github >}}"
format:
revealjs:
theme: custom.scss
slide-number: true
show-slide-number: speaker
chalkboard: true
code-line-numbers: false
preview-links: auto
author: "**David Wilby**<br>[RSE Team](https://rse.shef.ac.uk/)<br>[**rse.shef.ac.uk**](https://rse.shef.ac.uk) | [**davidwilby.dev**](https://davidwilby.dev)<br><br>
**Chris Wild**<br>[Research & Innovation IT Team](https://students.sheffield.ac.uk/it-services/research)
"
date: 05/23/2023
date-format: "ddd Do MMMM YYYY"
footer: "these slides: [davidwilby.dev/carpentries-git-slides](https://davidwilby.dev/carpentries-git-slides) - {{< fa brands github >}} [improve this talk!](https://github.com/davidwilby/carpentries-git-slides)"
from: markdown+emoji
---
##
{fig-align="center"}
“Piled Higher and Deeper” by Jorge Cham, [phd comics](http://www.phdcomics.com)
# Examples of version control (non-code)
* :books: Book editions
* {{< fa brands wikipedia-w >}} Wikipedia pages
* {{< fa brands google >}} Google docs
## What makes a version control system?
<br>
* :camera_flash: Snapshot current version
* :label: Name specific versions
* :leftwards_arrow_with_hook: Revert back to a particular version
<br>
Perhaps
* :books: Compare and merge versions
## Benefits of version control/source code management
. . .
**Local** :computer:
e.g. Git {{< fa brands git-alt >}}
* Protect against breaking *everything*
* Keep at least one working version of the code
* Snapshot your progress
. . .
**Remote** :globe_with_meridians:
e.g. GitHub {{< fa brands github >}}, GitLab {{< fa brands gitlab >}}
* Work collaboratively
* Share code easily
* Remote backup
## Without version control
<br>
. . .
:confused: Make changes by making a copy of the entire codebase.
<br>
. . .
:neutral_face: Merging is a manual process.
<br>
. . .
:fearful: Lose track of which version contains what functionality.
<br>
. . .
:sob: Collaborating is just emailing zip files and crying.
<br>
# Version Control == Git
. . .
More often than not
## How does Git work?
```{mermaid}
%%{init: { 'logLevel': 'debug', 'theme': 'base', 'gitGraph': {'showCommitLabel': true, 'rotateCommitLabel': true}} }%%
gitGraph
commit id: "commit 1"
commit id: "commit 2"
commit id: "commit 3"
commit id: "commit 4"
commit id: "commit 5"
commit id: "commit 6"
commit id: "commit 7"
```
::: {.callout-note appearance="simple"}
The most important concept in git is the `commit` - the name given to a unit of changes, and also to the process of making a commit.
:::
## Repositories (Repos)
<br>
::: {.callout-tip appearance="simple"}
<font size="6">Once a directory/folder is *initialised* with `git` it becomes a *repository*.</font>
<br><br>
:::
::: columns
::: {.column width="40%"}
**directory**
```
.
├── src/
├── LICENSE.md
└── README.md
```
:::
::: {.column width="20%"}
`git init`
------->
:::
::: {.column width="40%"}
**repository**
```
.
├── .git/
├── src/
├── LICENSE.md
└── README.md
```
:::
:::
. . .
::: {.callout-note appearance="simple"}
It's generally a bad idea to keep local repos in a managed location such as Dropbox or Google Drive.
Use GitHub or GitLab to make remote copies/backups.
:::
## Demo
<https://onlywei.github.io/explain-git-with-d3>
or
<https://bit.ly/git-sandbox>
or
{{< qrcode https://onlywei.github.io/explain-git-with-d3 width=350 height=350 >}}
## Firstly, a *linear* commit history
<br><br>
```{mermaid}
%%| fig-width: 15
%%{init: { 'logLevel': 'debug', 'theme': 'base', 'gitGraph': {'showCommitLabel': true, 'rotateCommitLabel': true}} }%%
gitGraph
commit id: "commit 1"
commit id: "commit 2"
commit id: "commit 3"
commit id: "commit 4"
commit id: "commit 5"
commit id: "commit 6"
commit id: "commit 7"
```
## Branches {{< fa solid code-branch >}}
Used to work on new features/changes/additions to the code.
```{mermaid}
%%| fig-width: 10
%%{init: { 'logLevel': 'debug', 'theme': 'base'} }%%
gitGraph
commit id:"8bc2520"
commit id:"2a70480"
branch experiment
commit id:"089e06b"
commit id:"bec84f4"
commit id:"2420edd"
```
```bash
git branch experiment
git checkout experiment
git commit
git commit
git commit
```
. . .
::: {.callout-tip appearance="simple"}
**Checkout**: switching to a different branch.
Alternatively, `git switch`
(**Be aware** `checkout` command has many jobs, not just switching branches.
:::
. . .
::: {.callout-note appearance="simple"}
The default branch is now usually called `main` but is sometimes still `master`.
:::
## Merging {{< fa solid code-merge >}}
<br>
Combine changes from two branches.
<br>
```{mermaid}
%%| fig-width: 10
%%{init: { 'logLevel': 'debug', 'theme': 'base'} }%%
gitGraph
commit id:"8bc2520"
commit id:"2a70480"
branch experiment
commit id:"089e06b"
commit id:"bec84f4"
commit id:"2420edd"
checkout main
merge experiment
commit id:"60489ec"
```
```bash
git checkout main
git merge experiment
git commit
```
## Making a commit {{< fa solid code-commit >}}
```{mermaid}
%%| fig-height: 10
flowchart TB
A(Edit file) --> B
B(Save) --> C
C(Stage changes) --> D(Commit)
```
<br>
. . .
### Commits contain *changes*
Not actually *snapshots* of a file.
But can recreate a state from a sequence of changes.
## The commit hash
<br>
Git generates a hash string, uniquely identifying each commit.
::: {.callout-note appearance="simple"}
Git uses a "[Merkle tree](https://en.wikipedia.org/wiki/Merkle_tree)" under the hood. (Don't ask me how it works, I have no idea :shrug:)
:::
. . .
<br>
Hashes look like:
`d3dd03f493707256c8528bc83ad280a460f05a56`
. . .
<br>
But are most often seen as the first 7 characters, as this is easier to read/type and is normally enough to identify the commit.
`d3dd03f`
## The commit message
Each commit has a *message* associated with it.
<br>
**Summary/Title**: <50-72 characters
Displayed most frequently.
<br>
**Detailed description**: no character limit.
*Can* be used to capture more detail. Not used that often.
. . .
<br>
### This commit will...
::: columns
::: {.column width="30%"}
* :x: some stuff
* :x: code
* :x: updates
:::
::: {.column width="70%"}
* :heavy_check_mark: add new module "renderers"
* :heavy_check_mark: add new install instructions
* :heavy_check_mark: fix bug #17 with package update
:::
:::
## How to interact with Git
<br>
### command line `git` {{< fa brands git-alt >}}
via unix shell (or gitbash/WSL on Windows)
```bash
$ git add README.md
$ git commit -m 'initial commit'
$ git status
```
<br>
::: columns
::: {.column width="50%"}
### IDEs
* [VSCode](https://code.visualstudio.com/)
* [RStudio](https://posit.co/download/rstudio-desktop/)
* [PyCharm](https://www.jetbrains.com/pycharm/)
* [Emacs](https://www.gnu.org/software/emacs/)
:::
::: {.column width="50%"}
### Other GUIs
* [GitKraken Client {{< fa brands gitkraken >}}](https://www.gitkraken.com/)
* [GitHub Desktop {{< fa brands github >}}](https://desktop.github.com/)
* [etc. etc.](https://git-scm.com/downloads/guis/)
:::
:::
## File types
**`Git` is great at handling _text_ files but NOT _binary_ files.**
::: columns
::: {.column width="50%"}
::: {.callout-tip icon=false appearance="simple"}
## What are text files?
Just plain text, e.g. files containing code such as:
* Plain text code files - e.g. .R, .py, .m, .cpp
* Plain text data files - e.g. csv
<br>
NOT documents such as
* .docx - Microsoft Word documents
* .pdf - PDF documents
These aren't text files, even though they primarily contain text.
:::
:::
::: {.column width="50%"}
::: {.callout-important icon=false appearance="simple"}
## What are binary files?
Files that need a specific program to read, including:
* .docx - Microsoft Word documents
* .xlsx - spreadsheets
* .pdf - PDF documents
* .fig - MATLAB figures
* .jpg, .gif - Images
<br>
**Note**: `Git` can handle binary files, but can't inspect what changes have been made, only that the file has changed. Making merging impossible.
:::
:::
:::
## Git learning resources
::: columns
::: {.column width="60%"}
* [Pro Git Book](http://git-scm.com/book/en/v2)
* [Software carpentry lesson](http://swcarpentry.github.io/git-novice/)
* *\"oh sh\*\* git\"* - [zine](https://wizardzines.com/zines/oh-shit-git/), or [blog](https://ohshitgit.com/)
* [The Turing Way](https://the-turing-way.netlify.app/reproducible-research/vcs.html)
* [stack overflow](https://stackoverflow.com/) *etc.* - *use carefully* :warning:
* blogs on [dev](https://dev.to/) or [atlassian](https://www.atlassian.com/git/tutorials) *etc.*
<br>
::: {.callout-warning appearance="simple"}
<font size="6">
**Remember**
Learning Git is a process.
Everyone makes mistakes.
</font>
:::
:::
::: {.column width="40%"}
[](https://ohshitgit.com/)
:::
:::
## Git {{< fa brands git-alt >}} vs GitHub {{< fa brands github >}} or GitLab {{< fa brands gitlab >}}
<br>
**Git**
* Local client for source code management
* Interacting with remote git servers
**GitHub/GitLab**
* Code hosting
* Collaboration
* OSS contribution
* Project management
* Automated workflows/continuous delivery
## Repositories

## Issues

## Projects/Kanban Board

## Continuous integration/Automated testing
{fig-align="center"}