-
-
Notifications
You must be signed in to change notification settings - Fork 54
/
index.html
662 lines (622 loc) · 23.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
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js ie7 oldie" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js ie8 oldie" lang="en"> <![endif]-->
<!-- [if gt IE 8]><! -->
<html class="no-js" lang="en">
<!-- <![endif] -->
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>
Git Hooks - A Guide for Programmers
</title>
<meta
name="description"
content="Git Hooks are a powerful tool for automating tasks in Git. Learn how to use them with this comprehensive guide for programmers."
/>
<meta name="author" content="Matthew Hudson" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta property="fb:admins" content="25102034" />
<meta property="og:site_name" content="GitHooks" />
<meta
property="og:description"
content="Git Hooks are a powerful tool for automating tasks in Git. Learn how to use them with this comprehensive guide for programmers."
/>
<meta property="og:locale" content="en_US" />
<meta property="og:title" content="Learn how to improve your Git skills" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://githooks.com/" />
<link rel="canonical" href="https://githooks.com/" />
<link
href="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/css/bootstrap-combined.no-icons.min.css"
rel="stylesheet"
/>
<link
href="https://fonts.googleapis.com/css?family=Inconsolata:400,700"
rel="stylesheet"
/>
<style>
body {
font-family: "Inconsolata", monospace, sans-serif;
color: #494949;
font-size: 1.15em;
margin-bottom: 1.25em;
}
h2 {
font-size: 22px;
line-height: 30px;
}
.container,
.container li {
line-height: 1.75em;
}
.container li {
margin: 0 0 0.35em 1.5em;
}
.container ul li {
list-style-type: circle;
}
.navbar-inner {
background: #067df7;
}
.navbar .brand,
.navbar .brand a {
color: #fff;
text-shadow: none;
font-size: 24px;
margin-bottom: 0;
line-height: 1.25em;
font-weight: 700;
letter-spacing: 2px;
}
.brand:hover {
background-color: #333;
background-color: rgba(255, 255, 255, 0.05);
color: #ffffff;
text-decoration: none;
}
code {
color: #bd10e0;
}
ul,
ol {
padding: 0;
margin: 0 0 0.5em 1em;
}
hr.soften {
margin: 1.5em 0 1.25em 0;
}
p {
padding: 0 0 1em;
}
a,
a:visited,
a:active,
a:hover {
color: #067df7;
text-decoration: none;
background: none;
font-weight: bold;
}
a:hover {
text-decoration: underline;
}
.github-corner:hover .octo-arm {
animation: octocat-wave 560ms ease-in-out;
}
@keyframes octocat-wave {
0%,
100% {
transform: rotate(0);
}
20%,
60% {
transform: rotate(-25deg);
}
40%,
80% {
transform: rotate(10deg);
}
}
@media (max-width: 500px) {
.github-corner:hover .octo-arm {
animation: none;
}
.github-corner .octo-arm {
animation: octocat-wave 560ms ease-in-out;
}
}
.container svg {
position: relative;
top: 5px;
}
.symbol-heart {
fill: red;
}
</style>
</head>
<body>
<a
href="https://github.com/matthewhudson/githooks.com"
class="github-corner"
aria-label="View source on GitHub"
>
<svg
width="80"
height="80"
viewBox="0 0 250 250"
style="
fill: #151513;
color: #fff;
position: absolute;
top: 0;
border: 0;
right: 0;
"
aria-hidden="true"
>
<path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
<path
d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
fill="currentColor"
style="transform-origin: 130px 106px;"
class="octo-arm"
></path>
<path
d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
fill="currentColor"
class="octo-body"
></path>
</svg>
</a>
<div class="container">
<div id="body" class="row">
<div class="span16">
<h1 class="text-center">
Git Hooks
</h1>
<p class="text-center">
Open source on
<a href="https://github.com/matthewhudson/githooks.com">GitHub</a
>.<br />
Made with
<svg
height="20"
class="symbol-heart"
aria-label="love"
viewBox="0 0 12 16"
version="1.1"
width="15"
role="img"
>
<path
fill-rule="evenodd"
d="M11.2 3c-.52-.63-1.25-.95-2.2-1-.97 0-1.69.42-2.2 1-.51.58-.78.92-.8 1-.02-.08-.28-.42-.8-1-.52-.58-1.17-1-2.2-1-.95.05-1.69.38-2.2 1-.52.61-.78 1.28-.8 2 0 .52.09 1.52.67 2.67C1.25 8.82 3.01 10.61 6 13c2.98-2.39 4.77-4.17 5.34-5.33C11.91 6.51 12 5.5 12 5c-.02-.72-.28-1.39-.8-2.02V3z"
></path>
</svg>
by <a href="https://hudson.dev">Matthew Hudson</a>
</p>
<hr />
<h2 id="introduction">Introduction</h2>
<p>Git Hooks are a built-in feature of Git that allow developers to automate tasks and enforce policies throughout the
Git workflow. By writing custom scripts that Git can execute at key points in the development process, Git Hooks
enable developers to streamline their workflow, ensure code quality, and enforce project-specific policies. In this
guide, we will explore Git Hooks and show you how to use them effectively.</p>
<hr class="soften" />
<h2 id="what-are-git-hooks">What are Git Hooks?</h2>
<p>
Git Hooks are scripts that Git can execute automatically when certain events occur, such as before or after a commit,
push, or merge. There are several types of Git Hooks, each with a specific purpose. Pre-commit hooks, for example, can
be used to enforce code formatting or run tests before a commit is made. Pre-push hooks can be used to prevent pushes to
certain branches or run additional tests before pushing. Post-merge hooks can be used to perform actions after a merge
is completed, such as updating dependencies or generating documentation.
</p>
<p>
These hook scripts are only limited by a developer's imagination.
Some example hook scripts include:
</p>
<ul>
<li>
<b>pre-commit</b>: Check the commit message for spelling errors.
</li>
<li><b>pre-receive</b>: Enforce project coding standards.</li>
<li><b>post-commit</b>: Email/SMS team members of a new commit.</li>
<li><b>post-receive</b>: Push the code to production.</li>
</ul>
<hr class="soften" />
<h2 id="how-to-use-git-hooks">How to Use Git Hooks:</h2>
<p>
To use Git Hooks, you simply need to create executable scripts in the <code>.git/hooks</code> directory of your Git
repository. The
scripts should be named after the Git Hook event they correspond to (e.g., <code>pre-commit</code>,
<code>pre-push</code>, <code>post-merge</code>) and have
the appropriate permissions (<code>chmod +x</code>). Once the scripts are in place, Git will automatically execute them
at the
corresponding events.
</p>
<p>Here's a full list of hooks you can attach scripts to:</p>
<ul>
<li>
<a
href="https://github.com/git/git/blob/master/templates/hooks--applypatch-msg.sample"
>applypatch-msg</a
>
</li>
<li>
<a
href="https://github.com/git/git/blob/master/templates/hooks--pre-applypatch.sample"
>pre-applypatch</a
>
</li>
<li>
<a href="https://www.git-scm.com/docs/githooks#_post_applypatch"
>post-applypatch</a
>
</li>
<li>
<a
href="https://github.com/git/git/blob/master/templates/hooks--pre-commit.sample"
>pre-commit</a
>
</li>
<li>
<a
href="https://github.com/git/git/blob/master/templates/hooks--prepare-commit-msg.sample"
>prepare-commit-msg</a
>
</li>
<li>
<a
href="https://github.com/git/git/blob/master/templates/hooks--commit-msg.sample"
>commit-msg</a
>
</li>
<li>
<a href="https://www.git-scm.com/docs/githooks#_post_commit"
>post-commit</a
>
</li>
<li>
<a
href="https://github.com/git/git/blob/master/templates/hooks--pre-rebase.sample"
>pre-rebase</a
>
</li>
<li>
<a href="https://www.git-scm.com/docs/githooks#_post_checkout"
>post-checkout</a
>
</li>
<li>
<a href="https://www.git-scm.com/docs/githooks#_post_merge"
>post-merge</a
>
</li>
<li>
<a href="https://www.git-scm.com/docs/githooks#pre-receive"
>pre-receive</a
>
</li>
<li>
<a
href="https://github.com/git/git/blob/master/templates/hooks--update.sample"
>update</a
>
</li>
<li>
<a href="https://www.git-scm.com/docs/githooks#post-receive"
>post-receive</a
>
</li>
<li>
<a
href="https://github.com/git/git/blob/master/templates/hooks--post-update.sample"
>post-update</a
>
</li>
<li>
<a href="https://www.git-scm.com/docs/githooks#_pre_auto_gc"
>pre-auto-gc</a
>
</li>
<li>
<a href="https://www.git-scm.com/docs/githooks#_post_rewrite"
>post-rewrite</a
>
</li>
<li>
<a href="https://www.git-scm.com/docs/githooks#_pre_push"
>pre-push</a
>
</li>
</ul>
<hr class="soften" />
<h2 id="tips-for-writing-git-hooks">Tips for Writing Effective Git Hooks:</h2>
<p>
When writing Git Hooks, it's important to keep a few things in mind:
</p>
<ol>
<li><i>Git Hooks should be fast and reliable.</i> Slow or unreliable scripts can slow down the Git workflow and cause
errors.</li>
<li><i>Git Hooks should be well-documented.</i> Make sure to include comments in your scripts so that other developers
can
understand what they do.</li>
<li><i>Git Hooks should be non-intrusive.</i> Avoid scripts that modify code or files without the user's consent.</li>
</ol>
<hr class="soften" />
<h2 id="why-should-i-care">Conclusion</h2>
<p>
Git Hooks are a powerful tool for automating tasks and enforcing policies in Git. By writing custom scripts that Git can
execute at key points in the development process, developers can streamline their workflow and ensure code quality. With
the tips and techniques outlined in this guide, you'll be able to use Git Hooks effectively in your own projects.
</p>
<hr class="soften" />
<h2 id="reading">Reading</h2>
<ul>
<li>
<a
href="http://ryanflorence.com/deploying-websites-with-a-tiny-git-hook/"
>Deploying websites with a Git hook</a
>
</li>
<li>
<a
href="http://longair.net/blog/2011/04/09/missing-git-hooks-documentation/"
>The missing Git hooks documentation</a
>
</li>
<li>
<a href="http://omerkatz.com/blog/git-hooks-part-i-the-basics"
>Git Hooks (Part I): The Basics</a
>
</li>
<li>
<a
href="http://omerkatz.com/blog/2013/5/23/git-hooks-part-2-implementing-git-hooks-using-python"
>Git Hooks (Part II): Implementing Git Hooks using Python</a
>
</li>
<li>
<a
href="http://codeinthehole.com/tips/tips-for-using-a-git-pre-commit-hook/"
>Tips for using Git pre commit hook</a
>
</li>
<li>
<a href="https://wilsonmar.github.io/git-hooks/"
>Use a bootstrap shell script to use Git Hooks in Mac with
PowerShell and with IntelliJ</a
>
</li>
<li>
<a href="https://knpw.rs/blog/direnv-git-hooks"
>Using direnv to Automatically Manage Git Hooks</a
>
</li>
</ul>
<hr class="soften" />
<h2 id="projects">Projects</h2>
<ul>
<li>
<a href="https://github.com/brigade/overcommit">overcommit</a> - A
well-maintained, up-to-date, flexible Git hook manager.
</li>
<li>
<a href="https://github.com/mroth/lolcommits">Lolcommits</a> -
Takes a snapshot with your webcam every time you git commit code,
and archives a lolcat style image with it.
</li>
<li>
<a href="https://github.com/bmwant/podmena">podmena</a> - Enhance
your commit messages adding random emoji to it.
</li>
<li>
<a href="https://pre-commit.com/">pre-commit</a> - A framework for
managing and maintaining multi-language pre-commit hooks.
</li>
<li>
<a href="https://npmjs.org/package/node-hooks">Hooks</a> is a
command line git hook management tool.
</li>
<li>
<a href="https://github.com/rudikershaw/git-build-hook">Git Build Hook Maven Plugin</a>
- A maven plugin for managing client side (local) git configuration and installing hooks for those working on your project.
</li>
<li>
<a href="https://github.com/gnustavo/Git-Hooks">Git::Hooks</a> - A
framework for implementing Git (and Gerrit) hooks.
</li>
<li>
<a href="https://pypi.python.org/pypi/git-pre-commit-hook"
>git-pre-commit-hook</a
>
- Hook that blocks bad commits. Useful for Python-development.
</li>
<li>
<a href="https://metacpan.org/pod/App::GitHooks">App::GitHooks</a>
- A modular and easy to configure git hooks framework, supporting
<a
href="https://metacpan.org/search?q=App%3A%3AGitHooks%3A%3APlugin%3A%3A"
>many plugins</a
>.
</li>
<li>
<a href="https://pythonhosted.org/jig/">Jig</a> - A pre-commit
hook on steroids.
</li>
<li>
<a href="https://github.com/wecodemore/GitPHPHooks"
>GitPHPHooks</a
>
- Write your hooks in PHP, manage and organize them on a task and
project level. Has an additional Hooks library
<a href="https://github.com/wecodemore/GitPHPHooksLibrary"
>on GitHub</a
>.
</li>
<li>
<a href="https://github.com/wecodemore/grunt-githooks"
>Grunt GitHooks</a
>
- Setup, manage and update your hooks with Grunt. Can be used with
all languages, supports templates.
</li>
<li>
<a href="https://github.com/git-hooks/git-hooks">git-hooks</a> -
Hook manager.
</li>
<li>
<a href="https://github.com/peacechen/node-git-hooks">
node-git-hooks
</a>
- Automated, cross-platform, deployment-friendly Git hooks installation.
</li>
<li>
<a href="https://github.com/typicode/husky">Husky</a> - Git hooks
for Node.js, manage your hooks from your package.json.
</li>
<li>
<a href="https://github.com/BernardoSilva/git-hooks-php"
>git-hooks-php</a
>
- Git hooks for PHP based projects.
</li>
<li>
<a href="https://github.com/elpete/commandbox-githooks"
>commandbox-githooks</a
>
- Git hooks for CommandBox CFML based projects.
</li>
<li>
<a href="https://github.com/Autohook/Autohook">Autohook</a> - A
very, <em>very</em> small Git hook manager with focus on
automation.
</li>
<li>
<a href="https://github.com/greenbone/autohooks">autohooks</a> - A
library for managing and writing git hooks in Python.
</li>
<li>
<a href="https://pypi.org/project/hooks4git">hooks4git</a> - A
simple, flexible and language agnostic git hook management
approach.
</li>
<li>
<a href="https://github.com/rycus86/githooks">Githooks</a> -
Auto-install Git hook, that supports hooks in any language checked
into Git and also shared repos.
</li>
<li>
<a href="https://github.com/aitemr/awesome-git-hooks"
>Awesome Git Hooks</a
>
- A collection of awesome Git Hooks.
</li>
<li>
<a href="https://github.com/ghooks-org/ghooks">ghooks</a> - Simple
git hooks for Javascript. Manage your hooks via package.json.
</li>
<li>
<a href="https://github.com/gtramontina/ghooks.cr">ghooks.cr</a> -
Simple git hooks for Crystal. Keep your hooks in a versioned
".githooks/" directory.
</li>
<li>
<a href="https://github.com/gtramontina/ghooks.gradle"
>ghooks.gradle</a
>
- Simple git hooks for Gradle. Keep your hooks in a versioned
".githooks/" directory.
</li>
<li>
<a href="https://github.com/evilmartians/lefthook">Lefthook</a> -
Fast and powerful Git hooks manager for any type of projects.
</li>
<li>
<a href="https://github.com/fisker/git-hooks-list"
>Git Hooks List</a
>
- List of Git hooks.
</li>
<li>
<a href="https://github.com/boddenberg-it/.githooker"
>.githooker</a
>
- Eases setup, maintenance, handling of git-hooks across
teams/projects for virtually all languages + common git-hook-ish
tasks as declarative configuration inside your repo!
</li>
<li>
<a href="https://commitlint.js.org/">Commit lint</a>
- Commitlint helps your team adhere to a commit convention.
</li>
<li>
<a href="https://mbrehin.github.io/git-precommit-checks/">git-precommit-checks</a>
- Configurable checks for staged contents.
</li>
<li>
<a href="https://www.npmjs.com/package/validate-branch-name">validate-branch-name</a>
- Branch name validator.
</li>
<li>
<a href="https://semantic-release.gitbook.io/semantic-release/">Semantic release</a>
- Fully automated version management and package publishing.
</li>
</ul>
<hr class="soften" />
<h2 id="snippets">Snippets</h2>
<ul>
<li>
<a
href="https://gist.github.com/kalpeshsingh/e7682478b8927700c714f12e37f0837e"
>Prevent Direct Push to Master</a
>
- A pre-push hook that prevents direct code push to master branch
and notify with a message in Amazon Chime group.
</li>
</ul>
<hr class="soften" />
<h2 id="contribute">Contribute</h2>
<p>
If you have a Git Hook you love, or a resource you've written for
the community - please create a pull request
<a href="https://github.com/matthewhudson/githooks.com/">here</a>.
</p>
<hr class="soften" />
<footer>
<p class="text-center">
Open source on
<a href="https://github.com/matthewhudson/githooks.com">GitHub</a
>.<br />
Made with
<svg
height="20"
class="symbol-heart"
aria-label="love"
viewBox="0 0 12 16"
version="1.1"
width="15"
role="img"
>
<path
fill-rule="evenodd"
d="M11.2 3c-.52-.63-1.25-.95-2.2-1-.97 0-1.69.42-2.2 1-.51.58-.78.92-.8 1-.02-.08-.28-.42-.8-1-.52-.58-1.17-1-2.2-1-.95.05-1.69.38-2.2 1-.52.61-.78 1.28-.8 2 0 .52.09 1.52.67 2.67C1.25 8.82 3.01 10.61 6 13c2.98-2.39 4.77-4.17 5.34-5.33C11.91 6.51 12 5.5 12 5c-.02-.72-.28-1.39-.8-2.02V3z"
></path>
</svg>
by <a href="https://hudson.dev">Matthew Hudson</a>
</p>
</footer>
</div>
</div>
</div>
<!-- ! end of .container -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-B0CMMW48E4"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-B0CMMW48E4');
</script>
</body>
</html>