-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
935 lines (866 loc) · 41.6 KB
/
index.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
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="generator" content="pandoc">
<meta name="author" content="Jeroen Budts">
<title>Git Training</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/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/css/theme/black.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/css/print/pdf.css' : './reveal/css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
<!--[if lt IE 9]>
<script src="./reveal/lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<h1 class="title">Git Training</h1>
<p class="author">Jeroen Budts</p>
</section>
<section id="who-am-i" class="slide level2">
<h2>Who am I?</h2>
<ul>
<li>Jeroen Budts</li>
<li>Developer / Project Manager</li>
<li>At <a href="http://inuits.eu">Inuits</a> - An Open Source Consultancy Company</li>
<li><a href="http://budts.be" class="uri">http://budts.be</a></li>
<li>twitter: <span class="citation" data-cites="teranex">@teranex</span></li>
<li>e-mail: [email protected]</li>
</ul>
</section>
<section><section id="overview" class="titleslide slide level1"><h1>Overview</h1></section><section class="slide level2">
<ul>
<li>Basic Git usage</li>
<li>How Git stores it's stuff</li>
<li>Normal Git usage: <em>branching, merging, rebasing, ..</em></li>
<li>Working with remotes</li>
<li>Some more advanced things: <em>subversion, submodules, bisect, stash</em></li>
</ul>
</section></section>
<section><section id="what-is-git" class="titleslide slide level1"><h1>What is Git?</h1></section><section class="slide level2">
<p><em>"Git is a free & open source, distributed version control system designed to handle everything from small to very large projects with speed and efficiency."</em></p>
</section><section id="distributed" class="slide level2">
<h2>Distributed</h2>
<ul>
<li>The entire repository is on your computer</li>
<li>No connection to the server required to work, view log</li>
<li>Very fast</li>
</ul>
</section><section id="open-source" class="slide level2">
<h2>Open source</h2>
<ul>
<li>Created in 2005</li>
<li>Linux Kernel</li>
<li>Linus Torvalds</li>
</ul>
</section></section>
<section><section id="basic-git-usage" class="titleslide slide level1"><h1>Basic Git Usage</h1></section><section id="initialize-repository" class="slide level2">
<h2>Initialize repository</h2>
<div class="sourceCode"><pre class="sourceCode zsh"><code class="sourceCode zsh">git init</code></pre></div>
</section><section id="then-add-files" class="slide level2">
<h2>Then add files</h2>
<div class="sourceCode"><pre class="sourceCode zsh"><code class="sourceCode zsh">git add -A
<span class="co"># or</span>
git add <span class="kw">.</span>
<span class="co"># or</span>
git add myfile.txt
git add *.rb
git add directory/</code></pre></div>
</section><section id="and-commit-the-files" class="slide level2">
<h2>And commit the files</h2>
<pre><code>git commit</code></pre>
<p>Git will ask you for a commit message.</p>
</section><section id="committing-modified-files." class="slide level2">
<h2>Committing modified files.</h2>
<p>Stage the files (more on that later):</p>
<pre><code>git add file.txt</code></pre>
<p>And commit:</p>
<pre><code>git commit</code></pre>
</section><section id="skip-staging" class="slide level2">
<h2>Skip staging</h2>
<p>Or skip the staging step and immediately commit:</p>
<pre><code>git commit -a</code></pre>
</section><section id="removing-a-file" class="slide level2">
<h2>Removing a file</h2>
<pre><code>git rm file.txt</code></pre>
<p>And commit</p>
<pre><code>git commit</code></pre>
</section><section id="try-it" class="slide level2">
<h2>Try it</h2>
<ol type="1">
<li>create a new repository</li>
<li>add some text-files</li>
<li>commit</li>
<li>make some changes</li>
<li>commit (with <code>-a</code> for now)</li>
<li>remove a file</li>
<li>commit (with <code>-a</code>)</li>
</ol>
</section></section>
<section><section id="the-index" class="titleslide slide level1"><h1>The Index</h1></section><section class="slide level2">
<p>A.K.A. The Staging Area</p>
<p>The index contains the changes that will be <strong>added</strong> to your next <strong>commit</strong>. Your commit will <em>not</em> contain the changes in your working directory.</p>
<p><strong>Only the changes that were added to the index will be in the commit</strong></p>
</section><section class="slide level2">
<p><img src="images/git-02.png" alt=""></p>
</section><section class="slide level2">
<p>If you add a file, or a part of a file, to the index, a copy is made of that file. When you commit, it is that copy which ends up in the commit.</p>
</section><section class="slide level2">
<p><strong>Important</strong>: if you make changes to the file after adding it to the index, those changes will not end up in your commit, unless you add the file again to the index!</p>
</section><section class="slide level2">
<p>If you modify files, you need to '<em>stage</em>' them again, by running</p>
<pre><code>`git add`</code></pre>
</section><section class="slide level2">
<p>You can also add only parts of a modified file:</p>
<pre><code>git add -p myfile.txt</code></pre>
<p><strong>Tip</strong>: use a tool for this</p>
</section></section>
<section><section id="checking-the-state-of-your-repository" class="titleslide slide level1"><h1>Checking the state of your repository</h1></section><section class="slide level2">
<p>Checking the state of the working copy</p>
<pre><code>git status</code></pre>
<figure>
<img src="images/status.png" alt="status" /><figcaption>status</figcaption>
</figure>
</section><section id="seeing-what-has-changed" class="slide level2">
<h2>Seeing what has changed</h2>
<div class="sourceCode"><pre class="sourceCode zsh"><code class="sourceCode zsh"> git <span class="kw">diff</span>
<span class="co"># shows the diff of your working copy</span>
git <span class="kw">diff</span> --cached
<span class="co"># show the diff of your index</span></code></pre></div>
<p><strong>Tip</strong>: use a tool for this</p>
</section><section id="the-log" class="slide level2">
<h2>The log</h2>
<p>This shows the log of your current branch</p>
<pre><code>git log</code></pre>
<figure>
<img src="images/git-13.png" alt="log" /><figcaption>log</figcaption>
</figure>
</section><section class="slide level2">
<p><code>git log</code> has many options. For example:</p>
<pre><code>git log --graph --pretty=format:'%Cred%h%Creset
-%C(yellow)%d%Creset %s %Cgreen(%cr)
%C(bold blue)<%an>%Creset' --abbrev-commit
--date=relative</code></pre>
<p>results in: <img src="images/git-11.png" alt="git-11" /></p>
</section><section class="slide level2">
<p><strong>Tip</strong>: add this in your global gitconfig as an alias:</p>
<div class="sourceCode"><pre class="sourceCode ini"><code class="sourceCode ini"><span class="dt"> </span><span class="kw">[alias]</span>
<span class="dt"> l </span><span class="ot">=</span><span class="st"> log --graph --pretty=format:'%Cred%h%Creset</span>
<span class="dt"> -%C(yellow)%d%Creset %s %Cgreen(%cr)</span>
<span class="dt"> %C(bold blue)<%an>%Creset' --abbrev-commit</span>
<span class="dt"> --date</span><span class="ot">=</span><span class="st">relative </span></code></pre></div>
</section><section class="slide level2">
<p>See the log of all the branches:</p>
<pre><code>git log --all</code></pre>
<figure>
<img src="images/log-all.png" alt="log --all" /><figcaption>log --all</figcaption>
</figure>
</section><section id="try-it-1" class="slide level2">
<h2>Try it</h2>
<ol type="1">
<li>edit two text files</li>
<li>check the status</li>
<li>add one of them to the index</li>
<li>commit</li>
<li>add the other to the index</li>
<li>edit the file again</li>
<li>check the status</li>
<li>check the diff and diff --cached</li>
</ol>
</section></section>
<section><section id="undoing-things" class="titleslide slide level1"><h1>Undoing things</h1></section><section id="undoing-changes-to-a-file" class="slide level2">
<h2>Undoing changes to a file</h2>
<div class="sourceCode"><pre class="sourceCode zsh"><code class="sourceCode zsh"> git checkout -- file.txt
<span class="co"># the -- are optional, to tell git it's about a file</span>
git checkout directory/</code></pre></div>
<p>But <strong>not</strong></p>
<pre><code>git checkout branch-name</code></pre>
<p><strong>Note</strong>: This gets back the version from the <strong>index</strong>. If the file is not in the index, it will get the file from the repository.</p>
</section><section id="resetting-from-the-index" class="slide level2">
<h2>Resetting from the index</h2>
<p>To reset the file after it was added to the index:</p>
<pre><code>git reset file.txt</code></pre>
<p>The working copy is now the version from the index and the file is not in the index anymore. Then you can use</p>
<pre><code>git checkout file.txt</code></pre>
<p>To completely reset it to the version in the repository.</p>
</section><section id="removing-unversioned-files" class="slide level2">
<h2>Removing unversioned files</h2>
<div class="sourceCode"><pre class="sourceCode zsh"><code class="sourceCode zsh">git clean -f
<span class="co"># to remove untracked files</span>
git clean -f -d
<span class="co"># to remove untracked directories</span></code></pre></div>
</section><section id="completely-resetting-your-working-copy" class="slide level2">
<h2>Completely resetting your working copy</h2>
<div class="sourceCode"><pre class="sourceCode zsh"><code class="sourceCode zsh">git reset --hard
<span class="co"># optionally followed by</span>
git clean -f</code></pre></div>
<p><strong>Use with care!</strong></p>
</section><section id="reverting-a-commit" class="slide level2">
<h2>Reverting a commit</h2>
<p>After a commit was already pushed out to other people.</p>
<pre><code>git revert <commit-hash></code></pre>
<p>This will create a commit to undo everything introduced by <commit-hash></p>
</section><section id="try-it-2" class="slide level2">
<h2>Try it</h2>
<ol type="1">
<li>edit a file</li>
<li>undo the edit</li>
<li>edit the file and add it to the index</li>
<li>edit the same file, get the version back from the index</li>
<li>create a new file</li>
<li>use <code>git clean</code> to remove it</li>
</ol>
</section><section id="try-it-3" class="slide level2">
<h2>Try it</h2>
<ol type="1">
<li>edit a file and commit</li>
<li>revert the commit with <code>git revert</code></li>
<li>check the git log</li>
<li>edit some more files and revert everything with <code>git reset --hard</code></li>
</ol>
</section></section>
<section><section id="how-git-stores-data" class="titleslide slide level1"><h1>How Git stores data</h1></section><section class="slide level2">
<p>Knowing this gives you a better understanding of Git</p>
<p>A Git repository is a<br />
<strong>collection of objects</strong></p>
</section><section id="types-of-objects" class="slide level2">
<h2>Types of objects</h2>
<ul>
<li>blobs</li>
<li>trees</li>
<li>commits</li>
<li>tags</li>
</ul>
</section><section id="blobs" class="slide level2">
<h2>blobs</h2>
<p>Git stores the <strong>contents of a file</strong> in a 'blob'.</p>
<ul>
<li>does not contain any meta data</li>
<li>a blob never changes</li>
<li>a hash is calculated as the blob name</li>
<li>the hash will always be the same for the same contents</li>
</ul>
</section><section class="slide level2">
<p>some examples:</p>
<pre><code>$ git hash-object hello.txt
ce6c1fd146f65c899e6b10e46c89097c644e3229
$ git hash-object say-hi.rb
a8784b043f12b4b0c9114c55ebf33f5c9b44ce8f</code></pre>
</section><section id="trees" class="slide level2">
<h2>Trees</h2>
<p>A tree is like a <strong>directory</strong></p>
<ul>
<li>Can contain references to 1 or more blobs</li>
<li>Can contain references to 0, 1 or more other trees</li>
<li>Contains the meta data about the files</li>
<li>Itself also identified by a hash</li>
</ul>
</section><section class="slide level2">
<figure>
<img src="images/git-03_2.png" alt="git-03" /><figcaption>git-03</figcaption>
</figure>
</section><section id="commits" class="slide level2">
<h2>Commits</h2>
<p>If you think about Git, think about commits!</p>
<ul>
<li>Contains a reference to one tree object</li>
<li>Contains references to one or more other commits
<ul>
<li>one exception: the very first commit in the repo</li>
</ul></li>
<li>A commit usually points to it's parent commit</li>
<li>In case of a merge, it can point to two or more commits (one commit for each branch which you merged together)</li>
</ul>
</section><section class="slide level2">
<figure>
<img src="images/git-04.png" alt="git-04" /><figcaption>git-04</figcaption>
</figure>
</section><section class="slide level2">
<p>If you understand commits,<br />
you basically understand Git.</p>
</section><section id="references-refs" class="slide level2">
<h2>references ('refs')</h2>
<p>Because a commit hash is very difficult to remember and not really useful to work with, Git uses references to point to specific commits.</p>
</section><section id="head" class="slide level2">
<h2>HEAD</h2>
<p>One such reference is <strong>HEAD</strong></p>
<p>It points to the commit which is currently checked out into your working directory</p>
</section><section id="master" class="slide level2">
<h2>master</h2>
<p>Another important reference is <strong>master</strong></p>
<ul>
<li>master is the 'default' branch in Git</li>
<li>when working on the master branch, the master reference and the HEAD reference point to the same commit</li>
</ul>
</section><section id="special" class="slide level2">
<h2>special</h2>
<ul>
<li><strong><code>HEAD^</code> & <code>HEAD^^</code></strong>: The commit before HEAD, two commits before HEAD</li>
<li><strong><code>master~7</code></strong>: 7 commits before master reference</li>
</ul>
</section></section>
<section><section id="branches" class="titleslide slide level1"><h1>Branches</h1></section><section class="slide level2">
<p>references to other commits</p>
<ul>
<li>very easy to create</li>
<li>a branch has a name</li>
<li>this name is also the reference to the most recent commit for that branch</li>
<li>a commit can be shared by branches</li>
</ul>
</section><section id="creating-a-branch" class="slide level2">
<h2>Creating a branch</h2>
<p>First create the branch</p>
<pre><code>git branch mywork</code></pre>
<p>Then start working on that branch:</p>
<pre><code>git checkout mywork</code></pre>
<p>Or combine the two steps</p>
<pre><code>git checkout -b mywork</code></pre>
</section><section id="deleting-a-branch" class="slide level2">
<h2>deleting a branch</h2>
<p>Deleting a local branch is also possible</p>
<pre><code>git branch -d mywork</code></pre>
</section><section id="branching" class="slide level2">
<h2>branching</h2>
<ul>
<li>We are working on a branch named 'origin'</li>
<li>At commit C2 we decide to split off a new branch named 'mywork'.</li>
<li>Both branches originate from commit C2; commit C3 and C5 have the same parent</li>
</ul>
</section><section class="slide level2">
<figure>
<img src="images/git-05.png" alt="git-05" /><figcaption>git-05</figcaption>
</figure>
</section><section id="merging" class="slide level2">
<h2>merging</h2>
<p>When you have been working on a (feature) branch for a while you will probably want to merge those branches back together.</p>
<div class="sourceCode"><pre class="sourceCode zsh"><code class="sourceCode zsh"> <span class="co"># to merge the origin branch back into your mywork</span>
<span class="co"># branch (to bring it up to date)</span>
<span class="co"># checkout the target branch</span>
git checkout mywork
<span class="co"># merge the branch into the current branch</span>
git merge origin</code></pre></div>
</section><section class="slide level2">
<p>Now your repository looks like this: (Notice that commit C7 has two parents)</p>
<figure>
<img src="images/git-06.png" alt="git-06" /><figcaption>git-06</figcaption>
</figure>
</section><section id="merging-1" class="slide level2">
<h2>Merging</h2>
<p>When merging two or more branches there are two possibilities:</p>
<ul>
<li>Merge commit</li>
<li>Fast Forward</li>
</ul>
</section><section id="merge-commit" class="slide level2">
<h2>Merge commit</h2>
<ul>
<li>When both branches have new commits a merge commit is created.</li>
<li><p>Git automatically proposes a commit message:</p>
<p><code>Merge branch 'mywork' into master</code></p></li>
<li><p>The commit has two or more parents</p></li>
</ul>
</section><section id="fast-forward" class="slide level2">
<h2>Fast Forward</h2>
<ul>
<li>When the target branch does not have new commits</li>
<li>No merge commit is created</li>
<li>In fact nothing much happens</li>
<li>Except: The reference for the target branch is simply changed to point the same commit as the source branch</li>
<li>This is an ideal situation and can never go wrong</li>
<li>Obviously you are not always this lucky (→ rebasing)</li>
</ul>
</section><section class="slide level2">
<p><img src="images/git-07-before.png" alt="git-07-before" /><br />
Merge the 'mywork' branch into origin</p>
</section><section class="slide level2">
<p><img src="images/git-07-after.png" alt="git-07-after" /><br />
The origin branch is simply fast-forwarded</p>
</section><section id="explicitly-create-merge-commit" class="slide level2">
<h2>Explicitly create merge commit</h2>
<p>Sometimes you want a merge commit, even when a simple Fast Forward is possible.</p>
<pre><code>git merge --no-ff</code></pre>
</section><section id="try-it-4" class="slide level2">
<h2>Try it</h2>
<ol type="1">
<li>Create a new branch and check it out</li>
<li>Edit a file and commit</li>
<li>Checkout the master branch</li>
<li>Merge the file</li>
<li>Edit files on both branches</li>
<li>Merge both branches</li>
</ol>
</section><section id="try-it-5" class="slide level2">
<h2>Try it</h2>
<ol type="1">
<li>Edit files on both branches, introducing conflicts</li>
<li>Merge both branches</li>
<li>Resolve the conflicts</li>
<li>Commit</li>
</ol>
</section></section>
<section><section id="history" class="titleslide slide level1"><h1>History</h1></section><section id="git-log" class="slide level2">
<h2>Git log</h2>
</section><section id="inspecting-an-earlier-commit" class="slide level2">
<h2>Inspecting an earlier commit</h2>
<pre><code>git show 2a2ea8d
git show HEAD^^</code></pre>
<p>Gives you a <strong>diff</strong> of what exactly that commit changed <strong>+ metadata</strong> for that commit</p>
</section><section id="checkout" class="slide level2">
<h2>Checkout</h2>
<p>You can checkout a commit to see the repository as it was back then</p>
<pre><code>git checkout <commit-hash></code></pre>
<p><strong>Note</strong>: Git will tell you that you are in a <em>detached head</em> state, because your HEAD reference doesn't point to any branch.</p>
</section><section id="resetting-to-an-earlier-commit" class="slide level2">
<h2>Resetting to an earlier commit</h2>
<p>You can reset your branch to an earlier commit, to throw away the newer commit(s).</p>
<pre><code>git reset HEAD^^</code></pre>
<p>This will change the reference for the branch to that commit</p>
<p><strong>Note</strong>: only do this if you have not yet pushed these newer commits</p>
</section><section id="reflog" class="slide level2">
<h2>Reflog</h2>
<p>The reflog is a log of everything which happened in your repository</p>
<pre><code>git reflog</code></pre>
<p>Useful when you make a mistake during rebasing, merging or resetting.</p>
<p>Your old commits are not 'lost'. They are simply not used anymore and will be removed by <code>git gc</code> after a while.</p>
</section><section id="try-it-6" class="slide level2">
<h2>Try it</h2>
<ol type="1">
<li>edit a file</li>
<li>commit</li>
<li>reset to the previous commit</li>
<li>use the reflog to find the newer commit</li>
<li>reset back to the newer commit (no more changes)</li>
<li>reset back to older</li>
<li>make additional changes to the file</li>
<li>commit the file</li>
<li>check the reflog</li>
</ol>
</section></section>
<section><section id="rebasing" class="titleslide slide level1"><h1>Rebasing</h1></section><section class="slide level2">
<p>Instead of merging (with merge commits) you can also rebase (so you can then fast forward)</p>
</section><section class="slide level2">
<p>Some people will tell you that this is very harmful, it can break your repository and destroy the universe.<br />
This is <strong>NOT TRUE</strong>. (At least if you know what you are doing)</p>
</section><section id="what-is-rebasing" class="slide level2">
<h2>What is 'rebasing'?</h2>
<p>By rebasing your commits you can actually rewrite your history:</p>
<ul>
<li>Edit a commit message</li>
<li>Add missing files to a commit</li>
<li>Reorder your commits</li>
<li>Modify the parent of a commit</li>
<li>Merge a few commits together into a single commit</li>
<li>Delete commits from the history</li>
<li>...</li>
<li>And break your repository if you want :)</li>
</ul>
</section><section id="how-not-to-destroy-your-repository" class="slide level2">
<h2>How not to destroy your repository?</h2>
</section><section class="slide level2">
<p><span style="font-size: 150%; ">Do <strong>not</strong> rebase commits which have already been pushed to other people</span></p>
</section><section class="slide level2">
<p><span style="font-size: 150%; ">Do <strong>not</strong> rebase commits which have already been pushed to other people</span></p>
</section><section class="slide level2">
<p><span style="font-size: 150%; ">Do <strong>not</strong> rebase commits which have already been pushed to other people</span></p>
</section><section class="slide level2">
<p>Each commit which is rebased will get a new, different, hash. People (and Git) which pull this new hash will get confused.</p>
</section><section class="slide level2">
<p>If you do rebase a commit which was already pushed, Git will refuse the new commit, unless you use the <code>--force</code> option.</p>
</section><section id="amending-changes" class="slide level2">
<h2>Amending changes</h2>
<ul>
<li>The easiest and 'safest' kind of rebase</li>
<li>Only possible for the most recent commit</li>
<li>Let's you add missing files and modify the commit message</li>
</ul>
<p>After modifying your index again:</p>
<pre><code>git commit --amend</code></pre>
</section><section id="rebasing-on-top-of-another-branch" class="slide level2">
<h2>Rebasing on top of another branch</h2>
<p>This is an alternative approach to merging, with a merge commit.</p>
</section><section class="slide level2">
<p>Let's reuse the example:</p>
<figure>
<img src="images/git-05.png" alt="git-05" /><figcaption>git-05</figcaption>
</figure>
</section><section class="slide level2">
<p>Now you want to merge 'mywork' into 'origin' without creating a merge commit</p>
</section><section class="slide level2">
<p>What we did before:</p>
<div class="sourceCode"><pre class="sourceCode zsh"><code class="sourceCode zsh"> git checkout origin
git merge mywork</code></pre></div>
</section><section class="slide level2">
<p>What we will do now:</p>
<div class="sourceCode"><pre class="sourceCode zsh"><code class="sourceCode zsh"> <span class="co"># on the mywork branch</span>
git rebase origin
<span class="co"># fix any merge conflicts</span>
git checkout origin
git merge mywork</code></pre></div>
</section><section class="slide level2">
<div class="sourceCode"><pre class="sourceCode zsh"><code class="sourceCode zsh"> <span class="co"># on the mywork branch</span>
git rebase origin</code></pre></div>
<figure>
<img src="images/git-08.png" alt="git-08" /><figcaption>git-08</figcaption>
</figure>
</section><section class="slide level2">
<figure>
<img src="images/git-09.png" alt="git-09" /><figcaption>git-09</figcaption>
</figure>
</section><section class="slide level2">
<figure>
<img src="images/git-10.png" alt="git-10" /><figcaption>git-10</figcaption>
</figure>
</section><section id="interactive-rebasing" class="slide level2">
<h2>Interactive rebasing</h2>
<p>With interactive rebasing you can really rewrite history the way you want it to be. ...And break your repository.</p>
<p>Rebase the commits since the specified commit-hash</p>
<div class="sourceCode"><pre class="sourceCode zsh"><code class="sourceCode zsh"> git rebase --interactive <span class="kw"><</span>commit-hash<span class="kw">></span></code></pre></div>
</section><section class="slide level2">
<p>Suppose we have the following commits</p>
<figure>
<img src="images/git-11.png" alt="git-11" /><figcaption>git-11</figcaption>
</figure>
</section><section class="slide level2">
<p>To rebase the most recent 3 commits:</p>
<div class="sourceCode"><pre class="sourceCode zsh"><code class="sourceCode zsh"> git rebase --interactive 4efd195</code></pre></div>
<figure>
<img src="images/git-12.png" alt="git-12" /><figcaption>git-12</figcaption>
</figure>
</section><section id="try-it-7" class="slide level2">
<h2>Try it</h2>
<ol type="1">
<li>edit a file and commit</li>
<li>edit the file again</li>
<li>commit the file with the <code>--amend</code> option</li>
</ol>
</section><section id="try-it-8" class="slide level2">
<h2>Try it</h2>
<ol type="1">
<li>create and checkout a branch</li>
<li>edit a file and commit</li>
<li>checkout the master branch</li>
<li>edit the same file and commit</li>
<li>do a merge</li>
<li>check the log</li>
</ol>
</section><section class="slide level2">
<ol start="7" type="1">
<li>undo the merge (reset & checkout)</li>
<li>checkout the branch</li>
<li>rebase the branch on top of master</li>
<li>checkout master and merge</li>
<li>check the log</li>
<li>Bonus: delete the merged branch</li>
</ol>
</section></section>
<section><section id="sharing-code" class="titleslide slide level1"><h1>Sharing code</h1></section><section id="remotes" class="slide level2">
<h2>Remotes</h2>
<p>To share work with other people, you can add one or more remotes</p>
<ul>
<li>remotes have an address</li>
<li>remotes have a name</li>
<li>you can add multiple remotes to a repository</li>
</ul>
</section><section class="slide level2">
<p>Easiest method to set this up is by cloning an existing repository instead of initializing your repo.</p>
<div class="sourceCode"><pre class="sourceCode zsh"><code class="sourceCode zsh"> git <span class="kw">clone</span> http://git.drupal.org/project/drupal.git</code></pre></div>
<figure>
<img src="images/git-14.png" alt="git-14" /><figcaption>git-14</figcaption>
</figure>
<p>This will set up everything for you</p>
</section><section id="manually-adding-remotes" class="slide level2">
<h2>Manually adding remotes</h2>
<p>Sometimes you will want to add a remote</p>
<ul>
<li>Because you had already created the repository</li>
<li>Or maybe because you want to add one or more additional remotes</li>
</ul>
</section><section id="adding-a-remote" class="slide level2">
<h2>Adding a remote</h2>
<p>This is done with the <code>git remote</code> command</p>
<pre><code>git remote add github [email protected]:teranex/git-talk.git</code></pre>
<p>This will add my Github repository for this presentation as a remote with the name <em>github</em></p>
</section><section id="tip-pretty-urls-for-remotes" class="slide level2">
<h2>Tip: pretty url's for remotes</h2>
<p>You can add shortcuts in your git config for often used url's</p>
<pre><code>git config --global [email protected] gh
git config --global
url.ssh://[email protected]/repos/.insteadOf r</code></pre>
<p>Then you can use short url's to clone</p>
<pre><code>git clone gh:teranex/dotvim
git clone r:myrepo.git</code></pre>
</section><section id="pulling-and-pushing" class="slide level2">
<h2>Pulling and pushing</h2>
<p>When you have cloned the repository:</p>
<pre><code>git pull</code></pre>
<p>This will pull in the changes from the current branch on the origin</p>
<pre><code>git push</code></pre>
<p>Will push your changes to the origin</p>
<p><strong>However</strong>: This will only work for '<em>tracking</em>' branches.</p>
</section><section id="remote-branches" class="slide level2">
<h2>Remote Branches</h2>
<p>It is important to think about remote branches as just <em>branches</em></p>
<p>By default, Git does not know, nor care, about relationships between branches!</p>
</section><section class="slide level2">
<ul>
<li>local branch: <strong>master</strong></li>
<li>remote ('github') branch: <strong>github/master</strong></li>
<li><p><strong>Git just sees two branches</strong></p>
<p><code>git pull github master</code><br />
<code>git push github master</code></p></li>
<li><p>By default, no local branches are created for remote branches</p></li>
</ul>
</section><section id="remote-branches-1" class="slide level2">
<h2>Remote Branches</h2>
<p>You can get a good overview of all your local and remote branches and how they are tracking with:</p>
<div class="sourceCode"><pre class="sourceCode zsh"><code class="sourceCode zsh"> git branch -avv</code></pre></div>
<figure>
<img src="images/git-19.png" alt="img-19" /><figcaption>img-19</figcaption>
</figure>
</section><section id="tracking-branches" class="slide level2">
<h2>Tracking branches</h2>
<p>To create a local branch based on a remote branch:</p>
<pre><code>git checkout --track -b mywork github/mywork</code></pre>
<p>To link an existing local branch to a remote branch:</p>
<pre><code>git branch --setup-stream github/mywork</code></pre>
</section><section class="slide level2">
<p>You can verify this in the git config file (.git/config) in your repository:</p>
<figure>
<img src="images/git-15.png" alt="git-15" /><figcaption>git-15</figcaption>
</figure>
</section><section id="merging-while-pulling" class="slide level2">
<h2>Merging while pulling</h2>
<p>To better understand pulling, let's see what actually happens. Instead of using <code>git pull</code>, you also do (while on the master branch):</p>
<div class="sourceCode"><pre class="sourceCode zsh"><code class="sourceCode zsh"> <span class="co"># pull in the new objects</span>
git fetch github
<span class="co"># merge the remote branch with the local branch</span>
git merge github/master</code></pre></div>
<p>This works exactly the same as merging two local branches!</p>
</section><section id="avoiding-useless-merge-commits" class="slide level2">
<h2>Avoiding useless merge commits</h2>
<p>Merging a remote branch in your local branch can create a useless merge commit:</p>
<figure>
<img src="images/git-16.png" alt="git-16" /><figcaption>git-16</figcaption>
</figure>
</section><section class="slide level2">
<p>You can avoid this by rebasing instead of merging:</p>
<div class="sourceCode"><pre class="sourceCode zsh"><code class="sourceCode zsh"> git pull --rebase</code></pre></div>
<p>or, if you want to do it manually:</p>
<div class="sourceCode"><pre class="sourceCode zsh"><code class="sourceCode zsh"> git fetch github
git rebase github/master</code></pre></div>
<p>%% ## Try it %% 1. Clone a repository %% 1. Checkout a remote branch (you are now in a detached head state) %% 1. Create a local branch for the remote branch</p>
</section></section>
<section><section id="stash" class="titleslide slide level1"><h1>Stash</h1></section><section class="slide level2">
<p>Sometimes you want to set aside your changes</p>
<ul>
<li>because you want to rebase (which is not possible in a dirty repository)</li>
<li>to try alternative approaches</li>
<li>...</li>
</ul>
</section><section class="slide level2">
<p>to stash everything</p>
<pre><code>git stash</code></pre>
<p>Or you can give a description</p>
<pre><code>git stash save "something fancy I was working on"</code></pre>
</section><section class="slide level2">
<p>to see the stashes</p>
<pre><code>git stash list</code></pre>
<p>to get changes back from the stash</p>
<pre><code>git stash pop</code></pre>
</section><section class="slide level2">
<p>I often use the stash when I want to <code>git pull --rebase</code>, while I have uncommitted changes (git will refuse to do it in that case):</p>
<pre><code>git stash
git pull --rebase
git stash pop</code></pre>
</section><section id="try-it-9" class="slide level2">
<h2>Try it</h2>
<ol type="1">
<li>make some edits</li>
<li>stash them</li>
<li>unstash them</li>
</ol>
</section></section>
<section><section id="submodules" class="titleslide slide level1"><h1>Submodules</h1></section><section class="slide level2">
<p>In a Git repository you can 'link' other repositories to subdirectories. This can be useful, for example when using external libraries or when building your VIM configuration, to pull in all the plugins.</p>
</section><section class="slide level2">
<p>Similar to svn:externals, but not quite the same:</p>
<ul>
<li>submodules must be registered in the repository</li>
<li>submodules must be pulled-in separately for each repo.</li>
<li>submodules are not updated automatically</li>
<li>submodules are not pushed automatically</li>
<li>a specific commit is referenced in the parent repo</li>
</ul>
</section><section id="add-a-submodule" class="slide level2">
<h2>Add a submodule</h2>
<pre><code># from the root of the repository
git submodule add git://path/to/repo path/in/repo</code></pre>
<p>This will modify the .gitmodules file, which is part of the parent repository, and record the exact commit which is checked out in the submodule. Now you can commit, push, etc.</p>
</section><section id="pulling-in-submodules" class="slide level2">
<h2>Pulling in submodules</h2>
<p>When another repository pulls in the change the following steps are required:</p>
<pre><code>git submodule init</code></pre>
<p>This will update the .git/config file for that repository and register the submodule in the repository</p>
<pre><code>git submodule update</code></pre>
<p>This will check-out all the submodules to the correct commit</p>
<pre><code># or combine both steps
git submodule update --init</code></pre>
</section><section id="updating-submodules" class="slide level2">
<h2>Updating submodules</h2>
<p>To update you can checkout another commit in the submodule (for example by pulling) and commit the reference to this new commit in the parent repository.</p>
<p>To update all the modules, you can use something like:</p>
<pre><code>git submodule foreach git pull origin master</code></pre>
</section><section id="try-it-10" class="slide level2">
<h2>Try it</h2>
<ol type="1">
<li>Create a new repo with a commit</li>
<li>Add it as a submodule of your main repo</li>
<li>Make some changes in the Submodule</li>
<li>Check the status of the main repo</li>
<li>Commit in the Submodule</li>
<li>Check the status of the main repo</li>
<li>Commit the updated main repo to point to the ne commit in the submodule</li>
</ol>
</section></section>
<section><section id="bisect" class="titleslide slide level1"><h1>Bisect</h1></section><section class="slide level2">
<p>Helping you to find which commit introduced the bug</p>
</section><section class="slide level2">
<p>Sometimes somebody will introduce bugs into your software or brake previously working features. Who knows, maybe even you! While trying to find the source of the problem, it can be useful to know which commit exactly introduced the troubles in paradise. That is exactly what Git bisect is for.</p>
</section><section id="steps-for-bisecting" class="slide level2">
<h2>Steps for bisecting</h2>
<ol type="1">
<li>Inform Git about one 'good' commit</li>
<li>And about one 'bad' commit</li>
<li>Git will checkout a commit for you</li>
<li>Verify that commit</li>
<li>Tell Git whether that commit has the problem ('bad'), or not ('good')</li>
<li>Finally the 'bad' commit will be found</li>
</ol>
</section><section id="an-example" class="slide level2">
<h2>an example</h2>
<p>Let's say you know the feature was already broken in the previous commit and 10 commits ago the feature still worked.</p>
</section><section class="slide level2">
<p>Start Git Bisect and inform Git about this:</p>
<pre><code>git bisect start
git bisect bad HEAD^
git bisect good HEAD~10</code></pre>
</section><section class="slide level2">
<p>Git will checkout the commit in the middle, so you can test:</p>
<pre><code>Bisecting: 5 revisions left to test after this
(roughly 3 steps)</code></pre>
</section><section class="slide level2">
<p>After testing you inform Git about the result</p>
<pre><code>git bisect good # when the feature worked
git bisect bad # when the feature is b0rken</code></pre>
</section><section class="slide level2">
<p>After you have found the bad commit, reset your repository:</p>
<pre><code>git bisect reset</code></pre>
<p>If you write a script which can verify each commit, you can let Git run it for every commit!</p>
</section><section id="try-it-11" class="slide level2">
<h2>Try it</h2>
<ol type="1">
<li>Find the commit which changed <code>A tree is a like a **directory**</code> into <code>A tree is like a **directory**</code></li>
</ol>
</section></section>
<section><section id="git-and-subversion" class="titleslide slide level1"><h1>Git and Subversion</h1></section><section id="git-svn" class="slide level2">
<h2>git-svn</h2>
<p>With git-svn you can:</p>
<ul>
<li>migrate an existing subversion repository to a git repository, including all the history.</li>
<li>use Git locally to do your work, but push to a central Subversion server.</li>
</ul>
</section><section id="local-git-subversion-server" class="slide level2">
<h2>Local Git, Subversion server</h2>
<p>To locally use Git and push to a central Subversion server:</p>
<p>First 'clone' the Subversion repository into a local Git repo</p>
<div class="sourceCode"><pre class="sourceCode zsh"><code class="sourceCode zsh">git svn <span class="kw">clone</span> -s http://svn.example.com/myproject
<span class="co"># the -s means the subversion repo has a</span>
<span class="co"># standard layout (trunk/ etc)</span></code></pre></div>
</section><section class="slide level2">
<p>Now you can work as usual with your Git repository. Except... instead of running <code>git pull</code> to get the changes from other people, you now do:</p>
<pre><code>git svn rebase</code></pre>
<p>And you don't do <code>git push</code>, but:</p>
<pre><code>git svn dcommit</code></pre>
</section></section>
<section><section id="suggested-reading" class="titleslide slide level1"><h1>Suggested reading</h1></section><section class="slide level2">
<ul>
<li>the git man-pages</li>
<li>the .git-folder of a repository (just take a look, it's interesting)</li>
<li>Pro Git: <a href="http://progit.org/" class="uri">http://progit.org/</a></li>
<li>The Git Community Book: <a href="http://book.git-scm.com/" class="uri">http://book.git-scm.com/</a></li>
<li>StackOverflow: <a href="http://stackoverflow.com/questions/tagged/git">http://stackoverflow.com</a> has a lot of valuable questions and answers related to Git.</li>
</ul>
</section></section>
<section><section id="question" class="titleslide slide level1"><h1>Question?</h1></section><section class="slide level2">
<p>Thank you for your time</p>
</section></section>
</div>
</div>
<script src="./reveal/lib/js/head.min.js"></script>
<script src="./reveal/js/reveal.js"></script>
<script>
// Full list of configuration options available at:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
// Push each slide change to the browser history
history: true,
// Optional reveal.js plugins
dependencies: [
{ src: './reveal/lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: './reveal/plugin/zoom-js/zoom.js', async: true },
{ src: './reveal/plugin/notes/notes.js', async: true }
]
});
</script>
</body>
</html>