-
Notifications
You must be signed in to change notification settings - Fork 1
/
slides.html
620 lines (588 loc) · 29.7 KB
/
slides.html
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
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="generator" content="pandoc">
<meta name="author" content="Simon Cockell">
<title>Introduction to Git for Scientists</title>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="reveal.js/css/reveal.css">
<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
div.sourceCode { overflow-x: auto; }
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
margin: 0; padding: 0; vertical-align: baseline; border: none; }
table.sourceCode { width: 100%; line-height: 100%; }
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
td.sourceCode { padding-left: 5px; }
code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
code > span.dt { color: #902000; } /* DataType */
code > span.dv { color: #40a070; } /* DecVal */
code > span.bn { color: #40a070; } /* BaseN */
code > span.fl { color: #40a070; } /* Float */
code > span.ch { color: #4070a0; } /* Char */
code > span.st { color: #4070a0; } /* String */
code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
code > span.ot { color: #007020; } /* Other */
code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
code > span.fu { color: #06287e; } /* Function */
code > span.er { color: #ff0000; font-weight: bold; } /* Error */
code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
code > span.cn { color: #880000; } /* Constant */
code > span.sc { color: #4070a0; } /* SpecialChar */
code > span.vs { color: #4070a0; } /* VerbatimString */
code > span.ss { color: #bb6688; } /* SpecialString */
code > span.im { } /* Import */
code > span.va { color: #19177c; } /* Variable */
code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code > span.op { color: #666666; } /* Operator */
code > span.bu { } /* BuiltIn */
code > span.ex { } /* Extension */
code > span.pp { color: #bc7a00; } /* Preprocessor */
code > span.at { color: #7d9029; } /* Attribute */
code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
</style>
<link rel="stylesheet" href="reveal.js/css/theme/solarized.css" id="theme">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'reveal.js/css/print/pdf.css' : 'reveal.js/css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
<!--[if lt IE 9]>
<script src="reveal.js/lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<h1 class="title">Introduction to Git for Scientists</h1>
<p class="author">Simon Cockell</p>
<p class="date">17th June 2020</p>
</section>
<section id="section" class="level1">
<h1></h1>
<section id="why-version-control" class="level2">
<h2>Why version control?</h2>
<p><img src='img/phd101212s.png' height=450></p>
<p><span style="font-size:12px">* Source: <a href="http://phdcomics.com/comics/archive.php?comicid=1531" class="uri">http://phdcomics.com/comics/archive.php?comicid=1531</a></span></p>
</section>
</section>
<section id="section-1" class="level1">
<h1></h1>
<section id="why-version-control-1" class="level2">
<h2>Why version control?</h2>
<ul>
<li>This sort of <em>ad hoc</em> versioning doesn't scale</li>
<li>Services like <a href="dropbox.com">Dropbox</a> and <a href="drive.google.com">Google Drive</a> can improve matters
<ul>
<li>Risk deletion or corruption</li>
<li>What happens on one computer propagates to whole project</li>
<li>Still not great for projects >1 directory</li>
</ul></li>
<li>Problems faced by software engineers for a long time
<ul>
<li>So -- version control</li>
</ul></li>
</ul>
</section>
</section>
<section id="section-2" class="level1">
<h1></h1>
<section id="what-is-git" class="level2">
<h2>What is Git?</h2>
<p><span style="color:red">Git is a distributed version control system.</span></p>
<ul>
<li>Git stores the history of all changes made to a project</li>
<li>You can use it to roll back these changes at any time
<ul>
<li>and to any point</li>
</ul></li>
<li>It's also a tool for collaboration</li>
<li>Git can handle integrating changes from multiple people</li>
</ul>
</section>
<section id="what-is-git-1" class="level2">
<h2>What is Git?</h2>
<ul>
<li>Git was written by Linus Torvalds
<ul>
<li>To manage the code for the Linux kernel</li>
<li>Thousands of collaborators</li>
<li>Huge codebase</li>
</ul></li>
</ul>
</section>
</section>
<section id="section-3" class="level1">
<h1></h1>
<section id="still-unconvinced-what-git-can-do-for-you" class="level2">
<h2>Still unconvinced? What git can do for you</h2>
<ul>
<li>Keep snapshots of your project
<ul>
<li>Freeze a version at submission of publication</li>
<li>Subsequent version with revision</li>
</ul></li>
<li>Keep track of important changes to code (and other files)
<ul>
<li>Allow even distant collaborators to keep up with developments</li>
</ul></li>
<li>Keep projects organised and available after people leave</li>
</ul>
</section>
</section>
<section id="section-4" class="level1">
<h1></h1>
<section id="how-to-use-git----the-basics" class="level2">
<h2>How to use Git -- the basics</h2>
<p>Installing Git</p>
<ul>
<li>MacOS - use <a href="https://brew.sh">Homebrew</a>
<ul>
<li><code>brew install git</code></li>
</ul></li>
<li>Linux - use your package manager
<ul>
<li><code>apt install git</code></li>
</ul></li>
<li>Windows - <span style="text-decoration:line-through">use Mac or Linux</span>
<ul>
<li><a href="https://git-scm.com/download/win">download installer package</a></li>
</ul></li>
</ul>
<p>All git commands are of the form <code>git verb</code> where <code>verb</code> is the thing you want git to do.</p>
</section>
</section>
<section id="section-5" class="level1">
<h1></h1>
<section id="config" class="level2">
<h2>config</h2>
<p>Set global git configurations. Because git is a collaborative platform, you need to identify yourself:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="fu">git</span> config --global user.name <span class="st">"Donald Duck"</span>
$ <span class="fu">git</span> config --global user.email <span class="st">"[email protected]"</span></code></pre></div>
<p>Other useful configuration options:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># Set up git to use terminal colours</span>
$ <span class="fu">git</span> config --global color.ui true
<span class="co"># Change the default text editor used for commit messages</span>
$ <span class="fu">git</span> config --global core.editor <span class="st">"vim"</span></code></pre></div>
</section>
</section>
<section id="section-6" class="level1">
<h1></h1>
<section id="init" class="level2">
<h2>init</h2>
<p>Initialise a new repository</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="fu">mkdir</span> mynewrepo
$ <span class="bu">cd</span> mynewrepo
$ <span class="fu">git</span> init
<span class="ex">Initialized</span> empty Git repository in /path/to/mynewrepo/.git/</code></pre></div>
<p>Creates a hidden directory (<code>.git/</code>) which is what manages the repo under the hood</p>
</section>
</section>
<section id="section-7" class="level1">
<h1></h1>
<section id="clone" class="level2">
<h2>clone</h2>
<p>Take a copy of another repository - often used if you want to grab someone's code from (e.g.) Github</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="fu">git</span> clone git://github.com/broadgsa/gatk.git
<span class="ex">Cloning</span> into <span class="st">'gatk'</span>...
<span class="ex">remote</span>: Counting objects: 175297, done.
<span class="ex">remote</span>: Total 175297 (delta 0), <span class="ex">reused</span> 0 (delta 0), <span class="ex">pack-reused</span> 175297
<span class="ex">Receiving</span> objects: 100% (175297/175297), <span class="ex">247.52</span> MiB <span class="kw">|</span> <span class="ex">11.54</span> MiB/s, done.
<span class="ex">Resolving</span> deltas: 100% (97299/97299), <span class="kw">done</span><span class="ex">.</span></code></pre></div>
<p>This gives you access to new updates as they're released -- you won't have permission to push changes to this repo.</p>
</section>
</section>
<section id="section-8" class="level1">
<h1></h1>
<section id="add" class="level2">
<h2>add</h2>
<p>We created a repository with <code>init</code>, but it's not tracking anything.</p>
<p>Use <code>add</code> to track files in your repo (the files will need to exist).</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="fu">touch</span> README
$ <span class="fu">git</span> add README</code></pre></div>
<p>Now, git is tracking our new <code>README</code> file.</p>
</section>
</section>
<section id="section-9" class="level1">
<h1></h1>
<section id="status" class="level2">
<h2>status</h2>
<p><code>status</code> tells you about git's status of the files in your repository</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="fu">git</span> status
<span class="ex">On</span> branch master
<span class="ex">Initial</span> commit
<span class="ex">Changes</span> to be committed:
<span class="kw">(</span><span class="ex">use</span> <span class="st">"git rm --cached <file>..."</span> to unstage<span class="kw">)</span>
<span class="ex">new</span> file: README</code></pre></div>
</section>
<section id="status-1" class="level2">
<h2>status</h2>
<p>If we create a new file, but don't <code>add</code> it, <code>status</code> tells us so</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="fu">touch</span> newfile
$ <span class="fu">git</span> status
<span class="ex">On</span> branch master
<span class="ex">Initial</span> commit
<span class="ex">Changes</span> to be committed:
<span class="kw">(</span><span class="ex">use</span> <span class="st">"git rm --cached <file>..."</span> to unstage<span class="kw">)</span>
<span class="ex">new</span> file: README
<span class="ex">Untracked</span> files:
<span class="kw">(</span><span class="ex">use</span> <span class="st">"git add <file>..."</span> to include in what will be committed<span class="kw">)</span>
<span class="ex">newfile</span></code></pre></div>
</section>
</section>
<section id="section-10" class="level1">
<h1></h1>
<section id="commit" class="level2">
<h2>commit</h2>
<p>Time to take a snapshot of our project</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># first add the untracked file</span>
$ <span class="fu">git</span> add newfile
<span class="co"># now take the snapshot</span>
$ <span class="fu">git</span> commit -m <span class="st">"My first commit"</span></code></pre></div>
<p>The <code>-m</code> option lets you add a commit message. If you don't do this at the command line, git will open it's <code>core.editor</code> and make you write one.</p>
</section>
</section>
<section id="section-11" class="level1">
<h1></h1>
<section id="commit-messages" class="level2">
<h2>Commit messages</h2>
<p>This is an important way of documenting your project, and what's in the commit. You should be able to find a relevant commit from the message.</p>
<p><img src='img/git_commit.png' height=250></p>
<p><span style="font-size:12px">* Source: <a href="http://xkcd.com/1296" class="uri">http://xkcd.com/1296</a></span></p>
</section>
</section>
<section id="section-12" class="level1">
<h1></h1>
<section id="final-word-on-add-status-and-commit" class="level2">
<h2>Final word on add, status and commit</h2>
<p>Tracking and staging are different concepts in git. A tracked file is not necessarily staged for the next commit. Even tracked files need to be <code>add</code>ed (staged) before commit:</p>
</section>
<section id="final-word-on-add-status-and-commit-1" class="level2">
<h2>Final word on add, status and commit</h2>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="bu">echo</span> <span class="st">"Copyright (c) 2017, Donald Duck"</span> <span class="op">></span> README
$ <span class="fu">git</span> status
<span class="ex">On</span> branch master
<span class="ex">Changes</span> not staged for commit:
<span class="kw">(</span><span class="ex">use</span> <span class="st">"git add <file>..."</span> to update what will be committed<span class="kw">)</span>
<span class="kw">(</span><span class="ex">use</span> <span class="st">"git checkout -- <file>..."</span> to discard changes in working directory<span class="kw">)</span>
<span class="ex">modified</span>: README
<span class="ex">no</span> changes added to commit (use <span class="st">"git add"</span> and/or <span class="st">"git commit -a"</span>)</code></pre></div>
</section>
<section id="final-word-on-add-status-and-commit-2" class="level2">
<h2>Final word on add, status and commit</h2>
<p>We have to <code>git add README</code> again to stage the change so it can be committed. Thankfully, git provides us with a shortcut: <code>git commit -a</code> will automatically stage all modified tracked files.</p>
</section>
</section>
<section id="section-13" class="level1">
<h1></h1>
<section id="diff" class="level2">
<h2>diff</h2>
<p><code>git diff</code> will show us the difference between the working tree and the index (what's currently staged for commit).</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="bu">echo</span> <span class="st">"This is the README file for a test project"</span> <span class="op">>></span> README
$ <span class="fu">git</span> diff
<span class="fu">diff</span> --git a/README b/README
<span class="ex">index</span> c13c494..45724b3 100644
<span class="ex">---</span> a/README
<span class="ex">+++</span> b/README
<span class="ex">@@</span> -1 +1,2 @@
<span class="ex">Copyright</span> (c) <span class="ex">2017</span>, Donald Duck
<span class="ex">+This</span> is the README file for a test project</code></pre></div>
</section>
</section>
<section id="section-14" class="level1">
<h1></h1>
<section id="log" class="level2">
<h2>log</h2>
<p>As the name suggests, this verb shows you the commit history of the project:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="fu">git</span> log
<span class="ex">commit</span> c745d67bfc071f9e8bad4c44dcc7b47be089ee4e
<span class="ex">Author</span>: Donald Duck <span class="op"><</span>[email protected]<span class="op">></span>
<span class="ex">Date</span>: Fri May 26 09:15:08 2017 +0100
<span class="ex">Second</span> commit
<span class="ex">commit</span> 213caa7b311b8196fedc9dfe72ba4dc449d60b50
<span class="ex">Author</span>: Donald Duck <span class="op"><</span>[email protected]<span class="op">></span>
<span class="ex">Date</span>: Thu May 25 15:36:30 2017 +0100
<span class="ex">My</span> first commit</code></pre></div>
</section>
</section>
<section id="section-15" class="level1">
<h1></h1>
<section id="mv-and-rm" class="level2">
<h2>mv and rm</h2>
<p>Once a file is tracked by git, the VCS becomes a bit of a control freak -- so if you want to move or delete a file, it's best to do it through git.</p>
</section>
<section id="mv-and-rm-1" class="level2">
<h2>mv and rm</h2>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="fu">mv</span> README README.bak
$ <span class="fu">git</span> status
<span class="ex">On</span> branch master
<span class="ex">Changes</span> not staged for commit:
<span class="kw">(</span><span class="ex">use</span> <span class="st">"git add/rm <file>..."</span> to update what will be committed<span class="kw">)</span>
<span class="kw">(</span><span class="ex">use</span> <span class="st">"git checkout -- <file>..."</span> to discard changes in working directory<span class="kw">)</span>
<span class="ex">deleted</span>: README
<span class="ex">Untracked</span> files:
<span class="kw">(</span><span class="ex">use</span> <span class="st">"git add <file>..."</span> to include in what will be committed<span class="kw">)</span>
<span class="ex">README.bak</span>
<span class="ex">no</span> changes added to commit (use <span class="st">"git add"</span> and/or <span class="st">"git commit -a"</span>)</code></pre></div>
</section>
<section id="mv-and-rm-2" class="level2">
<h2>mv and rm</h2>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="fu">git</span> mv README README.bak
$ <span class="fu">git</span> status
<span class="ex">On</span> branch master
<span class="ex">Changes</span> to be committed:
<span class="kw">(</span><span class="ex">use</span> <span class="st">"git reset HEAD <file>..."</span> to unstage<span class="kw">)</span>
<span class="ex">renamed</span>: README -<span class="op">></span> README.bak
<span class="ex">Changes</span> not staged for commit:
<span class="kw">(</span><span class="ex">use</span> <span class="st">"git add <file>..."</span> to update what will be committed<span class="kw">)</span>
<span class="kw">(</span><span class="ex">use</span> <span class="st">"git checkout -- <file>..."</span> to discard changes in working directory<span class="kw">)</span>
<span class="ex">modified</span>: README.bak</code></pre></div>
</section>
</section>
<section id="section-16" class="level1">
<h1></h1>
<section id="ignore" class="level2">
<h2>ignore</h2>
<p>There will often be files in a project directory that we don't want to track. This is especially true of large files (e.g. data), that git doesn't handle well.</p>
<p>Ignoring is controlled by the contents of a .gitignore file.</p>
</section>
<section id="ignore-1" class="level2">
<h2>ignore</h2>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="bu">echo</span> <span class="st">'data'</span> <span class="op">></span> .gitignore
$ <span class="ex">curl</span> -o data/grch38.fa ftp://[email protected]/pub/release-89/fasta/homo_sapiens/dna/Homo_sapiens.GRCh38.dna.toplevel.fa.gz
$ <span class="fu">git</span> status
<span class="ex">On</span> branch master
<span class="ex">Changes</span> not staged for commit:
<span class="kw">(</span><span class="ex">use</span> <span class="st">"git add <file>..."</span> to update what will be committed<span class="kw">)</span>
<span class="kw">(</span><span class="ex">use</span> <span class="st">"git checkout -- <file>..."</span> to discard changes in working directory<span class="kw">)</span>
<span class="ex">modified</span>: README
<span class="ex">Untracked</span> files:
<span class="kw">(</span><span class="ex">use</span> <span class="st">"git add <file>..."</span> to include in what will be committed<span class="kw">)</span>
<span class="ex">.gitignore</span>
<span class="ex">no</span> changes added to commit (use <span class="st">"git add"</span> and/or <span class="st">"git commit -a"</span>)</code></pre></div>
</section>
</section>
<section id="section-17" class="level1">
<h1></h1>
<section id="reset" class="level2">
<h2>reset</h2>
<p>Undo any mistaken changes. Can be used to rollback uncommitted changes, or revert to an old commit.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="fu">git</span> commit -a -m <span class="st">"Committing .gitignore"</span>
$ <span class="bu">echo</span> <span class="st">"A destructive change"</span> <span class="op">></span> README
$ <span class="fu">git</span> commit -a -m <span class="st">"Oops"</span>
$ <span class="fu">git</span> log
<span class="ex">commit</span> f361ea3c091ed804b43f1c88aa359d6625c13386
<span class="ex">Author</span>: Donald Duck <span class="op"><</span>[email protected]<span class="op">></span>
<span class="ex">Date</span>: Fri May 26 09:56:39 2017 +0100
<span class="ex">Oops</span>
<span class="ex">commit</span> 5e764bea879d61acb10e89479faa89291df7ab94
<span class="ex">Author</span>: Donald ...</code></pre></div>
</section>
<section id="reset-1" class="level2">
<h2>reset</h2>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="fu">git</span> reset --hard 5e764bea879d61acb10e89479faa89291df7ab94
<span class="ex">HEAD</span> is now at 5e764be Committing .gitignore
$ <span class="fu">cat</span> README
<span class="ex">Copyright</span> (c) <span class="ex">2017</span>, Donald Duck
<span class="ex">This</span> is the README file for a test project</code></pre></div>
</section>
</section>
<section id="section-18" class="level1">
<h1></h1>
<section id="git-for-collaboration" class="level2">
<h2>Git for collaboration</h2>
<p>So far, all operations have been with a <em>local repository</em>. Remote repositories can be used to enable git as a collaborative tool.</p>
</section>
<section id="git-for-collaboration-1" class="level2">
<h2>Git for collaboration</h2>
<p>Centralised version control - e.g. Subversion</p>
<p><img src='img/svn_example.png'></p>
</section>
<section id="git-for-collaboration-2" class="level2">
<h2>Git for collaboration</h2>
<p>Distributed version control</p>
<p><img src='img/git_example.png'></p>
</section>
<section id="git-for-collaboration-3" class="level2">
<h2>Git for collaboration</h2>
<p>More complicated distributed version control</p>
<p><img src='img/complex_git_example.png'></p>
</section>
</section>
<section id="section-19" class="level1">
<h1></h1>
<section id="github" class="level2">
<h2>Github</h2>
<p>Github will often perform the role of the 'central server' for git repositories.</p>
<ul>
<li>Free, with premium options</li>
<li>Educational accounts</li>
<li>"Social" features for organising collaborations around code</li>
</ul>
<p><img src='img/Octocat.png' height=150></p>
</section>
</section>
<section id="section-20" class="level1">
<h1></h1>
<section id="getting-setup-with-github" class="level2">
<h2>Getting setup with Github</h2>
<p>Some steps required to get going with Github:</p>
<ul>
<li>Sign up for an account</li>
<li>When signed in, click the '+' in the top right
<ul>
<li>Select 'New Repository'</li>
</ul></li>
<li>Follow the on screen steps to set up your repo</li>
</ul>
</section>
<section id="getting-setup-with-github-1" class="level2">
<h2>Getting setup with Github</h2>
<p>Once your repo is up and running, you can grab a local copy:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="fu">git</span> clone git://github.com/YOURUSERNAME/YOURNEWREPO.git</code></pre></div>
</section>
<section id="getting-setup-with-github-2" class="level2">
<h2>Getting setup with Github</h2>
<p>You can also set an existing repository up with a new Github repo:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="fu">git</span> remote add origin [email protected]:YOURUSERNAME/YOURNEWREPO.git</code></pre></div>
<p>This uses the <code>remote</code> verb to add a named remote repository (in this case <code>origin</code> - which is the conventional default).</p>
</section>
</section>
<section id="section-21" class="level1">
<h1></h1>
<section id="authenticating-with-github" class="level2">
<h2>Authenticating with Github</h2>
<p>Github needs to know who you are so you can send it updates to your projects.</p>
<ul>
<li>Github uses SSH keys for authentication</li>
<li>Out of scope here, but see Github Help:</li>
</ul>
<p><a href="https://help.github.com/articles/connecting-to-github-with-ssh/" class="uri">https://help.github.com/articles/connecting-to-github-with-ssh/</a></p>
</section>
</section>
<section id="section-22" class="level1">
<h1></h1>
<section id="push" class="level2">
<h2>push</h2>
<p>Send your commits to the remote repository.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="fu">git</span> push origin master</code></pre></div>
<p>This is of the form</p>
<p><code>git push <remote-name> <branch></code></p>
<p>the defaults for <code>remote-name</code> and <code>branch</code> are <code>origin</code> and <code>master</code>.</p>
<p>Once you've <code>push</code>ed once, git will fall back on your last <code>remote-name</code> and <code>branch</code>, so <code>git push</code> will suffice.</p>
</section>
</section>
<section id="section-23" class="level1">
<h1></h1>
<section id="pull" class="level2">
<h2>pull</h2>
<p>Download the latest updates from the remote repository.</p>
<p>Works very similarly to <code>push</code>:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="fu">git</span> pull origin master</code></pre></div>
<p>It's good to get into the habit of <code>pull</code>ing before starting to work on a shared repository.</p>
</section>
</section>
<section id="section-24" class="level1">
<h1></h1>
<section id="merge" class="level2">
<h2>merge</h2>
<p>If two committers have submitted separate commits, they will have to be merged.</p>
<ul>
<li>Easy if no conflicting changes</li>
<li>Manual decisions to make if not</li>
</ul>
</section>
</section>
<section id="section-25" class="level1">
<h1></h1>
<section id="merging-conflicts" class="level2">
<h2>Merging Conflicts</h2>
<p>A four-step guide:</p>
<ol type="1">
<li>Use <code>git status</code> to find the conflicting file(s)</li>
<li>Open and edit those files manually to a version that fixes the conflicting</li>
<li>Use <code>git add</code> to tell Git that you've resolved the conflict in a particular file</li>
<li>Once all conflicts are resolved, use <code>git status</code> to check staging, and <code>commit</code></li>
</ol>
</section>
</section>
<section id="section-26" class="level1">
<h1></h1>
<section id="forking-and-pull-requests" class="level2">
<h2>Forking and Pull requests</h2>
<p>These are features of Github that are designed for collaborative working.</p>
<p>Forking allows you to make a copy of someone else's repository, so you can work on your own updates.</p>
<p>You can ask that your changes get merged (or pulled) into the parent via a pull request.</p>
<p>This is the primary Github methodology that allows for large collaborative projects, while the lead developer can maintain close control over commits to master.</p>
</section>
</section>
<section id="section-27" class="level1">
<h1></h1>
<section id="github-desktop" class="level2">
<h2>Github Desktop</h2>
<p>App for Mac and Windows; makes managing Github repos easy, and removes dependency on command line.</p>
<p><a href="https://desktop.github.com" class="uri">https://desktop.github.com</a></p>
<p>Other tools available, which work with Git services other than Github (e.g BitBucket, Gitlab). For example, GitKraken:</p>
<p><a href="https://www.gitkraken.com/" class="uri">https://www.gitkraken.com/</a></p>
</section>
<section id="github-desktop-1" class="level2">
<h2>Github Desktop</h2>
<p><img src='img/github-desktop.png' height=500></p>
</section>
</section>
<section id="section-28" class="level1">
<h1></h1>
<section id="git-and-rstudio" class="level2">
<h2>Git and RStudio</h2>
<p>RStudio has integrated support for Git - this is dependent on the use of RStudio projects.</p>
<p>Instructions for setting up: <a href="https://support.rstudio.com/hc/en-us/articles/200532077-Version-Control-with-Git-and-SVN" class="uri">https://support.rstudio.com/hc/en-us/articles/200532077-Version-Control-with-Git-and-SVN</a>.</p>
</section>
<section id="acknowledgements" class="level2">
<h2>Acknowledgements</h2>
<p>The content here follows closely the Git chapter of</p>
<p>"Bioinformatics Data Skills"</p>
<p>by</p>
<p>Vince Buffalo</p>
<p>O'Reilly Media Inc, 2015. ISBN: 978-1-449-35737-4</p>
</section>
</section>
<section id="section-29" class="level1">
<h1></h1>
<section id="theres-plenty-more..." class="level2">
<h2>There's plenty more...</h2>
<p>We've barely scratched the surface here, but hopefully enough to get you past this:</p>
<p><img src='img/git.png' height=250></p>
<p>For slides: <a href="https://github.com/sjcockell/git-tutorial" class="uri">https://github.com/sjcockell/git-tutorial</a></p>
<p><span style="font-size:12px">* Source: <a href="https://xkcd.com/1597/" class="uri">https://xkcd.com/1597/</a></span></p>
</section>
</section>
</div>
</div>
<script src="reveal.js/lib/js/head.min.js"></script>
<script src="reveal.js/js/reveal.js"></script>
<script>
// Full list of configuration options available at:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
// Transition style
transition: 'linear', // none/fade/slide/convex/concave/zoom
// Optional reveal.js plugins
dependencies: [
{ src: 'reveal.js/lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'reveal.js/plugin/zoom-js/zoom.js', async: true },
{ src: 'reveal.js/plugin/notes/notes.js', async: true }
]
});
</script>
</body>
</html>