forked from hakimel/reveal.js
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
1197 lines (946 loc) · 36 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
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head><meta charset="utf-8">
<title>YAGT</title>
<meta name="description" content="YAGT: Yet another talk about the distributed version control management tool Git">
<meta name="author" content="Harald Schilly">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/yagt.css" id="theme">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="lib/css/github.css">
<script>
// If the query includes 'print-pdf' we'll use the PDF print sheet
document.write( '<link rel="stylesheet" href="css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body spellcheck="false">
<div class="reveal">
<!-- Used to fade in a background when a specific slide state is reached -->
<div class="state-background"></div>
<!-- breadcrumb note: each horizontal section should have a "bc" attribute
and each vertical one too. if the vertical one doesn't have one, the
title is derived from the first tag, iff it is a h1, h2 or h3.
Breadcrumb:
[html <title>] > [ hsection.bc ] > [ vsection.bc || vsection.h1,h2,h3]
-->
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section bc="">
<section>
<h1 id="YAGT">YAGT</h1>
<h2 id="YAGT2">Yet Another Git Talk</h2>
<hr/>
<h2>by <a href="http://harald.schil.ly">Harald Schilly</a></h2>
<p><img class="noborder" src='res/git-logo.svg' width="300px" /></p>
<aside class="footnote">
<a href="http://dev.harald.schil.ly/yagt/">dev.harald.schil.ly/yagt</a>
-
<a href="https://github.com/haraldschilly/yagt">yagt@github</a>
</aside>
</section>
</section>
<script><!-- easter egg -->
var yagt = document.querySelector("#YAGT");
var yagt2 = document.querySelector("#YAGT2");
var tt = "Yes, A Great Git Talk!".split("").reverse();
var phase2 = false;
yagt.onclick = function() {
yagt.onclick = undefined;
loop = setInterval(function() {
if (phase2) {
if(tt.length > 0) {
yagt2.innerHTML += tt.pop(0);
} else {
clearInterval(loop);
yagt.innerHTML = "<b>YAGGT!</b>";
}
} else { // phase 1
var t = yagt2.innerHTML;
if(t.length > 1) {
yagt2.innerHTML = t.substring(0, t.length-1);
} else {
yagt2.innerHTML = " ";
phase2 = true;
}
}
}, 50);
}
</script>
<section data-markdown bc="Introduction">
<section data-markdown>
# What's Git?
From the website:
<blockquote cite="http://git-scm.com/">
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.</blockquote>
</section>
<section data-markdown>
## Purpose
<ul>
<li>Git tracks line oriented <em>text</em> files
(i.e. Source Code, TXT, HTML, SVG, LaTeX, ...)
in a specific directory and all its sub-directories.
(This is called "<b>repository</b>".)
</li>
<li class="fragment">Git records modifications in a history.</li>
<li class="fragment">Git allows to conveniently share modifications of a project
between <b>any</b> member in a p2p fashion.</li>
</ul>
</section>
<section data-markdown>
## History
Git was created by [Linus Torvalds](http://en.wikipedia.org/wiki/Linus_Torvalds)
for the development of Linux in 2005.
There was no tool available that would meet all his needs,
and would fit into the existing kernel development model.
His major accomplishment was to break down the complexity of
a full fledged RCS/SCM into 3 very basic building blocks.
All Git operations manipulate and operate only on those!
<aside class="footnote">
<a href="http://en.wikipedia.org/wiki/Git_%28software%29">Git@Wikipedia</a>
</aside>
</section>
<section data-markdown>
## Design Goals
* Speed
* Simple design
* Strong support for non-linear development (thousands of parallel branches)
* Fully distributed
* Able to handle large projects like the Linux kernel efficiently (speed and data size)
<aside class="footnote">
<a href="http://git-scm.com/book/en/Getting-Started-A-Short-History-of-Git">Short Git History</a>
</aside>
</section>
<section data-markdown>
## Distributed
Git is also a *distributed* version control system.
This means, everyone has all the history stored locally.
This allows you to make any kind of queries or modifications
without connecting to a central server.
It also fits much better with our mental model of *collaboration* in general.
</section>
<section data-markdown data-state="alert">
## Git is not ...
<ul>
<li>... a friend of binary files (i.e. jpeg, mp3, avi, doc, docx, odt, zip (unzip first), png, ...)</li>
<li class="fragment">... a way to just upload data to a (web-) server<br/>
→ use <code>rsync -av --delete $SRC $DEST</code></li>
<li class="fragment">... a mere incremental backup <br/>
→ use <code>rdiff-backup</code></li>
</ul>
<aside class="footnote">although, you can happily abuse Git for all of this ...</aside>
</section>
<section bc="Git in Politics?">
<iframe src="http://embed.ted.com/talks/clay_shirky_how_the_internet_will_one_day_transform_government.html" width="80%" height="480" frameborder="0" scrolling="no" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
TED Talk: <a href="http://www.ted.com/talks/clay_shirky_how_the_internet_will_one_day_transform_government.html">Git/Internet transforms Government</a>
</section>
</section>
<section bc="Prerequisites">
<section data-markdown>
## Internal Stuff
Git models the state and history via three very simplistic data structures:
blob, tree and commit.
It sounds scary, but the best way to understand Git, is to learn about those basic ideas.
<p class="fragment">Hey, we are hackers after all :-)</p>
<aside class="footnote">
<a href="http://git-scm.com/book/en/Git-Internals-Git-Objects">Git Book: Internal Objects</a>
</aside>
</section>
<section data-markdown>
## Hash function
A hash function is a cryptographic primitive,
which transforms some arbitrary data (file, byte-string)
into a byte-string of *fixed length*!
Such a hash is **unique** and **deterministic**.<sup>1</sup>
Git uses this technique extensively via
[sha1](http://en.wikipedia.org/wiki/SHA-1).
Usually, the first few characters
are enough to specify it. e.g. <code>d22f6ac</code>
<aside class="footnote"><sup>1</sup> Only due to this, two
developers can agree on a common state witout any centralized tracking.
</aside>
</section>
<section data-markdown>
## Hash Example
A commit from the Git history:
<pre>
$ git log -1
commit <b>d22f6ac868fd62dba328b555d93ec63b0fb00194</b>
Author: Harald Schilly <harald.schilly@gmail.com>
Date: Sat Oct 6 21:07:48 2012 +0200
fragment: zoom and relative offset animation
</pre>
</section>
<section data-markdown>
## Linked List & Trees
All "objects" behind such hashes are uniquely identified by the hashsum<sup>1</sup>.
References to other objects from "*inside*" such an object
are used to build trees (or to be precise, a DAG).
This data-structure will be the "*history*" of the project.
<aside class="footnote">
<sup>1</sup> for files, this is a <em>content-addressable</em> file-system,
not the usual one with "filenames".
</aside>
</section>
<section data-markdown>
## Tree = File-System
All files tracked by Git are hierarchically organized by "*trees*".
Each entry of a tree points to one specific "hashed" content of a file
(a "*blob*") or another tree (a sub-directory).
Besides that, the name of the file is recorded, too.
</section>
<section data-markdown>
## Commit
A **commit** is one specific snapshot in time of a tree with all referenced
files in their current state.
This is the fundamental building block of everything inside the
Git repository. Learning Git means mastering how to create
commits and how to juggle them around.
Such a commit also records the author, the time/date, and usually
references one or more previous commits.
</section>
<section data-markdown>
## Working Dir & Staging
To create a commit, you have to go "*shopping*".
<ol>
<li>Modify or create at least one file in your "<em>working directory</em>".</li>
<li class="fragment">Go around and explicitly put desired
changes into your shopping cart ("<em>index</em>").</li>
<li class="fragment">Finally, a commit appends the content of this
shopping cart to your "<em>history</em>".</li
</ol>
</section>
<section data-markdown>
## History
The collection of all those commits, referencing to the
immediate ancestor(s), builds the history of the entire project.
* A **root** is a commit with no ancestors<sup>1</sup>.
* A **merge** is a commit with more than one ancestor.
<aside class="footnote"><sup>1</sup> Yes, there could be more than one:
<code>git checkout --orphan root2</code></aside>
</section>
<section data-markdown>
## Branch
It is hard to remember all those constantly changing hashsums.
A *named reference* to a specific commit is the start of a **branch**.
It is the linear ordering of all reachable commits until the root.
Also, when we *commit*, the branch reference automatically changes
and points to the new commit!<sup>1</sup>
<aside class="footnote">
<sup>1</sup> not always true, see <a href="#/2/13">detached HEAD</a>
</section>
<section data-markdown bc="History Graph">
<img style="width: 90%;" src="res/dag.svg" />
History is a [DAG](http://en.wikipedia.org/wiki/Directed_acyclic_graph)
</section>
<section data-markdown bc="History Graph (annotated)">
<img style="width: 95%;" src="res/dag-named.svg" />
Same history with names.
</section>
<section data-markdown>
## HEAD
The **HEAD** is a special companion,
which points to to the *current* branch
or a specific revision.
It is the base for all files in your current working space.
<pre>$ <b>cat .git/HEAD</b>
ref: refs/heads/master
</pre>
</section>
<section data-markdown bc="Committing Diagram">
<img style="width: 95%;" src="res/commit-master.svg" />
Committing: HEAD moves and takes the branch reference with it.
</section>
<section data-markdown data-state="alert">
## Detached HEAD
Unfortunately, your **HEAD** could fall off.
In this case, it points directly to a revision and not a branch.
Then, the branch reference doesn't automatically move with the next commit!
Git does not care about those revisions which aren't reachable from any branch (or tag).
This means, a commit in a detached state will get lost!
<pre class="small">$ <b>cat .git/HEAD</b>
b1b7e86e011aebad8df6d9af33214abedb113983</pre>
</section>
<section data-markdown data-state="alert" bc="Commit w/ Detached Head">
<img style="width: 90%;" src="res/commit-detached.svg" />
committing w/ a detached head
</section>
<section data-markdown data-state="alert">
## Rewriting History
The feature<sup>1</sup> of Git to discard all commits which are not reachable,
is used in various ways. This is often called "**rewriting history**".
<ul class="fragment">
<li>Cons: You can shoot yourself in the foot<sup>2</sup>.</li>
<li>Pros: It allows you to fix errors (e.g. the last commit was incomplete),
or to extract and combine parts of a larger history.</li>
</ul>
<aside class="footnote">
<sup>1</sup>Yes, feature not bug. <b>This is the key to repair mistakes!</b><br/>
<sup>2</sup>But don't worry, Git takes great care to not loose anything
unless you <code>-f</code> "*force*" it.
There is also a safety net called "*reflog*".
</section>
<section data-markdown>
## Selecting Revisions
<ul>
<li><code>HEAD</code> is where you are</li>
<li class="fragment">beginning of the hashsum <code>8frfa1</code></li>
<li class="fragment">ancestors: <code>master~</code> or <code>master~2</code> ...</li>
<li class="fragment">2nd parent of a merge: <code>8r7af^2</code></li>
<li class="fragment">combo move: <code>master~3^2~~</code></li>
<li class="fragment">ranges: <code>master..topic1</code></li>
<li class="fragment">branch differences: <code>master...topic2</code></li>
</ul>
<aside class="footnote">
<a href="http://git-scm.com/book/en/Git-Tools-Revision-Selection">read more here</a>
</aside>
</section>
</section>
<section bc="First Steps">
<section data-markdown bc="Installation">
## Installation
* download from [Git homepage](http://www.git-scm.com/)<sup>1</sup>
* Ubuntu: <code>sudo apt-get install git</code>
* MacPorts: <code>sudo port install git-core</code>
### Install Tools
<code>sudo apt-get install gitk git-cola</code>
<aside class="footnote">
<sup>1</sup> http://www.git-scm.com/<br/>
</aside>
</section>
<section>
<h2>Basics</h2>
Git is a <b>command-line tool</b>, called via <code>git</code>.
<h2 class="fragment">HELP</h2>
<div class="fragment">
<h3>I NEED HHHEEEELP!!!</h3>
<code>git help [<command>]</code>
<br/>
or
<br/>
<code> git [<command>] --help</code>
</div>
<aside class="footnote">GUIs: <code>gitk</code> and <code>git-gui</code>,
<em><a href="http://git-scm.com/downloads/guis">Git Guis</a></em>,
<a href="http://git-cola.github.com/">git-cola</a>,
<a href="http://www.syntevo.com/smartgit/index.html">SmartGit</a>,
<a href="http://code.google.com/p/tortoisegit/">TortoiseGit</a>,
<a href="http://www.eclipse.org/egit/">Eclipse</a>,
... but this talk stays "pure".
</section>
<section data-markdown>
## Configuration
Git has a global <code>~/.gitconfig</code> and project specific local
<code>.git/config</code> configuration file.
Edit them either directly (leet!) or via
<code>git config [--global] [--edit] ...</code>
</section>
<section data-markdown>
## Config: Identity
All commits are associated with you.
That's necessary for [licensing copyrighted works](http://www.wipo.int/treaties/en/ip/berne/trtdocs_wo001.html).
<pre><code contenteditable>$ git config --global user.name "Gitti Gitian"
$ git config --global user.email "gitti@gitiscool.com"
# and check it
$ git config --global user.name
Gitti Gitian
</code></pre>
<aside class="footnote">
Remember: <code>--global</code> sets this for your entire account!
</aside>
</section>
<section data-markdown>
## Config: Aliases
Git allows to create custom commands. They can be shortcuts
or even small scripts.
Set them this way:
<pre><code contenteditable>$ git config --global alias.[SHORTCUT] [COMMAND ...]</code></pre>
</section>
<section data-markdown>
## My Aliases
<pre class="small">$ <b>git aliases</b>
st = status
ci = commit
ll = log --oneline --graph --decorate -25
lla = log --oneline --graph --decorate --all -25
br = branch
co = checkout
df = diff
who = shortlog -s --
aliases = !git config --get-regexp 'alias.*' | colrm 1 6 | sed 's/[ ]/ = /'
</pre>
</section>
<section data-markdown>
## Config: Editor
Git sometimes pops up an text editor.
Choose your poison:
<pre><code>$ git config --global core.editor "vim"</code></pre>
</section>
<section data-markdown>
## Config: Merge Tool
This is what Git gives you via <code>git mergetool</code>,
when it gives up resolving conflicts.
<pre><code>$ git config --global merge.tool "meld"</code></pre>
</section>
<section data-markdown>
## Config: Color
Makes reading output much easier.
<pre><code>$ git config --global color.ui true</code></pre>
</section>
<section data-markdown>
## Config: Ignore Files
Usually, your working directory contains a mix of tracked files
and generated files which should not be tracked.
You can tell Git to ignore them globally:
<pre>$ git config --global core.excludesfile ~/.gitignore</pre>
and project specific:<br/> edit <code>$PROJ_ROOT/.gitignore</code>
</section>
<section>
<h2>Config: Ignore Files /2</h2>
Typical entries for the global <code>~/.gitignore</code>:
<pre class="small">*.o
*.so
*.class
*.pyc
*~ # temporary editor files
*.swp # vim temp file
*.min.js
*.log
*.DS_Store # Mac users
</pre>
<aside class="footnote">
<a href="https://help.github.com/articles/ignoring-files">more examples what to exclude</a></aside>
</section>
</section>
<!-- ################# -->
<section bc="Hands On">
<section data-markdown>
## Start a repository
A repository in Git is decentralized.
You do not need to know in advance,
with whom you want to work together.
<pre>$ mkdir myshinynewrepo
$ cd !$
$ git init
</pre>
</section>
<section data-markdown data-state="soothe">
## Clone a Repo
... but if you know the project,
it is easier to just <em>"clone"</em> it.
<pre>$ git clone [git|http]://server/.../project.git</pre>
Then, this <em>remote</em> server is already setup for
sending your commits to it
(<em>"<a href="#/5">pushing</a>"</em>).
</section>
<section data-markdown>
<h2>Status</h2>
To see all modified and untracked files (which are not ignored),
Git provides the <code>status</code> command.
Its output also lists useful commands, which will be explained in the next slides.
</section>
<section data-markdown>
<h2>Staging</h2>
Git has a so called <em>"staging area"</em>.
This is a selection of modified files,
or parts of files, that you wish to be part of the next
<em>"[commit](#/2/5)"</em>.
<pre>$ git add fileA fileB ...
# or just all, which are already tracked or deleted
$ git add -A
# or just a part
$ git add -p fileX
# to get rid of files
$ git rm fileY
</pre>
</section>
<section data-markdown data-state="alert">
##Edits after staging are ignored!
Only the changes that were present at the time of
staging will be committed - not the additional modifications.
Reason: Staging means, that the modifications are copied into
something called *"index"*; it has nothing to do with the actual files.
To see what's going on: <code>git status</code>.
<aside class="footnote"><code>git diff --cached</code> tells what will be committed</aside>
</section>
<section data-markdown>
## Committing
Creating a new commit is probably the most famous feature.
In its basic use case, the modifications from the *index*
are taken and stored as a new commit in the history.
<code>git commit</code>
Additionally, your author information, the time and a custom
"*commit message*" are stored.
</section>
<section data-markdown bc="Diff">
It is also easy to see commit **diff**erences.
<pre class="small">$ <b>git diff HEAD~3..HEAD~2 index.html</b>
diff --git a/index.html b/index.html
index 43063fb..06d9a2e 100644
--- a/index.html
+++ b/index.html
@@ -140,7 +144,9 @@
Gitti Gitian
<span style="color:red">- <code>--global</code> sets this for your entire account!</span>
<span style="color:green">+ <aside class="footnote"></span>
<span style="color:green">+ Remember: <code>--global</code> sets this for your entire account!</span>
<span style="color:green">+ </aside></span>
</section>
</pre>
<code>-</code> = removed <code style="margin-left:2em">+</code> = added
</section>
<section data-markdown data-state="soothe">
## Too many commands?
It is possible to combine **add -A** and **commit**,
even including the commit message:
<pre><code>$ git commit -am "commit message"</code></pre>
</section>
<section data-markdown>
## Log
To see the history, use <code>git log</code>.
* <code>-[number]</code> limits to the last [number] entries
* <code>--oneline</code> self explanatory
* <code>--graph</code> tries to be artsy
* <code>--decorate</code> shows HEAD, branches, and tags
</section>
<section data-markdown bc="short log example">
<pre class="small">$ <b>git log -5 --oneline --graph --decorate HEAD~59</b>
* c411c4d Merge pull request #131 from Sinetheta/master
|\
| * 495cb98 changed theme file swap to be relative to theme file instead of slide-deck
|/
* aa97d80 correction to code style in sky theme, adjusted transition demo page
* 0c06469 prevent same theme from loading repeatedly
* dc9b93a tweaks to the simple theme
* 90f343e add theme config option, add sky theme, fix line-height of <small>
* e3f3e9d Update README.md
* 141d694 support for named links (closes #55)
</pre>
</section>
<section data-markdown>
## Branch, Checkout, Reset
Now we start to get really serious!
There are three very powerful commands, that let you
* move around in the history, pick files from the past
* change all files in the working directory to another state
* change a branch reference without committing
* create a new branch anywhere
* get rid of erroneous work
* etc.
</section>
<section data-markdown>
## Branch
<pre>git branch <i>branch_name</i> [commit] [-f]</pre>
This creates a new branch right where the HEAD is,
or at the given commit.
<code>-f</code> can be used to move an existing branch *reference* around.
<code>-d</code> deletes and <code>-m</code> renames.
</section>
<section data-markdown>
## Checkout
The <code>checkout</code> command has several basic functions.
The most basic one is for switching branches,
which moves the HEAD and populates the index and working directory:
<pre>git checkout branch_name</pre>
Copy a file from the repository:
<pre>git checkout [commit] -- path/filename</pre>
<aside class="footnote">
Apart from that, it also has the shortcut <code>-B</code>
for creating a new branch and immediately switching to it.
</aside>
</section>
<section data-markdown bc="Checkout Branch Graphic">
<img style="width: 90%" src="res/checkout-branch.svg" />
checking out a branch (HEAD moves)
</section>
<section data-markdown bc="Checkout File Graphic">
<img style="width: 90%" src="res/checkout-files.svg" />
checking out files from the history (HEAD doesn't move)
</section>
<section data-markdown>
## Reset
<code>reset</code> sounds a bit more scary - and yes it is.
It's job is to move around the branch reference underneath the HEAD.
<ul>
<li><code>--soft</code> only moves HEAD (like all modes do) and doesn't touch index
<li><code>--mixed</code> (default), resets index
<li><code>--hard</code> resets index and working directory (local changes lost forever!)
</ul>
</section>
<section data-markdown bc="Reset Graphic">
<img style="width: 90%" src="res/reset-commit.svg" />
HEAD+master moves, three commits are lost
</section>
<section data-markdown>
## Reset -- path/filename
Like <code>checkout</code>, <code>reset</code> also
has a mode where it works on paths to files.
This resets the entries for the specified files in the index.
<pre>git reset [commit] -- path/filename</pre>
Hence, this is the opposite of <code>add</code>.
</section>
<section data-markdown bc="Reset File Picture">
<img style="width: 90%" src="res/reset-files.svg" />
</section>
<section data-markdown>
## Summary /1
<img src="res/basic-usage.svg" />
</section>
<section data-markdown>
### Summary /2
It is possible to *skip* the staging area. *Both are modified!*
<img src="res/basic-usage-2.svg" />
</section>
<section data-markdown>
## Merge
Finally, once we have several alternative realities in
different branches, we want to "*merge*" them into one.
The <code>merge</code> command has the job, of creating
a new commit with more than one parent.<sup>1</sup>
<aside class="footnote"><sup>1</sup> Due to "*fast-forwarding*", a merge
could still lead to just one parent. In this case, the
branches are just moved to be on top of each other.
</aside>
</section>
<section data-markdown bc="git help merge">
<pre class="small">Assume the following history exists and the
current branch is "master":
A---B---C topic
/
D---E---F---G master
Then "<b>git merge topic</b>" will replay the changes made
on the topic branch [...] and record the result
in a new commit [...]
A---B---C topic
/ \
D---E---F---G---H master
</section>
</section> <!-- end hands on -->
<section bc="Collaboration">
<section data-markdown>
## P2P
Ok wait. Wasn't Git about *collaboration*?
<p class="fragment">
Well, 99% happens locally.
<br/><br/>
The missing piece is a way to send and recieve commits
as part of branches, based on given references.
</p>
</section>
<section data-markdown>
## Hosting
Lonely Git repositories are sad repositories.
Share your project with collaborators via hosting services!
<ul class="small">
<li>Any server with an <code>sshd</code> server and Git installed</li>
<li><a href="https://www.github.com/">GitHub</a> - very popular, issue tracker, hosting, wiki</li>
<li><a href="http://gitorious.org/">Gitorious</a> - open-source project hosting w/ collaboration tools.</a> </li>
<li><a href="https://bitbucket.org/">Bitbucket</a> - similar to GitHub, also offers free non-public hosting</li>
<li><a href="http://code.google.com/">Google Code</a> - issue tracker and wiki</a></li>
<li><a href="http://www.codeplex.com/">CodePlex</a> - even Microsoft talks Git</a></li>
<li>... or a shared directory initialized with <code>git init --bare</code> usually ending in <code>*.git</code>.</li>
<li>... or a <code>bundle</code> for the paranoid on an isolated machine :-)</li>
</ul>
</section>
<section data-markdown>
## Remote
<code>git remote</code> manages all remote servers.
<code>git remote add [name] [URL]</code> adds a remote server.
And you can list remotes
<pre>$ <b>git remote -v show</b>
origin git@github.com:.../...git (fetch)
origin git@github.com:.../...git (push)
uni ssh://name@login/.../repo (fetch)
uni ssh://name@login/.../repo (push)
</pre>
</section>
<section data-markdown>
## origin/master
When you do a <code>git clone git://.../</code>,
Git has already set you up with a "*remote*"
called **origin** pointing to the given URL.
Also, your main branch is usually called **master**.
Hence, the reference to the master branch on the server is <code>origin/master</code>.
(But you can call them as you like.)
</section>
<section data-markdown>
## pull/push and fetch
* <code>push</code> uploads commits that aren't on the server to it
* <code>fetch</code> downloads new commits which you don't have
* <code>pull</code> does a fetch and also merges with your respective branch
</section>
<section data-markdown>
## Tracking
Finally, you can tell Git which of your local branches
correspond to which ones of the remote repository.
This is called "*tracking*" and could be done via
<pre>git branch --set-upstream master origin/master</pre>
Also, when pushing to a remote, you can do this
via the <code>-u</code> switch: <code>git push -u joe featureX</code>.
<aside class="footnote">
In case of total confusion, this is also in <code>.git/config</code>.
</aside>
</section>
<section data-markdown>
## Check tracking
<pre>$ <b>git branch -vv</b>
* master cf36560 [origin/master] readme
other d39c6f1 [origin/other] init "other" branch, ...
</pre>
<aside class="footnote">There is probably a better way, it's also in the .git/config file</aside>
</section>
<section data-markdown data-state="alert">
## Outdated references
Git could be unaware of new changes on the server.
That usually causes headaches!
In that case, do a <code>git remote update</code>
to get the references straight.
Then, e.g. <code>git log --decorate</code> shows the remote references
at the correct positions!
</section>
</section> <!-- end collab -->
<section bc="Advanced">
<section data-markdown>
## Tags
<code>git tag name [commit]</code> creates a named reference to a specific commit.
They are very similar to a branch reference, but stay fixed.
Usually, it is used to name a specific release version, <code>v2.7.1</code>.
Checking out a tag brings you into the
<a href="#/2/13">detached HEAD</a> state.
It's also possible to cryptographically sign it.
</section>
<section data-markdown>
## Quick Undo
One way to do a quick undo:
<code>git reset [--hard] HEAD^</code>
</section>
<section data-markdown>
## Reflog
As a safeguard, Git stores the entire journey of the HEAD.
This "*reflog*" prevents Git from forgetting
unreachable commits for at least a few weeks.
<b>This means, the quick undo can be undone!</b>
<code>git reflog</code> lists you the relevant hashes.
Use <code>reset --hard</code> to reset everything back to how it was.
Note: This reflog is only local to your repository!
</section>
<section data-markdown>
## Tree
<pre class="small">$ <b>git ls-tree HEAD</b>
100644 blob aa5fa7141766f8cf11d1d25d39cd04a2ffee7a95 .gitignore
100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 .nojekyll
100644 blob 6fed1c32d012538ea783b0eb8d13a643cc981666 LICENSE
100644 blob 27ed242ad6ab8bbb19c9b6182ee47b3939a15db0 README.md
040000 tree 96d0c04c1d308c31faacfa26eeee2b4b256be116 css
100644 blob a9aa16404dd4d78493208929095137097f133975 index.html
040000 tree dd1ae6043bf368f504b2aff6e3b936607bf0be07 js
040000 tree 6e46172d37ce36c570fd65458eefc02cee58c8b2 lib
100644 blob 86578fe468e926513e2ca87d4c5792e333b4b58d package.json
040000 tree 04016b53decd21110649ef3cfdc936ca7849ddce plugin
040000 tree 3f2ac677462a553dbcfe81088d8b276b52c50f29 res
</pre>
</section>
<section data-markdown>
## Blob by Hash
<pre class="small">$ <b>git show 27ed242ad6ab8bbb19c9b6182ee47b3939a15db0</b>
# YAGT - Yet another Git talk
This is a fork of [reveal.js](https://github.com/hakimel/reveal.js)
with the goal to build a talk about [Git](http://www.git-scm.org/)
and hence explaining it.
[...]
</pre>
</section>
<section data-markdown>
## Commit
<pre class="small">$ <b>git show eec35ee</b>
commit eec35ee92b9e3d1f97aecd49b6d884db82604c47
Author: Harald Schilly <harald.schilly@gmail.com>
Date: Sun Oct 7 01:19:58 2012 +0200
more links
diff --git a/index.html b/index.html
index 97f4792..1744916 100644
--- a/index.html
+++ b/index.html
@@ -502,21 +502,33 @@ It is possible to *skip* the staging area. *Both are modified!*
[...]
</pre>
</section>
<section data-markdown>
## Cherry Picking
**Copy** one changeset from one branch into another one.
This is useful to extract changes for one particular aspect
into a separate branch.
<pre>$ <b>git checkout -b fix666 [start_point]</b>
$ <b>git cherry-pick 5d3e1b6</b>
Finished one cherry-pick.
[master e458a9b] Bug fix for Issue #666
3 files changed, 36 insertions(+), 3 deletions(-)
</pre>