-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
440 lines (420 loc) · 15.5 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
<!DOCTYPE html>
<html>
<head>
<title>Git Panic and how to avoid it</title>
<meta charset="utf-8">
<meta name=viewport content="width=device-width, initial-scale=1">
<meta name="description" content="A presentation about advanced git topics and using git the right way" />
<link rel="stylesheet" href="build/bundle.css" />
</head>
<body>
<div id="presentation" class="reveal">
<div class="slides">
<section id="title">
<h1>Git Panic</h1>
<h2>and how to avoid it</h2>
</section>
<section id="alternative-title">
<div class="underlined">Alternative tite:</div>
<h3>Cool tricks you learn<br/>
if you actually read the manual</h3>
<div class="italic">
*Disclaimer: basic git knowledge required
</div>
</section>
<section id="about-the-presenter">
<h3>About me:</h3>
<ul>
<li>Hi, I'm Mihail Mikov</li>
<li>Full-stack engineer at Skyscanner</li>
<li>Hobby juggler</li>
</ul>
<pre><code class="bash">
git config --global user.name "Mihail Mikov"
git config --global user.email "[email protected]"
</code></pre>
</section>
<section id="git-is-hard">
<h3>Git is hard</h3>
<img alt="git is hard meme with jackie chan" width="50%" src="images/git-is-hard.jpg" />
</section>
<section id="symptoms-1">
<h3>Git Panic symptoms</h3>
<ul>
<li class="fragment">Fear of the console / GUI only</li>
<li class="fragment">Unstructured / messy history</li>
<li class="fragment">Complicated / blocking workflow</li>
<li class="fragment warning">Fixing git by cloning to a new repo</li>
</ul>
</section>
<section id="symptoms-2">
<h3>Git Panic symptoms</h3>
<ul>
<li class="fragment">Push races / lots of conflicts</li>
<li class="fragment warning">Lost local changes</li>
<li class="fragment warning">Lost remote commits</li>
</ul>
</section>
<section id="how-do-i-fix-my-git">
<h3>So, how do I fix my git?</h3>
<img width="50%" src="images/house-how-do-we-fix-this.jpg" />
</section>
<section id="panic">
<h3>Bad solution: Panic</h3>
<img width="45%" src="images/panic-home-alone.jpg" />
</section>
<section id="solution">
<h3>Solution</h3>
<img src="images/dontpanic.jpg" />
</section>
<section id="solutions-1">
<h3>Pure Vegan Homeopathic solutions</h3>
<ul>
<li class="fragment bold">Read the manual</li>
<li class="fragment">Use the console</li>
<li class="fragment">Check your status and history often</li>
<li class="fragment">Fetch remotes often</li>
<li class="fragment">Push your WIP often</li>
</ul>
</section>
<section id="solutions-2">
<h3>Pure Vegan Homeopathic solutions</h3>
<ul>
<li class="fragment">Follow a commit message format</li>
<li class="fragment">Name remotes and branches meaningfully</li>
<li class="fragment">Make git help you:
<ul>
<li>Aliases</li>
<li>Tags</li>
<li>Hooks</li>
<li>Command options</li>
</ul>
</li>
</ul>
</section>
<section id="commands">
<h3>About commands</h3>
<pre><code class="sh">
commandName --options arguments
</code></pre>
<div id="command_types">
<span>Command Types:</span>
<ul>
<li><ul>
<li>Local</li>
<li>Remote</li>
</ul></li>
<li><ul>
<li>Pluming</li>
<li>Porcelain</li>
</ul></li>
</ul>
</div>
</section>
<section>
<h3>Command scope</h3>
<img width="50%" src="images/git_commands_affect.png" />
</section>
<section id="repo-history">
<h3>Project history</h3>
<div>Use a short, but detailed graph view of your history</div>
<pre><code class="bash">
git log --all --graph --format="%h %d %an %cr %s"
git log --author="Your Name" --since="3 weeks ago"
git log master...my-branch --left-right
git log --stat -p
</code></pre>
<img src="images/git-log-nice.png" />
</section>
<section id="commit-ranges">
<h3>Commit ranges</h3>
<div>double vs triple dot ranges</div>
<img width="45%" src="images/double-dot-tree.png" />
<img width="45%" src="images/triple-dot-tree.png" />
</section>
<section id="reflog">
<h3>Branch history</h3>
<div>Useful for finding things you were working on</div>
<pre><code class="bash">
# show a history of the commits
# the given branch was pointing to
git reflog <branch>
</code></pre>
<img src="images/git-reflog.png" />
</section>
<section id="revs">
<h3>Referencing commits</h3>
<div>The many ways to refer to commits</div>
<pre><code class="bash">
# exclude commit and its ancestry
^master
# the 2nd ancestor of the given commit
master^^
master~2
#the 2nd parent of the current commit
master^2
</code></pre>
<img style="position: fixed; left: 72%; top: 36%;" src="images/refs.png" />
</section>
<section id="more-revs">
<h3>Referencing refs</h3>
<pre><code>
# the 3rd commit in the log of the ref
master@{2}
# the commit the ref pointed to at the given date
master@{5.days.ago}
</code></pre>
</section>
<section id="file-history">
<h3>File history</h3>
<div>Don't blame the player, blame the game</div>
<pre><code class="bash">
# show who and when last modified each line of a file
git blame --date=relative <file-name>
# show the detailed history of a file
git lg -p -- <file-name>
</code></pre>
<img src="images/git-blame.png" />
</section>
<section id="history-meme">
<img width="40%" src="images/history.jpg" />
</section>
<section id="adding">
<h3>Adding something specific</h3>
<div>Stage your changes and create your commits with care</div>
<pre><code class="bash">
git add -p
</code></pre>
<img src="images/add-p.png" />
</section>
<section id="reset-p">
<h3>Clearing the index snippet by snippet</h3>
<div>That shouldn't be in your next commit</div>
<pre><code class="bash">
# unstage changes from the index
git reset -p
</code></pre>
<img src="images/git-reset-p.png" />
</section>
<section id="checkout-p">
<h3>Make that snippet great again</h3>
<div>Bring back an older version of the snippet</div>
<pre><code class="bash">
# pick and override snippets in the working tree
git checkout -p <commitish> <file-name>
</code></pre>
<img src="images/git-checkout-p.png" />
</section>
<section id="checkout">
<h3>Checkout the code</h3>
<div>Checkout does a lot of things</div>
<pre><code class="bash">
# checkout a branch you previously worked on
git checkout @{-1}
# create a new branch and switch to it
git checkout -b "new_branch"
# like "-b" creates a branch, but the first commit
# on this branch will start an independant history
git checkout --orphan "separate_history"
</code></pre>
</section>
<section id="detached-head">
<h3>Detached head</h3>
<div>A scary name for "you are not on any branch"</div>
<pre><code class="bash">
git checkout <branch>
# HEAD is pointing to a branch
# which is pointing to a commit
git checkout <commit>
# HEAD is pointing directly to a commit
</code></pre>
<img src="images/detached-head.png" />
</section>
<section id="reset-soft">
<h3>Unpacking commits</h3>
<div>You don't need to rebase to squash your commits</div>
<pre><code class="bash">
# make HEAD point to a specific commit
# without changing the index or the working tree
git reset --soft <commitish>
</code></pre>
</section>
<section id="reset-hard">
<h3>Moving our HEAD around</h3>
<pre><code class="bash">
# both HEAD and the current branch
# will point to the given commit
git reset --hard <commitish>
</code></pre>
<div class="warning">
deletes changes in the index and working tree<br/>
may lead to disconnected commits
</div>
</section>
<section id="git-head-meme">
<img src="images/git-head.jpg" />
</section>
<section id="revert">
<h3>Undo some changes</h3>
<div>without rewriting history</div>
<pre><code class="bash">
# creates a commit that negates the changes
# introduced in another commit
git revert <commitish>
</code></pre>
<img src="images/revert.png" />
</section>
<section id="cherry-pick">
<h3>"Moving" a single commit around</h3>
<pre><code class="bash">
# creates a new commit at HEAD with the
# same changes introduced by another commit
git cherry-pick <commitish>
</code></pre>
<img src="images/cherry-pick.png" />
</section>
<section id="rebase">
<h3>"Moving" many commits around</h3>
<pre><code class="bash">
# as if you cherry-picked
# all the commits on a brach in order
git rebase <new-base> <target-defaults-to-HEAD>
# interactive rebase
git rebase -i
# rebase instead of creating a merge commit
git pull --rebase
</code></pre>
</section>
<section id="rebase-img">
<h3>Rebase in action</h3>
<img width="55%" src="images/rebase.png" />
</section>
<section id="aliases">
<h3>Setting up Aliases</h3>
<div>Common tasks should be easy to perform</div>
<pre><code class="bash">
git config --global alias.co "checkout"
git config --global alias.br "branch --verbose"
git config --global alias.up "pull --rebase"
git config --global alias.lg
"log --graph --format='%h %d %an %cr %s'"
git config --global alias.quickfix
"commit -p --amend --no-edit"
</code></pre>
</section>
<section id="ignore-it">
<h3>Conflicts? Just ignore 'em</h3>
<img width="50%" src="images/dont-ignore-the-symptoms.gif">
</section>
<section id="conflicts">
<h3>Resolving conflicts</h3>
<div>
Conflicts appear when git cannot merge<br/>
the content of two versions of a file meaningfully
</div>
<pre><code class="bash">
# abort if you can't solve the conflicts
git <merge | rebase | cherry-pick> --abort
# Warning: the meaning of --theirs / --ours
# is different between merge and rebase
# finish the operation with "--continue"
git add <resolved-files>
git <merge | rebase | cherry-pick> --continue
</code></pre>
</section>
<section id="workflows">
<h3>Common workflows</h3>
<ul>
<li>All in master</li>
<li>Team / Feature branches</li>
<li>Merge / Pull requests</li>
</ul>
</section>
<section id="fetch-and-compare">
<h3>Fetch, compare, rebase</h3>
<div>A pull is just a fetch and a merge</div>
<pre><code class="bash">
git fetch <remote> <branch>
# show a graph of all commits
# since the last common point between the branches
git lg --left-right HEAD...<remote/branch>
# rebase your changes on top of the remote
git rebase <remote/branch>
</code></pre>
</section>
<section id="safe-force-push">
<h3>Safe force push</h3>
<pre><code class="bash">
# only re-write the remote's history
# if you already have a local copy of it
git push --force-with-lease
# alias: git sfp
</code></pre>
</section>
<section id="merge-no-ff">
<h3>Merge, but no fast-forward</h3>
<pre><code class="bash">
# Rebase and merge to keep the branch history visible
git rebase feature_branch master
git merge feature_branch --no-ff
</code></pre>
</section>
<section id="take-aways">
<h3>Recap & takeaways</h3>
<ul>
<li class="fragment">Use the console</li>
<li class="fragment">Name remotes, branches and commits meaningfully</li>
<li class="fragment">Keep your workflow & history understandable</li>
<li class="fragment">Fetch and push often</li>
<li class="fragment">Read the manual</li>
<li class="fragment">Make git help you</li>
</ul>
</section>
<section id="links">
<h3>Links:</h3>
<ul>
<li><a target="_blank" href="http://learngitbranching.js.org/">Learn git in the browser</a></li>
<li><a target="_blank" href="https://www.atlassian.com/git/tutorials">
Git tutorials by Atlassian</a></li>
<li><a target="_blank" href="https://marklodato.github.io/visual-git-guide/index-en.html">
A visual guide to git</a></li>
<li><a target="_blank" href="https://codewords.recurse.com/issues/two/git-from-the-inside-out">
Git from the inside out</a></li>
<li><a target="_blank" href="https://www.youtube.com/watch?v=fCtZWGhQBvo">
Git from the inside out (youtube)</a></li>
<li><a target="_blank" href="https://git-scm.com/book/en/v1/Git-Internals">
Git internals</a></li>
<li><a target="_blank" href="https://blog.scottnonnenberg.com/better-git-configuration/">
Git configuration tips & tricks</a></li>
<li><a target="_blank" href="https://github.com/debel/git-panic-and-how-to-avoid-it">
The code of this presentation on github</a></li>
</ul>
</section>
<section id="qa">
<h3>Questions?!</h3>
<img width="60%" src="images/meeseeks-box-qa.png" />
</section>
<section id="meme-2">
<h3>Thank you!</h3>
<img width="40%" src="images/git.jpg" />
</section>
</div>
</div>
<script src="build/bundle.js"></script>
<script>
(function(i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function() {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-93032616-1', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>