forked from aolabs/git-workflow-slides
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
1626 lines (1358 loc) · 38.7 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>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Git Worflows</title>
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/solarized.css">
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="lib/css/solarized-dark.css">
<!-- 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) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName('head')[0].appendChild(link);
</script>
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<section data-background="images/ao-labs.jpg" style="color:#000">
<h1 style="color:#000">Git Workflows</h1>
<p>Slides by Matthew Gray</p>
<p>
<small>
<br>https://matthew.nz
<br>https://github.com/heymatthew
</small>
</p>
<p>Special thanks to</p>
<p>
<small>
<br><strong>Jef Vratny:</strong> Opportunity setting and guidance
<br><strong>Section 6:</strong> Compatibility advice and feedback
</small>
</p>
</section>
<section data-markdown>
## Rough Timeline
9:30 - 12
- Setup and Overview
- Personal Workflows
12:30 - 5
- Team Workflows
- Release workflows
Tomorrow Onsite for Help
</section>
<section data-markdown>
## Why Git?
* Flexability
* Tooling
* Speed
* Momentum
</section>
<section data-markdown>
## SVN Comparison
* Decentralised, every clone is an entire copy
* Branches contain entire history
* Git tracks content
* SVN tracks deltas
</section>
<section data-markdown>
Git thinks in Snapshots, Not Differences
> The major difference between Git and any other VCS (Subversion and friends included)
> is the way Git thinks about its data.
src: git-scm.com, ch 1.3 Getting Started: Git Basics
</section>
<section>
<p>SVN commits</p>
<div>
<img src="images/branches-svn.png" alt="svn branching strategy">
</div>
<p>Git commits</p>
<div>
<img src="images/branches-commits.png" alt="git history">
</div>
</section>
<section data-markdown>
## Setup
Git
https://git-scm.com/download/win
Tortose Git
https://tortoisegit.org/
Git pad
https://github.com/github/GitPad
Yes! "...use gitpad as your default editor for git"
</section>
<section data-markdown>
## Configure
```bash
git config --global user.name "Matthew B. Gray"
git config --global user.email "[email protected]"
git config --list
git config --list --show-origin
```
--global stores your global settings
Default puts settings into your repo
</section>
<section data-markdown>
## Docs
For help on git config, git has a help page
```bash
git help $command
git help config
```
</section>
<section data-markdown>
## Exercise
- Using `git help`, pull up pages on `git config`
- Use help to find out how to unset `user.email`
- List configurations with `--list --show-origin`
- Open your .gitconfig file, how are fields saved?
</section>
</section>
<section>
<section data-markdown>
## Personal Workflows 1
- Immediate productivity: Build and commit to repos
- Anatomy of a commit: Fields and behaviours
- Staging files: Steps leading to a commit
- All about Branches: Create and delete branches
</section>
<section data-markdown>
## Immediate productivity
Create a git repo
```bash
mkdir test
cd test
git init
git status
```
</section>
<section data-markdown>
## Immediate productivity
Adding and resetting files in the staging area
```bash
git status
git add myfile.txt
git reset myfile.txt
git status
```
Whole directories too
```bash
git add .
git add myfolder
git reset myfolder
```
</section>
<section data-markdown>
## Immediate productivity
Commit your staged changes
```bash
git commit
```
Save with an empty file and git will abort
</section>
<section data-markdown>
## Immediate productivity
Delete a git repo
```bash
rmdir /S .git
git status
```
</section>
<section data-markdown>
## Exercise time!
Create a repo and commit to it
```
mkdir test_repo
cd test_repo
git init
git add
git commit
```
HOT TIP
Set verbose on commit and commit another file
```
git config --global commit.verbose true
git add
git commit
```
What shows up in the commit message?
</section>
<section data-markdown>
## Exercise time 2!
Lookup help pages on git commit
```
git help
```
Based on help hints, remove a file and commit
</section>
<section data-markdown>
## Anatomy of a commit
Commits are
- Immutable
- SHA1 Hashed
- Built on
- File contents
- Timestamp
- Author
- Parent or parents
</section>
<section>
<p>One more time in context</p>
<div>
<img src="images/branches-commits.png" alt="git history">
</div>
</section>
<section data-markdown>
## Anatomy of a commit
Commits can be seen with
```
git show
git log
```
And referenced by
- Hash
- Branch
- HEAD
- Relative to other commits
</section>
<section data-markdown>
## Anatomy of a commit
Looking at a commit
```
git show
```
```
commit d5401a6399234ddfe7bc986a0fe120359505aad5 (HEAD -> master)
Author: Matthew B. Gray <[email protected]>
Date: Mon Oct 13 13:01:15 2017 -0800
All of the things
diff --git a/bar.txt b/bar.txt
new file mode 100644
index 0000000..7bcc722
--- /dev/null
+++ b/bar.txt
@@ -0,0 +1 @@
+the bar has a bar tender
\ No newline at end of file
diff --git a/fu.txt b/fu.txt
new file mode 100644
index 0000000..f2e93e3
--- /dev/null
+++ b/fu.txt
@@ -0,0 +1 @@
+a fu enters the bar
\ No newline at end of file
```
</section>
<section data-markdown>
## Anatomy of a commit
Raw commit
```
git show --raw
```
```
commit d5401a6399234ddfe7bc986a0fe120359505aad5
Author: Matthew B. Gray <[email protected]>
Date: Mon Oct 13 13:01:15 2017 -0800
All of the things
:000000 100644 0000000... 7bcc722... A bar.txt
:000000 100644 0000000... f2e93e3... A fu.txt
:000000 100644 0000000... bc979a6... A lib/flubber.txt
:000000 100644 0000000... e69de29... A lib/flubber2.txt
```
</section>
<section data-markdown>
## Anatomy of a commit
Lets talk about immutability!
* Nodes represent diffs with respect to each other
* Nodes represent entire file tree on their own
Point to nodes with...
* **branch** - a name to track your work
* **tag** - a label, it doesn't move
* **commit hash** - complete history and set of files
* **HEAD** - your current checkout
* **$ref~** - above are $refs, chain ^ or ~ to go up a branch
</section>
<section data-markdown>
## Exercise time!
What is the difference between
```
git show
git show HEAD
git show master
```
You can get at relative commits by appending ~, try it
```
git show HEAD~
git show master~
```
Find the parent commit with `git log`
Make log show all but the last commit with `HEAD~`
What does `git log --stat` do?
</section>
<section data-markdown>
## Exercise time 2!
Take the hash from
```
git show
```
Pass it to `git log` and `git show`
</section>
<section data-markdown>
## Staging files
![staged, unstages, commits, and stashes](images/staging-area.png)
credit: http://ndpsoftware.com/git-cheatsheet.html
</section>
<section>
<h3>Typical git workflow</h3>
<img src="images/individual-workflow.svg" height="500" alt="personal workflow">
</section>
<section data-markdown>
## Staging files
Lets talk about Test Driven Development
1. write test, RED
2. git add
3. write code, GREEN
4. git add, git commit
5. REFACTOR
6. git commit
</section>
<section data-markdown>
## Staging files
Audit your work interactively with your staging area
```
git add -p
```
Unstaging files can be done in parts too
```
git reset -p
```
</section>
<section data-markdown>
## Staging files
If you want to reset to a GREEN state
```
git checkout .
git checkout myfile.txt
git status
```
This doesn't affect added files
```
git add -p
git checkout .
git status
```
</section>
<section data-markdown>
## Exercise time!
1. Make changes to 2 files already committed
2. Change 1 of them
3. Checkout everything
```
git checkout .
```
What changed?
How could you get rid of your staged changes?
</section>
<section data-markdown>
## All about Branches
Master is the default branch in git
Create branches with
```
git branch mybranch
```
Checkout branches with
```
git checkout mybranch
```
</section>
<section data-markdown>
## All about branches
![](images/branches-typical.png)
![](images/branches-multi.png)
Typical branching, images from http://git-scm.com
</section>
<section data-markdown>
## All about branches
![](images/branches-perspective.png)
How branches can be used for workflow
</section>
<section data-markdown>
## All about Branches
List branches with
```
git branch
```
...list all branches with -a
```
git branch -a
```
</section>
<section data-markdown>
## All about Branches
Delete branches with
```
git branch -d mybranch
```
It complains if this is the only copy, such as
- When another branch isn't referencing it
- When it's not shared / pushed
...use -D to go ahead deleting the only copy
</section>
<section data-markdown>
## Exercise time!
Create and checkout a branch
```
git branch
git checkout
git status
```
Commit to the branch, copy the hash down
Delete the branch
```
git branch -d
```
Can you `show` the hash from the deleted branch?
</section>
<section data-markdown>
## Exercise time 2!
Run
```
git gc
```
Can you still see the hash? Why?
```
git help gc
```
</section>
</section>
<section>
<section data-markdown>
## Personal Workflows 2
- Searching and Testing: How to find missing stuff
- Reset the world: Moving branches around arbitrarily
- Diffs and Commits: Tips for review
- Merge stuff, break stuff: Integrate your work
</section>
<section data-markdown>
## Searching and Testing
Understanding why something is in it's current form
1. Avoids regressing your codebase
2. Lets you know if code is under warantee
3. Lets you seek out a human when stuck
</section>
<section data-markdown>
## Searching and Testing
* Log - Show commit logs
* Pickaxe - Search commit diffs for changes
* Blame - revision and author for lines of a file
* Headless Checkout - Options for work without tracking
</section>
<section data-markdown>
## Searching and Testing
Regular log
```
git log
```
Show me contents of patches
```
git log -p
```
Show me a summary of patches
```
git log --stat
```
Find changes associated with text in a commit message:
```
git log --grep '$search_term'
git log --grep 'bug#1234'
```
</section>
<section data-markdown>
## Searching and Testing
```
git log -S 'some distinct line that changed'
git log --stat -S '$racebook_uri_result'
```
* Find all the changes to a line in your entire history
* The pickaxe can help find code that’s been deleted or moved
* Typically helps you with questions like
- What happened to myFabuliousFunc()?
- When did $mySillyVariable get referenced everywhere?
* Works with log, diff, and format-patch
</section>
<section data-markdown>
## Searching and Testing
```
git blame $filename
git show $hash
```
Ignore whitespace
```
git blame -w $filename
```
Copy paste detection in a file, and across the repo
```
git blame -C $filename
```
</section>
<section data-markdown>
## Headless Checkout
Options for work without tracking
If you're not on a branch, git puts you in a headless state
```
git checkout $tag
git checkout $commit
git checkout $hash
```
</section>
<section data-markdown>
## Headless Checkout
Trying something like this...
```
git checkout HEAD~
```
Results in something like this...
```
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
HEAD is now at f4b37d8... CSS: Return values should be numbers
```
Which is git being melodramatic
</section>
<section data-markdown>
## Exercise time!
1. Clone jquery repo
2. Use git log to find fixes to issue #14756
3. Use pickaxe to find commits that added or removed 'parseFloat'
4. Try git blame on the README.md file
5. With this info, when was the Contribution Guides section last modified?
```
git clone https://github.com/jquery/jquery
git log --grep 'asdf'
git log -S 'asdf'
git blame $file
git show $hash
```
</section>
<section data-markdown>
## Reset the world
Moving branches around arbitrarily
```
git checkout $branch
git reset $ref
```
Same command for repo and staging area
```
git reset $ref
git reset myfile.txt
git reset myfolder
```
</section>
<section data-markdown>
## Reset the world
Backup if you're not sure with a branch
```
git branch backup
git reset $ref
```
And if everything goes pear shaped
```
git reflog
```
</section>
<section data-background-image="images/oops.gif" data-markdown>
```
# Save my ass! What have I had 'checked out' recently?
git reflog
git reset REF
```
</section>
<section data-markdown>
## Exercise time!
In jquery, from master, create a backup branch
Run
```
git reset HEAD~
```
What happened?
What happens when you use `--hard`?
Reset to your backup branch
Run
```git reflog```
How else could you put master back?
</section>
<section data-markdown>
## Diffs and Commits
Review modifications to a file with
```
git diff
```
Review modifications after git add with
```
git diff --staged
```
</section>
<section data-markdown>
## Diffs and Commits
You can specify ranges with dots to both log and diff
.. (two dots)
* differences between two revisions
* optionally limiting comparison to files/folders
... (three dots)
* differences between the *last common ancestor*
* also optionally limiting comparison to files/folders
</section>
<section data-markdown>
## Diffs and Commits
Differences between your branch and master
```
git diff master..HEAD
```
Differences added since you branched from master
```
git diff master...HEAD
```
</section>
<section data-markdown>
## Diffs and Commits
Similarly, differences between your branch and master
```
git log master..HEAD
```
Differences added since you branched from master
```
git log master...HEAD
```
</section>
<section data-markdown>
## Exercise time!
In your jquery checkout, diff between 1.1 and 1.2
```
git diff 1.1...1.2
```
What happens when you pass `--stat`?
Try with 3 and 2 dots, are they different? Why?
What happens when you run
```
git diff 1.1...
```
Repeat with `git log`
</section>
<section data-markdown>
## Merge stuff, break stuff
Check out the branch you want your stuff in, and merge with git merge
```
git checkout master
git merge mybranch
```
Or pull other people's stuff into your branch
```
git checkout mybranch
git merge master
git merge anotherbranch
```
</section>
<section data-markdown>
## Merge stuff, break stuff
Source control is about social coding and interactions.
A conflict should be a conversation. When you see
```
CONFLICT (content): Merge conflict in jabberwocky.html
Automatic merge failed; fix conflicts and then commit the result.
```
Get info with
```
git status
git diff
git blame $file
```
</section>
<section data-markdown>
## Merge stuff, break stuff
Markers are usually HEAD and a $ref, where
1. HEAD is work of yours
2. $ref is the thing you're in conflict with
Lets try simulate a merge conflict and get here...
```
git status
git diff
git blame $file
```
</section>
<section data-markdown>
## Exercise time!
In your jquery repo, checkout master and merge in `origin/killphp`
```
git merge origin/killphp
git status
git diff
git blame $file
```
What files are in conflict?
What authors need to talk?
How many commits is origin/killphp from master?
```
git log ref1...ref2
```
</section>
</section>
<section>
<section data-markdown>
## Team Workflows 1
- Remotes: Lets talk about branches on origin
- Share your work: Team Foundation Server
- Rebase vs Merge: An argument for clean history
- Git ignore: Don't bother tracking the superfluous
</section>
<section data-markdown>
## Remotes
Git just tracks content. All history is stored in .git, and sharing
is just syncing this directory.
Location can be...
1. ssh://[user@]host.xz[:port]/path/to/repo.git/
1. git://host.xz[:port]/path/to/repo.git/
1. http[s]://host.xz[:port]/path/to/repo.git/
1. ftp[s]://host.xz[:port]/path/to/repo.git/
1. rsync://host.xz/path/to/repo.git/
</section>
<section data-markdown>
## Remotes
Clone coppies a remote
```
git clone $location
```
...creates a remote called "origin"
To modify remotes...
```
git remote add $alias $location
git remote rm $alias $location
```
</section>
<section data-markdown>
## Exercise Time!
Share your terrible poetry with your neighbour.
This is for unauthenticated read-only access.
```
git config --global alias.serve ^
"daemon --verbose --export-all " ^
"--base-path=.git --reuseaddr --strict-paths .git/"
```
Run it in the base of any git checkout
```
git clone https://github.com/heymatthew/jabberwocky
cd jabberwocky
git serve
```
</section>
<section data-markdown>
## Exercise Time 2!
When this is setup, exchange details and try clone...
```
ipconfig
git clone git://$host_ip/ jabberwocky-fred
cd jabberwocky-fred
```
or add a remote...
```
git remote add git://$host_ip/ fred
git fetch --all
git log fred/master
git diff fred/master master
```
</section>
<section>
<img src="images/share.gif" alt="lion king, throwing simba as a metaphor for sharing">
</section>
<section data-markdown>
## Share your work
Lets try again with Team Foundation Server
1. Lets get everyone on this project
https://fregroup.visualstudio.com/_git/AO%20Training
2. Clone it
3. Create a branch
4. Make a change, commit and push
5. Create a merge request
6. Leave a comment on the merge request
</section>
<section data-markdown>
## Rebase vs Merge
An argument for clean history
`pull` can create merges implicitly
</section>
<section data-markdown>
## Rebase vs Merge
`pull --rebase` will use a rebase strategy to get your work copied over
</section>
<section data-markdown>
## Rebase vs Merge
And you can rewrite your history with `--interactive`
</section>
<section data-markdown>
## Rebase vs Merge
Set up git pull to rebase by default
```
git config --global branch.rebase true
git config --global branch.autosetuprebase always
```
If you're not ready, you can pull the plug
```
git rebase --abort
git merge --abort
```
</section>
<section data-markdown>
## Rebase vs Merge
Demo with `exec` on `heymatthew/status-gem.git`
</section>
<section data-markdown>
## Exercise time!
1. From the jabberwocky repo
3. Delete script tag on line 28
4. Commit, call it something like FIXUP
5. Interactive rebase onto the tag v1
6. Squash your fix with 'Oops' and give it a message.
```
cd jabberwocky
git add jabberwocky.html
git commit
git rebase v1 --interactive
git log -p
```
...it's as if the error was never there.
</section>