Autogenerated HTML docs for v2.46.0-551-gc5ee8
[git-htmldocs.git] / MyFirstContribution.html
blob4756ee38f59d70d881b8eb39ec8f4078c7527da5
1 <!DOCTYPE html>
2 <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
3 <head>
4 <meta charset="UTF-8"/>
5 <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
6 <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
7 <meta name="generator" content="Asciidoctor 2.0.20"/>
8 <title>My First Contribution to the Git Project</title>
9 <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700"/>
10 <style>
11 /*! Asciidoctor default stylesheet | MIT License | https://asciidoctor.org */
12 /* Uncomment the following line when using as a custom stylesheet */
13 /* @import "https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700"; */
14 html{font-family:sans-serif;-webkit-text-size-adjust:100%}
15 a{background:none}
16 a:focus{outline:thin dotted}
17 a:active,a:hover{outline:0}
18 h1{font-size:2em;margin:.67em 0}
19 b,strong{font-weight:bold}
20 abbr{font-size:.9em}
21 abbr[title]{cursor:help;border-bottom:1px dotted #dddddf;text-decoration:none}
22 dfn{font-style:italic}
23 hr{height:0}
24 mark{background:#ff0;color:#000}
25 code,kbd,pre,samp{font-family:monospace;font-size:1em}
26 pre{white-space:pre-wrap}
27 q{quotes:"\201C" "\201D" "\2018" "\2019"}
28 small{font-size:80%}
29 sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}
30 sup{top:-.5em}
31 sub{bottom:-.25em}
32 img{border:0}
33 svg:not(:root){overflow:hidden}
34 figure{margin:0}
35 audio,video{display:inline-block}
36 audio:not([controls]){display:none;height:0}
37 fieldset{border:1px solid silver;margin:0 2px;padding:.35em .625em .75em}
38 legend{border:0;padding:0}
39 button,input,select,textarea{font-family:inherit;font-size:100%;margin:0}
40 button,input{line-height:normal}
41 button,select{text-transform:none}
42 button,html input[type=button],input[type=reset],input[type=submit]{-webkit-appearance:button;cursor:pointer}
43 button[disabled],html input[disabled]{cursor:default}
44 input[type=checkbox],input[type=radio]{padding:0}
45 button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}
46 textarea{overflow:auto;vertical-align:top}
47 table{border-collapse:collapse;border-spacing:0}
48 *,::before,::after{box-sizing:border-box}
49 html,body{font-size:100%}
50 body{background:#fff;color:rgba(0,0,0,.8);padding:0;margin:0;font-family:"Noto Serif","DejaVu Serif",serif;line-height:1;position:relative;cursor:auto;-moz-tab-size:4;-o-tab-size:4;tab-size:4;word-wrap:anywhere;-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased}
51 a:hover{cursor:pointer}
52 img,object,embed{max-width:100%;height:auto}
53 object,embed{height:100%}
54 img{-ms-interpolation-mode:bicubic}
55 .left{float:left!important}
56 .right{float:right!important}
57 .text-left{text-align:left!important}
58 .text-right{text-align:right!important}
59 .text-center{text-align:center!important}
60 .text-justify{text-align:justify!important}
61 .hide{display:none}
62 img,object,svg{display:inline-block;vertical-align:middle}
63 textarea{height:auto;min-height:50px}
64 select{width:100%}
65 .subheader,.admonitionblock td.content>.title,.audioblock>.title,.exampleblock>.title,.imageblock>.title,.listingblock>.title,.literalblock>.title,.stemblock>.title,.openblock>.title,.paragraph>.title,.quoteblock>.title,table.tableblock>.title,.verseblock>.title,.videoblock>.title,.dlist>.title,.olist>.title,.ulist>.title,.qlist>.title,.hdlist>.title{line-height:1.45;color:#7a2518;font-weight:400;margin-top:0;margin-bottom:.25em}
66 div,dl,dt,dd,ul,ol,li,h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6,pre,form,p,blockquote,th,td{margin:0;padding:0}
67 a{color:#2156a5;text-decoration:underline;line-height:inherit}
68 a:hover,a:focus{color:#1d4b8f}
69 a img{border:0}
70 p{line-height:1.6;margin-bottom:1.25em;text-rendering:optimizeLegibility}
71 p aside{font-size:.875em;line-height:1.35;font-style:italic}
72 h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{font-family:"Open Sans","DejaVu Sans",sans-serif;font-weight:300;font-style:normal;color:#ba3925;text-rendering:optimizeLegibility;margin-top:1em;margin-bottom:.5em;line-height:1.0125em}
73 h1 small,h2 small,h3 small,#toctitle small,.sidebarblock>.content>.title small,h4 small,h5 small,h6 small{font-size:60%;color:#e99b8f;line-height:0}
74 h1{font-size:2.125em}
75 h2{font-size:1.6875em}
76 h3,#toctitle,.sidebarblock>.content>.title{font-size:1.375em}
77 h4,h5{font-size:1.125em}
78 h6{font-size:1em}
79 hr{border:solid #dddddf;border-width:1px 0 0;clear:both;margin:1.25em 0 1.1875em}
80 em,i{font-style:italic;line-height:inherit}
81 strong,b{font-weight:bold;line-height:inherit}
82 small{font-size:60%;line-height:inherit}
83 code{font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;font-weight:400;color:rgba(0,0,0,.9)}
84 ul,ol,dl{line-height:1.6;margin-bottom:1.25em;list-style-position:outside;font-family:inherit}
85 ul,ol{margin-left:1.5em}
86 ul li ul,ul li ol{margin-left:1.25em;margin-bottom:0}
87 ul.circle{list-style-type:circle}
88 ul.disc{list-style-type:disc}
89 ul.square{list-style-type:square}
90 ul.circle ul:not([class]),ul.disc ul:not([class]),ul.square ul:not([class]){list-style:inherit}
91 ol li ul,ol li ol{margin-left:1.25em;margin-bottom:0}
92 dl dt{margin-bottom:.3125em;font-weight:bold}
93 dl dd{margin-bottom:1.25em}
94 blockquote{margin:0 0 1.25em;padding:.5625em 1.25em 0 1.1875em;border-left:1px solid #ddd}
95 blockquote,blockquote p{line-height:1.6;color:rgba(0,0,0,.85)}
96 @media screen and (min-width:768px){h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{line-height:1.2}
97 h1{font-size:2.75em}
98 h2{font-size:2.3125em}
99 h3,#toctitle,.sidebarblock>.content>.title{font-size:1.6875em}
100 h4{font-size:1.4375em}}
101 table{background:#fff;margin-bottom:1.25em;border:1px solid #dedede;word-wrap:normal}
102 table thead,table tfoot{background:#f7f8f7}
103 table thead tr th,table thead tr td,table tfoot tr th,table tfoot tr td{padding:.5em .625em .625em;font-size:inherit;color:rgba(0,0,0,.8);text-align:left}
104 table tr th,table tr td{padding:.5625em .625em;font-size:inherit;color:rgba(0,0,0,.8)}
105 table tr.even,table tr.alt{background:#f8f8f7}
106 table thead tr th,table tfoot tr th,table tbody tr td,table tr td,table tfoot tr td{line-height:1.6}
107 h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{line-height:1.2;word-spacing:-.05em}
108 h1 strong,h2 strong,h3 strong,#toctitle strong,.sidebarblock>.content>.title strong,h4 strong,h5 strong,h6 strong{font-weight:400}
109 .center{margin-left:auto;margin-right:auto}
110 .stretch{width:100%}
111 .clearfix::before,.clearfix::after,.float-group::before,.float-group::after{content:" ";display:table}
112 .clearfix::after,.float-group::after{clear:both}
113 :not(pre).nobreak{word-wrap:normal}
114 :not(pre).nowrap{white-space:nowrap}
115 :not(pre).pre-wrap{white-space:pre-wrap}
116 :not(pre):not([class^=L])>code{font-size:.9375em;font-style:normal!important;letter-spacing:0;padding:.1em .5ex;word-spacing:-.15em;background:#f7f7f8;border-radius:4px;line-height:1.45;text-rendering:optimizeSpeed}
117 pre{color:rgba(0,0,0,.9);font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;line-height:1.45;text-rendering:optimizeSpeed}
118 pre code,pre pre{color:inherit;font-size:inherit;line-height:inherit}
119 pre>code{display:block}
120 pre.nowrap,pre.nowrap pre{white-space:pre;word-wrap:normal}
121 em em{font-style:normal}
122 strong strong{font-weight:400}
123 .keyseq{color:rgba(51,51,51,.8)}
124 kbd{font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;display:inline-block;color:rgba(0,0,0,.8);font-size:.65em;line-height:1.45;background:#f7f7f7;border:1px solid #ccc;border-radius:3px;box-shadow:0 1px 0 rgba(0,0,0,.2),inset 0 0 0 .1em #fff;margin:0 .15em;padding:.2em .5em;vertical-align:middle;position:relative;top:-.1em;white-space:nowrap}
125 .keyseq kbd:first-child{margin-left:0}
126 .keyseq kbd:last-child{margin-right:0}
127 .menuseq,.menuref{color:#000}
128 .menuseq b:not(.caret),.menuref{font-weight:inherit}
129 .menuseq{word-spacing:-.02em}
130 .menuseq b.caret{font-size:1.25em;line-height:.8}
131 .menuseq i.caret{font-weight:bold;text-align:center;width:.45em}
132 b.button::before,b.button::after{position:relative;top:-1px;font-weight:400}
133 b.button::before{content:"[";padding:0 3px 0 2px}
134 b.button::after{content:"]";padding:0 2px 0 3px}
135 p a>code:hover{color:rgba(0,0,0,.9)}
136 #header,#content,#footnotes,#footer{width:100%;margin:0 auto;max-width:62.5em;*zoom:1;position:relative;padding-left:.9375em;padding-right:.9375em}
137 #header::before,#header::after,#content::before,#content::after,#footnotes::before,#footnotes::after,#footer::before,#footer::after{content:" ";display:table}
138 #header::after,#content::after,#footnotes::after,#footer::after{clear:both}
139 #content{margin-top:1.25em}
140 #content::before{content:none}
141 #header>h1:first-child{color:rgba(0,0,0,.85);margin-top:2.25rem;margin-bottom:0}
142 #header>h1:first-child+#toc{margin-top:8px;border-top:1px solid #dddddf}
143 #header>h1:only-child,body.toc2 #header>h1:nth-last-child(2){border-bottom:1px solid #dddddf;padding-bottom:8px}
144 #header .details{border-bottom:1px solid #dddddf;line-height:1.45;padding-top:.25em;padding-bottom:.25em;padding-left:.25em;color:rgba(0,0,0,.6);display:flex;flex-flow:row wrap}
145 #header .details span:first-child{margin-left:-.125em}
146 #header .details span.email a{color:rgba(0,0,0,.85)}
147 #header .details br{display:none}
148 #header .details br+span::before{content:"\00a0\2013\00a0"}
149 #header .details br+span.author::before{content:"\00a0\22c5\00a0";color:rgba(0,0,0,.85)}
150 #header .details br+span#revremark::before{content:"\00a0|\00a0"}
151 #header #revnumber{text-transform:capitalize}
152 #header #revnumber::after{content:"\00a0"}
153 #content>h1:first-child:not([class]){color:rgba(0,0,0,.85);border-bottom:1px solid #dddddf;padding-bottom:8px;margin-top:0;padding-top:1rem;margin-bottom:1.25rem}
154 #toc{border-bottom:1px solid #e7e7e9;padding-bottom:.5em}
155 #toc>ul{margin-left:.125em}
156 #toc ul.sectlevel0>li>a{font-style:italic}
157 #toc ul.sectlevel0 ul.sectlevel1{margin:.5em 0}
158 #toc ul{font-family:"Open Sans","DejaVu Sans",sans-serif;list-style-type:none}
159 #toc li{line-height:1.3334;margin-top:.3334em}
160 #toc a{text-decoration:none}
161 #toc a:active{text-decoration:underline}
162 #toctitle{color:#7a2518;font-size:1.2em}
163 @media screen and (min-width:768px){#toctitle{font-size:1.375em}
164 body.toc2{padding-left:15em;padding-right:0}
165 #toc.toc2{margin-top:0!important;background:#f8f8f7;position:fixed;width:15em;left:0;top:0;border-right:1px solid #e7e7e9;border-top-width:0!important;border-bottom-width:0!important;z-index:1000;padding:1.25em 1em;height:100%;overflow:auto}
166 #toc.toc2 #toctitle{margin-top:0;margin-bottom:.8rem;font-size:1.2em}
167 #toc.toc2>ul{font-size:.9em;margin-bottom:0}
168 #toc.toc2 ul ul{margin-left:0;padding-left:1em}
169 #toc.toc2 ul.sectlevel0 ul.sectlevel1{padding-left:0;margin-top:.5em;margin-bottom:.5em}
170 body.toc2.toc-right{padding-left:0;padding-right:15em}
171 body.toc2.toc-right #toc.toc2{border-right-width:0;border-left:1px solid #e7e7e9;left:auto;right:0}}
172 @media screen and (min-width:1280px){body.toc2{padding-left:20em;padding-right:0}
173 #toc.toc2{width:20em}
174 #toc.toc2 #toctitle{font-size:1.375em}
175 #toc.toc2>ul{font-size:.95em}
176 #toc.toc2 ul ul{padding-left:1.25em}
177 body.toc2.toc-right{padding-left:0;padding-right:20em}}
178 #content #toc{border:1px solid #e0e0dc;margin-bottom:1.25em;padding:1.25em;background:#f8f8f7;border-radius:4px}
179 #content #toc>:first-child{margin-top:0}
180 #content #toc>:last-child{margin-bottom:0}
181 #footer{max-width:none;background:rgba(0,0,0,.8);padding:1.25em}
182 #footer-text{color:hsla(0,0%,100%,.8);line-height:1.44}
183 #content{margin-bottom:.625em}
184 .sect1{padding-bottom:.625em}
185 @media screen and (min-width:768px){#content{margin-bottom:1.25em}
186 .sect1{padding-bottom:1.25em}}
187 .sect1:last-child{padding-bottom:0}
188 .sect1+.sect1{border-top:1px solid #e7e7e9}
189 #content h1>a.anchor,h2>a.anchor,h3>a.anchor,#toctitle>a.anchor,.sidebarblock>.content>.title>a.anchor,h4>a.anchor,h5>a.anchor,h6>a.anchor{position:absolute;z-index:1001;width:1.5ex;margin-left:-1.5ex;display:block;text-decoration:none!important;visibility:hidden;text-align:center;font-weight:400}
190 #content h1>a.anchor::before,h2>a.anchor::before,h3>a.anchor::before,#toctitle>a.anchor::before,.sidebarblock>.content>.title>a.anchor::before,h4>a.anchor::before,h5>a.anchor::before,h6>a.anchor::before{content:"\00A7";font-size:.85em;display:block;padding-top:.1em}
191 #content h1:hover>a.anchor,#content h1>a.anchor:hover,h2:hover>a.anchor,h2>a.anchor:hover,h3:hover>a.anchor,#toctitle:hover>a.anchor,.sidebarblock>.content>.title:hover>a.anchor,h3>a.anchor:hover,#toctitle>a.anchor:hover,.sidebarblock>.content>.title>a.anchor:hover,h4:hover>a.anchor,h4>a.anchor:hover,h5:hover>a.anchor,h5>a.anchor:hover,h6:hover>a.anchor,h6>a.anchor:hover{visibility:visible}
192 #content h1>a.link,h2>a.link,h3>a.link,#toctitle>a.link,.sidebarblock>.content>.title>a.link,h4>a.link,h5>a.link,h6>a.link{color:#ba3925;text-decoration:none}
193 #content h1>a.link:hover,h2>a.link:hover,h3>a.link:hover,#toctitle>a.link:hover,.sidebarblock>.content>.title>a.link:hover,h4>a.link:hover,h5>a.link:hover,h6>a.link:hover{color:#a53221}
194 details,.audioblock,.imageblock,.literalblock,.listingblock,.stemblock,.videoblock{margin-bottom:1.25em}
195 details{margin-left:1.25rem}
196 details>summary{cursor:pointer;display:block;position:relative;line-height:1.6;margin-bottom:.625rem;outline:none;-webkit-tap-highlight-color:transparent}
197 details>summary::-webkit-details-marker{display:none}
198 details>summary::before{content:"";border:solid transparent;border-left:solid;border-width:.3em 0 .3em .5em;position:absolute;top:.5em;left:-1.25rem;transform:translateX(15%)}
199 details[open]>summary::before{border:solid transparent;border-top:solid;border-width:.5em .3em 0;transform:translateY(15%)}
200 details>summary::after{content:"";width:1.25rem;height:1em;position:absolute;top:.3em;left:-1.25rem}
201 .admonitionblock td.content>.title,.audioblock>.title,.exampleblock>.title,.imageblock>.title,.listingblock>.title,.literalblock>.title,.stemblock>.title,.openblock>.title,.paragraph>.title,.quoteblock>.title,table.tableblock>.title,.verseblock>.title,.videoblock>.title,.dlist>.title,.olist>.title,.ulist>.title,.qlist>.title,.hdlist>.title{text-rendering:optimizeLegibility;text-align:left;font-family:"Noto Serif","DejaVu Serif",serif;font-size:1rem;font-style:italic}
202 table.tableblock.fit-content>caption.title{white-space:nowrap;width:0}
203 .paragraph.lead>p,#preamble>.sectionbody>[class=paragraph]:first-of-type p{font-size:1.21875em;line-height:1.6;color:rgba(0,0,0,.85)}
204 .admonitionblock>table{border-collapse:separate;border:0;background:none;width:100%}
205 .admonitionblock>table td.icon{text-align:center;width:80px}
206 .admonitionblock>table td.icon img{max-width:none}
207 .admonitionblock>table td.icon .title{font-weight:bold;font-family:"Open Sans","DejaVu Sans",sans-serif;text-transform:uppercase}
208 .admonitionblock>table td.content{padding-left:1.125em;padding-right:1.25em;border-left:1px solid #dddddf;color:rgba(0,0,0,.6);word-wrap:anywhere}
209 .admonitionblock>table td.content>:last-child>:last-child{margin-bottom:0}
210 .exampleblock>.content{border:1px solid #e6e6e6;margin-bottom:1.25em;padding:1.25em;background:#fff;border-radius:4px}
211 .sidebarblock{border:1px solid #dbdbd6;margin-bottom:1.25em;padding:1.25em;background:#f3f3f2;border-radius:4px}
212 .sidebarblock>.content>.title{color:#7a2518;margin-top:0;text-align:center}
213 .exampleblock>.content>:first-child,.sidebarblock>.content>:first-child{margin-top:0}
214 .exampleblock>.content>:last-child,.exampleblock>.content>:last-child>:last-child,.exampleblock>.content .olist>ol>li:last-child>:last-child,.exampleblock>.content .ulist>ul>li:last-child>:last-child,.exampleblock>.content .qlist>ol>li:last-child>:last-child,.sidebarblock>.content>:last-child,.sidebarblock>.content>:last-child>:last-child,.sidebarblock>.content .olist>ol>li:last-child>:last-child,.sidebarblock>.content .ulist>ul>li:last-child>:last-child,.sidebarblock>.content .qlist>ol>li:last-child>:last-child{margin-bottom:0}
215 .literalblock pre,.listingblock>.content>pre{border-radius:4px;overflow-x:auto;padding:1em;font-size:.8125em}
216 @media screen and (min-width:768px){.literalblock pre,.listingblock>.content>pre{font-size:.90625em}}
217 @media screen and (min-width:1280px){.literalblock pre,.listingblock>.content>pre{font-size:1em}}
218 .literalblock pre,.listingblock>.content>pre:not(.highlight),.listingblock>.content>pre[class=highlight],.listingblock>.content>pre[class^="highlight "]{background:#f7f7f8}
219 .literalblock.output pre{color:#f7f7f8;background:rgba(0,0,0,.9)}
220 .listingblock>.content{position:relative}
221 .listingblock code[data-lang]::before{display:none;content:attr(data-lang);position:absolute;font-size:.75em;top:.425rem;right:.5rem;line-height:1;text-transform:uppercase;color:inherit;opacity:.5}
222 .listingblock:hover code[data-lang]::before{display:block}
223 .listingblock.terminal pre .command::before{content:attr(data-prompt);padding-right:.5em;color:inherit;opacity:.5}
224 .listingblock.terminal pre .command:not([data-prompt])::before{content:"$"}
225 .listingblock pre.highlightjs{padding:0}
226 .listingblock pre.highlightjs>code{padding:1em;border-radius:4px}
227 .listingblock pre.prettyprint{border-width:0}
228 .prettyprint{background:#f7f7f8}
229 pre.prettyprint .linenums{line-height:1.45;margin-left:2em}
230 pre.prettyprint li{background:none;list-style-type:inherit;padding-left:0}
231 pre.prettyprint li code[data-lang]::before{opacity:1}
232 pre.prettyprint li:not(:first-child) code[data-lang]::before{display:none}
233 table.linenotable{border-collapse:separate;border:0;margin-bottom:0;background:none}
234 table.linenotable td[class]{color:inherit;vertical-align:top;padding:0;line-height:inherit;white-space:normal}
235 table.linenotable td.code{padding-left:.75em}
236 table.linenotable td.linenos,pre.pygments .linenos{border-right:1px solid;opacity:.35;padding-right:.5em;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}
237 pre.pygments span.linenos{display:inline-block;margin-right:.75em}
238 .quoteblock{margin:0 1em 1.25em 1.5em;display:table}
239 .quoteblock:not(.excerpt)>.title{margin-left:-1.5em;margin-bottom:.75em}
240 .quoteblock blockquote,.quoteblock p{color:rgba(0,0,0,.85);font-size:1.15rem;line-height:1.75;word-spacing:.1em;letter-spacing:0;font-style:italic;text-align:justify}
241 .quoteblock blockquote{margin:0;padding:0;border:0}
242 .quoteblock blockquote::before{content:"\201c";float:left;font-size:2.75em;font-weight:bold;line-height:.6em;margin-left:-.6em;color:#7a2518;text-shadow:0 1px 2px rgba(0,0,0,.1)}
243 .quoteblock blockquote>.paragraph:last-child p{margin-bottom:0}
244 .quoteblock .attribution{margin-top:.75em;margin-right:.5ex;text-align:right}
245 .verseblock{margin:0 1em 1.25em}
246 .verseblock pre{font-family:"Open Sans","DejaVu Sans",sans-serif;font-size:1.15rem;color:rgba(0,0,0,.85);font-weight:300;text-rendering:optimizeLegibility}
247 .verseblock pre strong{font-weight:400}
248 .verseblock .attribution{margin-top:1.25rem;margin-left:.5ex}
249 .quoteblock .attribution,.verseblock .attribution{font-size:.9375em;line-height:1.45;font-style:italic}
250 .quoteblock .attribution br,.verseblock .attribution br{display:none}
251 .quoteblock .attribution cite,.verseblock .attribution cite{display:block;letter-spacing:-.025em;color:rgba(0,0,0,.6)}
252 .quoteblock.abstract blockquote::before,.quoteblock.excerpt blockquote::before,.quoteblock .quoteblock blockquote::before{display:none}
253 .quoteblock.abstract blockquote,.quoteblock.abstract p,.quoteblock.excerpt blockquote,.quoteblock.excerpt p,.quoteblock .quoteblock blockquote,.quoteblock .quoteblock p{line-height:1.6;word-spacing:0}
254 .quoteblock.abstract{margin:0 1em 1.25em;display:block}
255 .quoteblock.abstract>.title{margin:0 0 .375em;font-size:1.15em;text-align:center}
256 .quoteblock.excerpt>blockquote,.quoteblock .quoteblock{padding:0 0 .25em 1em;border-left:.25em solid #dddddf}
257 .quoteblock.excerpt,.quoteblock .quoteblock{margin-left:0}
258 .quoteblock.excerpt blockquote,.quoteblock.excerpt p,.quoteblock .quoteblock blockquote,.quoteblock .quoteblock p{color:inherit;font-size:1.0625rem}
259 .quoteblock.excerpt .attribution,.quoteblock .quoteblock .attribution{color:inherit;font-size:.85rem;text-align:left;margin-right:0}
260 p.tableblock:last-child{margin-bottom:0}
261 td.tableblock>.content{margin-bottom:1.25em;word-wrap:anywhere}
262 td.tableblock>.content>:last-child{margin-bottom:-1.25em}
263 table.tableblock,th.tableblock,td.tableblock{border:0 solid #dedede}
264 table.grid-all>*>tr>*{border-width:1px}
265 table.grid-cols>*>tr>*{border-width:0 1px}
266 table.grid-rows>*>tr>*{border-width:1px 0}
267 table.frame-all{border-width:1px}
268 table.frame-ends{border-width:1px 0}
269 table.frame-sides{border-width:0 1px}
270 table.frame-none>colgroup+*>:first-child>*,table.frame-sides>colgroup+*>:first-child>*{border-top-width:0}
271 table.frame-none>:last-child>:last-child>*,table.frame-sides>:last-child>:last-child>*{border-bottom-width:0}
272 table.frame-none>*>tr>:first-child,table.frame-ends>*>tr>:first-child{border-left-width:0}
273 table.frame-none>*>tr>:last-child,table.frame-ends>*>tr>:last-child{border-right-width:0}
274 table.stripes-all>*>tr,table.stripes-odd>*>tr:nth-of-type(odd),table.stripes-even>*>tr:nth-of-type(even),table.stripes-hover>*>tr:hover{background:#f8f8f7}
275 th.halign-left,td.halign-left{text-align:left}
276 th.halign-right,td.halign-right{text-align:right}
277 th.halign-center,td.halign-center{text-align:center}
278 th.valign-top,td.valign-top{vertical-align:top}
279 th.valign-bottom,td.valign-bottom{vertical-align:bottom}
280 th.valign-middle,td.valign-middle{vertical-align:middle}
281 table thead th,table tfoot th{font-weight:bold}
282 tbody tr th{background:#f7f8f7}
283 tbody tr th,tbody tr th p,tfoot tr th,tfoot tr th p{color:rgba(0,0,0,.8);font-weight:bold}
284 p.tableblock>code:only-child{background:none;padding:0}
285 p.tableblock{font-size:1em}
286 ol{margin-left:1.75em}
287 ul li ol{margin-left:1.5em}
288 dl dd{margin-left:1.125em}
289 dl dd:last-child,dl dd:last-child>:last-child{margin-bottom:0}
290 li p,ul dd,ol dd,.olist .olist,.ulist .ulist,.ulist .olist,.olist .ulist{margin-bottom:.625em}
291 ul.checklist,ul.none,ol.none,ul.no-bullet,ol.no-bullet,ol.unnumbered,ul.unstyled,ol.unstyled{list-style-type:none}
292 ul.no-bullet,ol.no-bullet,ol.unnumbered{margin-left:.625em}
293 ul.unstyled,ol.unstyled{margin-left:0}
294 li>p:empty:only-child::before{content:"";display:inline-block}
295 ul.checklist>li>p:first-child{margin-left:-1em}
296 ul.checklist>li>p:first-child>.fa-square-o:first-child,ul.checklist>li>p:first-child>.fa-check-square-o:first-child{width:1.25em;font-size:.8em;position:relative;bottom:.125em}
297 ul.checklist>li>p:first-child>input[type=checkbox]:first-child{margin-right:.25em}
298 ul.inline{display:flex;flex-flow:row wrap;list-style:none;margin:0 0 .625em -1.25em}
299 ul.inline>li{margin-left:1.25em}
300 .unstyled dl dt{font-weight:400;font-style:normal}
301 ol.arabic{list-style-type:decimal}
302 ol.decimal{list-style-type:decimal-leading-zero}
303 ol.loweralpha{list-style-type:lower-alpha}
304 ol.upperalpha{list-style-type:upper-alpha}
305 ol.lowerroman{list-style-type:lower-roman}
306 ol.upperroman{list-style-type:upper-roman}
307 ol.lowergreek{list-style-type:lower-greek}
308 .hdlist>table,.colist>table{border:0;background:none}
309 .hdlist>table>tbody>tr,.colist>table>tbody>tr{background:none}
310 td.hdlist1,td.hdlist2{vertical-align:top;padding:0 .625em}
311 td.hdlist1{font-weight:bold;padding-bottom:1.25em}
312 td.hdlist2{word-wrap:anywhere}
313 .literalblock+.colist,.listingblock+.colist{margin-top:-.5em}
314 .colist td:not([class]):first-child{padding:.4em .75em 0;line-height:1;vertical-align:top}
315 .colist td:not([class]):first-child img{max-width:none}
316 .colist td:not([class]):last-child{padding:.25em 0}
317 .thumb,.th{line-height:0;display:inline-block;border:4px solid #fff;box-shadow:0 0 0 1px #ddd}
318 .imageblock.left{margin:.25em .625em 1.25em 0}
319 .imageblock.right{margin:.25em 0 1.25em .625em}
320 .imageblock>.title{margin-bottom:0}
321 .imageblock.thumb,.imageblock.th{border-width:6px}
322 .imageblock.thumb>.title,.imageblock.th>.title{padding:0 .125em}
323 .image.left,.image.right{margin-top:.25em;margin-bottom:.25em;display:inline-block;line-height:0}
324 .image.left{margin-right:.625em}
325 .image.right{margin-left:.625em}
326 a.image{text-decoration:none;display:inline-block}
327 a.image object{pointer-events:none}
328 sup.footnote,sup.footnoteref{font-size:.875em;position:static;vertical-align:super}
329 sup.footnote a,sup.footnoteref a{text-decoration:none}
330 sup.footnote a:active,sup.footnoteref a:active{text-decoration:underline}
331 #footnotes{padding-top:.75em;padding-bottom:.75em;margin-bottom:.625em}
332 #footnotes hr{width:20%;min-width:6.25em;margin:-.25em 0 .75em;border-width:1px 0 0}
333 #footnotes .footnote{padding:0 .375em 0 .225em;line-height:1.3334;font-size:.875em;margin-left:1.2em;margin-bottom:.2em}
334 #footnotes .footnote a:first-of-type{font-weight:bold;text-decoration:none;margin-left:-1.05em}
335 #footnotes .footnote:last-of-type{margin-bottom:0}
336 #content #footnotes{margin-top:-.625em;margin-bottom:0;padding:.75em 0}
337 div.unbreakable{page-break-inside:avoid}
338 .big{font-size:larger}
339 .small{font-size:smaller}
340 .underline{text-decoration:underline}
341 .overline{text-decoration:overline}
342 .line-through{text-decoration:line-through}
343 .aqua{color:#00bfbf}
344 .aqua-background{background:#00fafa}
345 .black{color:#000}
346 .black-background{background:#000}
347 .blue{color:#0000bf}
348 .blue-background{background:#0000fa}
349 .fuchsia{color:#bf00bf}
350 .fuchsia-background{background:#fa00fa}
351 .gray{color:#606060}
352 .gray-background{background:#7d7d7d}
353 .green{color:#006000}
354 .green-background{background:#007d00}
355 .lime{color:#00bf00}
356 .lime-background{background:#00fa00}
357 .maroon{color:#600000}
358 .maroon-background{background:#7d0000}
359 .navy{color:#000060}
360 .navy-background{background:#00007d}
361 .olive{color:#606000}
362 .olive-background{background:#7d7d00}
363 .purple{color:#600060}
364 .purple-background{background:#7d007d}
365 .red{color:#bf0000}
366 .red-background{background:#fa0000}
367 .silver{color:#909090}
368 .silver-background{background:#bcbcbc}
369 .teal{color:#006060}
370 .teal-background{background:#007d7d}
371 .white{color:#bfbfbf}
372 .white-background{background:#fafafa}
373 .yellow{color:#bfbf00}
374 .yellow-background{background:#fafa00}
375 span.icon>.fa{cursor:default}
376 a span.icon>.fa{cursor:inherit}
377 .admonitionblock td.icon [class^="fa icon-"]{font-size:2.5em;text-shadow:1px 1px 2px rgba(0,0,0,.5);cursor:default}
378 .admonitionblock td.icon .icon-note::before{content:"\f05a";color:#19407c}
379 .admonitionblock td.icon .icon-tip::before{content:"\f0eb";text-shadow:1px 1px 2px rgba(155,155,0,.8);color:#111}
380 .admonitionblock td.icon .icon-warning::before{content:"\f071";color:#bf6900}
381 .admonitionblock td.icon .icon-caution::before{content:"\f06d";color:#bf3400}
382 .admonitionblock td.icon .icon-important::before{content:"\f06a";color:#bf0000}
383 .conum[data-value]{display:inline-block;color:#fff!important;background:rgba(0,0,0,.8);border-radius:50%;text-align:center;font-size:.75em;width:1.67em;height:1.67em;line-height:1.67em;font-family:"Open Sans","DejaVu Sans",sans-serif;font-style:normal;font-weight:bold}
384 .conum[data-value] *{color:#fff!important}
385 .conum[data-value]+b{display:none}
386 .conum[data-value]::after{content:attr(data-value)}
387 pre .conum[data-value]{position:relative;top:-.125em}
388 b.conum *{color:inherit!important}
389 .conum:not([data-value]):empty{display:none}
390 dt,th.tableblock,td.content,div.footnote{text-rendering:optimizeLegibility}
391 h1,h2,p,td.content,span.alt,summary{letter-spacing:-.01em}
392 p strong,td.content strong,div.footnote strong{letter-spacing:-.005em}
393 p,blockquote,dt,td.content,td.hdlist1,span.alt,summary{font-size:1.0625rem}
394 p{margin-bottom:1.25rem}
395 .sidebarblock p,.sidebarblock dt,.sidebarblock td.content,p.tableblock{font-size:1em}
396 .exampleblock>.content{background:#fffef7;border-color:#e0e0dc;box-shadow:0 1px 4px #e0e0dc}
397 .print-only{display:none!important}
398 @page{margin:1.25cm .75cm}
399 @media print{*{box-shadow:none!important;text-shadow:none!important}
400 html{font-size:80%}
401 a{color:inherit!important;text-decoration:underline!important}
402 a.bare,a[href^="#"],a[href^="mailto:"]{text-decoration:none!important}
403 a[href^="http:"]:not(.bare)::after,a[href^="https:"]:not(.bare)::after{content:"(" attr(href) ")";display:inline-block;font-size:.875em;padding-left:.25em}
404 abbr[title]{border-bottom:1px dotted}
405 abbr[title]::after{content:" (" attr(title) ")"}
406 pre,blockquote,tr,img,object,svg{page-break-inside:avoid}
407 thead{display:table-header-group}
408 svg{max-width:100%}
409 p,blockquote,dt,td.content{font-size:1em;orphans:3;widows:3}
410 h2,h3,#toctitle,.sidebarblock>.content>.title{page-break-after:avoid}
411 #header,#content,#footnotes,#footer{max-width:none}
412 #toc,.sidebarblock,.exampleblock>.content{background:none!important}
413 #toc{border-bottom:1px solid #dddddf!important;padding-bottom:0!important}
414 body.book #header{text-align:center}
415 body.book #header>h1:first-child{border:0!important;margin:2.5em 0 1em}
416 body.book #header .details{border:0!important;display:block;padding:0!important}
417 body.book #header .details span:first-child{margin-left:0!important}
418 body.book #header .details br{display:block}
419 body.book #header .details br+span::before{content:none!important}
420 body.book #toc{border:0!important;text-align:left!important;padding:0!important;margin:0!important}
421 body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-break-before:always}
422 .listingblock code[data-lang]::before{display:block}
423 #footer{padding:0 .9375em}
424 .hide-on-print{display:none!important}
425 .print-only{display:block!important}
426 .hide-for-print{display:none!important}
427 .show-for-print{display:inherit!important}}
428 @media amzn-kf8,print{#header>h1:first-child{margin-top:1.25rem}
429 .sect1{padding:0!important}
430 .sect1+.sect1{border:0}
431 #footer{background:none}
432 #footer-text{color:rgba(0,0,0,.6);font-size:.9em}}
433 @media amzn-kf8{#header,#content,#footnotes,#footer{padding:0}}
434 </style>
435 <style>
436 pre>code {
437 display: inline;
439 </style>
440 </head>
441 <body class="article">
442 <div id="header">
443 <h1>My First Contribution to the Git Project</h1>
444 <div class="details">
445 <span id="revdate">2024-09-10</span>
446 </div>
447 </div>
448 <div id="content">
449 <div class="sect1">
450 <h2 id="summary"><a class="anchor" href="#summary"></a>Summary</h2>
451 <div class="sectionbody">
452 <div class="paragraph">
453 <p>This is a tutorial demonstrating the end-to-end workflow of creating a change to
454 the Git tree, sending it for review, and making changes based on comments.</p>
455 </div>
456 <div class="sect2">
457 <h3 id="prerequisites"><a class="anchor" href="#prerequisites"></a>Prerequisites</h3>
458 <div class="paragraph">
459 <p>This tutorial assumes you&#8217;re already fairly familiar with using Git to manage
460 source code. The Git workflow steps will largely remain unexplained.</p>
461 </div>
462 </div>
463 <div class="sect2">
464 <h3 id="related-reading"><a class="anchor" href="#related-reading"></a>Related Reading</h3>
465 <div class="paragraph">
466 <p>This tutorial aims to summarize the following documents, but the reader may find
467 useful additional context:</p>
468 </div>
469 <div class="ulist">
470 <ul>
471 <li>
472 <p><code>Documentation/SubmittingPatches</code></p>
473 </li>
474 <li>
475 <p><code>Documentation/howto/new-command.txt</code></p>
476 </li>
477 </ul>
478 </div>
479 </div>
480 <div class="sect2">
481 <h3 id="getting-help"><a class="anchor" href="#getting-help"></a>Getting Help</h3>
482 <div class="paragraph">
483 <p>If you get stuck, you can seek help in the following places.</p>
484 </div>
485 <div class="sect3">
486 <h4 id="_gitvger_kernel_org"><a class="anchor" href="#_gitvger_kernel_org"></a><a href="mailto:git@vger.kernel.org">git@vger.kernel.org</a></h4>
487 <div class="paragraph">
488 <p>This is the main Git project mailing list where code reviews, version
489 announcements, design discussions, and more take place. Those interested in
490 contributing are welcome to post questions here. The Git list requires
491 plain-text-only emails and prefers inline and bottom-posting when replying to
492 mail; you will be CC&#8217;d in all replies to you. Optionally, you can subscribe to
493 the list by sending an email to &lt;<a href="mailto:git+subscribe@vger.kernel.org">git+subscribe@vger.kernel.org</a>&gt;
494 (see <a href="https://subspace.kernel.org/subscribing.html" class="bare">https://subspace.kernel.org/subscribing.html</a> for details).
495 The <a href="https://lore.kernel.org/git">archive</a> of this mailing list is
496 available to view in a browser.</p>
497 </div>
498 </div>
499 <div class="sect3">
500 <h4 id="_git_mentoringgooglegroups_com"><a class="anchor" href="#_git_mentoringgooglegroups_com"></a><a href="https://groups.google.com/forum/#!forum/git-mentoring">git-mentoring@googlegroups.com</a></h4>
501 <div class="paragraph">
502 <p>This mailing list is targeted to new contributors and was created as a place to
503 post questions and receive answers outside of the public eye of the main list.
504 Veteran contributors who are especially interested in helping mentor newcomers
505 are present on the list. In order to avoid search indexers, group membership is
506 required to view messages; anyone can join and no approval is required.</p>
507 </div>
508 </div>
509 <div class="sect3">
510 <h4 id="_git_devel_on_libera_chat"><a class="anchor" href="#_git_devel_on_libera_chat"></a><a href="https://web.libera.chat/#git-devel">#git-devel</a> on Libera Chat</h4>
511 <div class="paragraph">
512 <p>This IRC channel is for conversations between Git contributors. If someone is
513 currently online and knows the answer to your question, you can receive help
514 in real time. Otherwise, you can read the
515 <a href="https://colabti.org/irclogger/irclogger_logs/git-devel">scrollback</a> to see
516 whether someone answered you. IRC does not allow offline private messaging, so
517 if you try to private message someone and then log out of IRC, they cannot
518 respond to you. It&#8217;s better to ask your questions in the channel so that you
519 can be answered if you disconnect and so that others can learn from the
520 conversation.</p>
521 </div>
522 </div>
523 </div>
524 </div>
525 </div>
526 <div class="sect1">
527 <h2 id="getting-started"><a class="anchor" href="#getting-started"></a>Getting Started</h2>
528 <div class="sectionbody">
529 <div class="sect2">
530 <h3 id="cloning"><a class="anchor" href="#cloning"></a>Clone the Git Repository</h3>
531 <div class="paragraph">
532 <p>Git is mirrored in a number of locations. Clone the repository from one of them;
533 <a href="https://git-scm.com/downloads" class="bare">https://git-scm.com/downloads</a> suggests one of the best places to clone from is
534 the mirror on GitHub.</p>
535 </div>
536 <div class="listingblock">
537 <div class="content">
538 <pre>$ git clone https://github.com/git/git git
539 $ cd git</pre>
540 </div>
541 </div>
542 </div>
543 <div class="sect2">
544 <h3 id="dependencies"><a class="anchor" href="#dependencies"></a>Installing Dependencies</h3>
545 <div class="paragraph">
546 <p>To build Git from source, you need to have a handful of dependencies installed
547 on your system. For a hint of what&#8217;s needed, you can take a look at
548 <code>INSTALL</code>, paying close attention to the section about Git&#8217;s dependencies on
549 external programs and libraries. That document mentions a way to "test-drive"
550 our freshly built Git without installing; that&#8217;s the method we&#8217;ll be using in
551 this tutorial.</p>
552 </div>
553 <div class="paragraph">
554 <p>Make sure that your environment has everything you need by building your brand
555 new clone of Git from the above step:</p>
556 </div>
557 <div class="listingblock">
558 <div class="content">
559 <pre>$ make</pre>
560 </div>
561 </div>
562 <div class="admonitionblock note">
563 <table>
564 <tr>
565 <td class="icon">
566 <div class="title">Note</div>
567 </td>
568 <td class="content">
569 The Git build is parallelizable. <code>-j#</code> is not included above but you can
570 use it as you prefer, here and elsewhere.
571 </td>
572 </tr>
573 </table>
574 </div>
575 </div>
576 <div class="sect2">
577 <h3 id="identify-problem"><a class="anchor" href="#identify-problem"></a>Identify Problem to Solve</h3>
578 <div class="paragraph">
579 <p>In this tutorial, we will add a new command, <code>git psuh</code>, short for &#8220;Pony Saying
580 &#8216;Um, Hello&#8221;&#8217; - a feature which has gone unimplemented despite a high frequency
581 of invocation during users' typical daily workflow.</p>
582 </div>
583 <div class="paragraph">
584 <p>(We&#8217;ve seen some other effort in this space with the implementation of popular
585 commands such as <code>sl</code>.)</p>
586 </div>
587 </div>
588 <div class="sect2">
589 <h3 id="setup-workspace"><a class="anchor" href="#setup-workspace"></a>Set Up Your Workspace</h3>
590 <div class="paragraph">
591 <p>Let&#8217;s start by making a development branch to work on our changes. Per
592 <code>Documentation/SubmittingPatches</code>, since a brand new command is a new feature,
593 it&#8217;s fine to base your work on <code>master</code>. However, in the future for bugfixes,
594 etc., you should check that document and base it on the appropriate branch.</p>
595 </div>
596 <div class="paragraph">
597 <p>For the purposes of this document, we will base all our work on the <code>master</code>
598 branch of the upstream project. Create the <code>psuh</code> branch you will use for
599 development like so:</p>
600 </div>
601 <div class="listingblock">
602 <div class="content">
603 <pre>$ git checkout -b psuh origin/master</pre>
604 </div>
605 </div>
606 <div class="paragraph">
607 <p>We&#8217;ll make a number of commits here in order to demonstrate how to send a topic
608 with multiple patches up for review simultaneously.</p>
609 </div>
610 </div>
611 </div>
612 </div>
613 <div class="sect1">
614 <h2 id="code-it-up"><a class="anchor" href="#code-it-up"></a>Code It Up!</h2>
615 <div class="sectionbody">
616 <div class="admonitionblock note">
617 <table>
618 <tr>
619 <td class="icon">
620 <div class="title">Note</div>
621 </td>
622 <td class="content">
623 A reference implementation can be found at
624 <a href="https://github.com/nasamuffin/git/tree/psuh" class="bare">https://github.com/nasamuffin/git/tree/psuh</a>.
625 </td>
626 </tr>
627 </table>
628 </div>
629 <div class="sect2">
630 <h3 id="add-new-command"><a class="anchor" href="#add-new-command"></a>Adding a New Command</h3>
631 <div class="paragraph">
632 <p>Lots of the subcommands are written as builtins, which means they are
633 implemented in C and compiled into the main <code>git</code> executable. Implementing the
634 very simple <code>psuh</code> command as a built-in will demonstrate the structure of the
635 codebase, the internal API, and the process of working together as a contributor
636 with the reviewers and maintainer to integrate this change into the system.</p>
637 </div>
638 <div class="paragraph">
639 <p>Built-in subcommands are typically implemented in a function named "cmd_"
640 followed by the name of the subcommand, in a source file named after the
641 subcommand and contained within <code>builtin/</code>. So it makes sense to implement your
642 command in <code>builtin/psuh.c</code>. Create that file, and within it, write the entry
643 point for your command in a function matching the style and signature:</p>
644 </div>
645 <div class="listingblock">
646 <div class="content">
647 <pre>int cmd_psuh(int argc, const char **argv, const char *prefix)</pre>
648 </div>
649 </div>
650 <div class="paragraph">
651 <p>We&#8217;ll also need to add the declaration of psuh; open up <code>builtin.h</code>, find the
652 declaration for <code>cmd_pull</code>, and add a new line for <code>psuh</code> immediately before it,
653 in order to keep the declarations alphabetically sorted:</p>
654 </div>
655 <div class="listingblock">
656 <div class="content">
657 <pre>int cmd_psuh(int argc, const char **argv, const char *prefix);</pre>
658 </div>
659 </div>
660 <div class="paragraph">
661 <p>Be sure to <code>#include "builtin.h"</code> in your <code>psuh.c</code>. You&#8217;ll also need to
662 <code>#include "gettext.h"</code> to use functions related to printing output text.</p>
663 </div>
664 <div class="paragraph">
665 <p>Go ahead and add some throwaway printf to the <code>cmd_psuh</code> function. This is a
666 decent starting point as we can now add build rules and register the command.</p>
667 </div>
668 <div class="admonitionblock note">
669 <table>
670 <tr>
671 <td class="icon">
672 <div class="title">Note</div>
673 </td>
674 <td class="content">
675 Your throwaway text, as well as much of the text you will be adding over
676 the course of this tutorial, is user-facing. That means it needs to be
677 localizable. Take a look at <code>po/README</code> under "Marking strings for translation".
678 Throughout the tutorial, we will mark strings for translation as necessary; you
679 should also do so when writing your user-facing commands in the future.
680 </td>
681 </tr>
682 </table>
683 </div>
684 <div class="listingblock">
685 <div class="content">
686 <pre>int cmd_psuh(int argc, const char **argv, const char *prefix)
688 printf(_("Pony saying hello goes here.\n"));
689 return 0;
690 }</pre>
691 </div>
692 </div>
693 <div class="paragraph">
694 <p>Let&#8217;s try to build it. Open <code>Makefile</code>, find where <code>builtin/pull.o</code> is added
695 to <code>BUILTIN_OBJS</code>, and add <code>builtin/psuh.o</code> in the same way next to it in
696 alphabetical order. Once you&#8217;ve done so, move to the top-level directory and
697 build simply with <code>make</code>. Also add the <code>DEVELOPER=1</code> variable to turn on
698 some additional warnings:</p>
699 </div>
700 <div class="listingblock">
701 <div class="content">
702 <pre>$ echo DEVELOPER=1 &gt;config.mak
703 $ make</pre>
704 </div>
705 </div>
706 <div class="admonitionblock note">
707 <table>
708 <tr>
709 <td class="icon">
710 <div class="title">Note</div>
711 </td>
712 <td class="content">
713 When you are developing the Git project, it&#8217;s preferred that you use the
714 <code>DEVELOPER</code> flag; if there&#8217;s some reason it doesn&#8217;t work for you, you can turn
715 it off, but it&#8217;s a good idea to mention the problem to the mailing list.
716 </td>
717 </tr>
718 </table>
719 </div>
720 <div class="paragraph">
721 <p>Great, now your new command builds happily on its own. But nobody invokes it.
722 Let&#8217;s change that.</p>
723 </div>
724 <div class="paragraph">
725 <p>The list of commands lives in <code>git.c</code>. We can register a new command by adding
726 a <code>cmd_struct</code> to the <code>commands[]</code> array. <code>struct cmd_struct</code> takes a string
727 with the command name, a function pointer to the command implementation, and a
728 setup option flag. For now, let&#8217;s keep mimicking <code>push</code>. Find the line where
729 <code>cmd_push</code> is registered, copy it, and modify it for <code>cmd_psuh</code>, placing the new
730 line in alphabetical order (immediately before <code>cmd_pull</code>).</p>
731 </div>
732 <div class="paragraph">
733 <p>The options are documented in <code>builtin.h</code> under "Adding a new built-in." Since
734 we hope to print some data about the user&#8217;s current workspace context later,
735 we need a Git directory, so choose <code>RUN_SETUP</code> as your only option.</p>
736 </div>
737 <div class="paragraph">
738 <p>Go ahead and build again. You should see a clean build, so let&#8217;s kick the tires
739 and see if it works. There&#8217;s a binary you can use to test with in the
740 <code>bin-wrappers</code> directory.</p>
741 </div>
742 <div class="listingblock">
743 <div class="content">
744 <pre>$ ./bin-wrappers/git psuh</pre>
745 </div>
746 </div>
747 <div class="paragraph">
748 <p>Check it out! You&#8217;ve got a command! Nice work! Let&#8217;s commit this.</p>
749 </div>
750 <div class="paragraph">
751 <p><code>git status</code> reveals modified <code>Makefile</code>, <code>builtin.h</code>, and <code>git.c</code> as well as
752 untracked <code>builtin/psuh.c</code> and <code>git-psuh</code>. First, let&#8217;s take care of the binary,
753 which should be ignored. Open <code>.gitignore</code> in your editor, find <code>/git-pull</code>, and
754 add an entry for your new command in alphabetical order:</p>
755 </div>
756 <div class="listingblock">
757 <div class="content">
758 <pre>...
759 /git-prune-packed
760 /git-psuh
761 /git-pull
762 /git-push
763 /git-quiltimport
764 /git-range-diff
765 ...</pre>
766 </div>
767 </div>
768 <div class="paragraph">
769 <p>Checking <code>git status</code> again should show that <code>git-psuh</code> has been removed from
770 the untracked list and <code>.gitignore</code> has been added to the modified list. Now we
771 can stage and commit:</p>
772 </div>
773 <div class="listingblock">
774 <div class="content">
775 <pre>$ git add Makefile builtin.h builtin/psuh.c git.c .gitignore
776 $ git commit -s</pre>
777 </div>
778 </div>
779 <div class="paragraph">
780 <p>You will be presented with your editor in order to write a commit message. Start
781 the commit with a 50-column or less subject line, including the name of the
782 component you&#8217;re working on, followed by a blank line (always required) and then
783 the body of your commit message, which should provide the bulk of the context.
784 Remember to be explicit and provide the "Why" of your change, especially if it
785 couldn&#8217;t easily be understood from your diff. When editing your commit message,
786 don&#8217;t remove the <code>Signed-off-by</code> trailer which was added by <code>-s</code> above.</p>
787 </div>
788 <div class="listingblock">
789 <div class="content">
790 <pre>psuh: add a built-in by popular demand
792 Internal metrics indicate this is a command many users expect to be
793 present. So here's an implementation to help drive customer
794 satisfaction and engagement: a pony which doubtfully greets the user,
795 or, a Pony Saying "Um, Hello" (PSUH).
797 This commit message is intentionally formatted to 72 columns per line,
798 starts with a single line as "commit message subject" that is written as
799 if to command the codebase to do something (add this, teach a command
800 that). The body of the message is designed to add information about the
801 commit that is not readily deduced from reading the associated diff,
802 such as answering the question "why?".
804 Signed-off-by: A U Thor &lt;author@example.com&gt;</pre>
805 </div>
806 </div>
807 <div class="paragraph">
808 <p>Go ahead and inspect your new commit with <code>git show</code>. "psuh:" indicates you
809 have modified mainly the <code>psuh</code> command. The subject line gives readers an idea
810 of what you&#8217;ve changed. The sign-off line (<code>-s</code>) indicates that you agree to
811 the Developer&#8217;s Certificate of Origin 1.1 (see the
812 <code>Documentation/SubmittingPatches</code> [[dco]] header).</p>
813 </div>
814 <div class="paragraph">
815 <p>For the remainder of the tutorial, the subject line only will be listed for the
816 sake of brevity. However, fully-fleshed example commit messages are available
817 on the reference implementation linked at the top of this document.</p>
818 </div>
819 </div>
820 <div class="sect2">
821 <h3 id="implementation"><a class="anchor" href="#implementation"></a>Implementation</h3>
822 <div class="paragraph">
823 <p>It&#8217;s probably useful to do at least something besides printing out a string.
824 Let&#8217;s start by having a look at everything we get.</p>
825 </div>
826 <div class="paragraph">
827 <p>Modify your <code>cmd_psuh</code> implementation to dump the args you&#8217;re passed, keeping
828 existing <code>printf()</code> calls in place:</p>
829 </div>
830 <div class="listingblock">
831 <div class="content">
832 <pre> int i;
836 printf(Q_("Your args (there is %d):\n",
837 "Your args (there are %d):\n",
838 argc),
839 argc);
840 for (i = 0; i &lt; argc; i++)
841 printf("%d: %s\n", i, argv[i]);
843 printf(_("Your current working directory:\n&lt;top-level&gt;%s%s\n"),
844 prefix ? "/" : "", prefix ? prefix : "");</pre>
845 </div>
846 </div>
847 <div class="paragraph">
848 <p>Build and try it. As you may expect, there&#8217;s pretty much just whatever we give
849 on the command line, including the name of our command. (If <code>prefix</code> is empty
850 for you, try <code>cd Documentation/ &amp;&amp; ../bin-wrappers/git psuh</code>). That&#8217;s not so
851 helpful. So what other context can we get?</p>
852 </div>
853 <div class="paragraph">
854 <p>Add a line to <code>#include "config.h"</code>. Then, add the following bits to the
855 function body:</p>
856 </div>
857 <div class="listingblock">
858 <div class="content">
859 <pre> const char *cfg_name;
863 git_config(git_default_config, NULL);
864 if (git_config_get_string_tmp("user.name", &amp;cfg_name) &gt; 0)
865 printf(_("No name is found in config\n"));
866 else
867 printf(_("Your name: %s\n"), cfg_name);</pre>
868 </div>
869 </div>
870 <div class="paragraph">
871 <p><code>git_config()</code> will grab the configuration from config files known to Git and
872 apply standard precedence rules. <code>git_config_get_string_tmp()</code> will look up
873 a specific key ("user.name") and give you the value. There are a number of
874 single-key lookup functions like this one; you can see them all (and more info
875 about how to use <code>git_config()</code>) in <code>Documentation/technical/api-config.txt</code>.</p>
876 </div>
877 <div class="paragraph">
878 <p>You should see that the name printed matches the one you see when you run:</p>
879 </div>
880 <div class="listingblock">
881 <div class="content">
882 <pre>$ git config --get user.name</pre>
883 </div>
884 </div>
885 <div class="paragraph">
886 <p>Great! Now we know how to check for values in the Git config. Let&#8217;s commit this
887 too, so we don&#8217;t lose our progress.</p>
888 </div>
889 <div class="listingblock">
890 <div class="content">
891 <pre>$ git add builtin/psuh.c
892 $ git commit -sm "psuh: show parameters &amp; config opts"</pre>
893 </div>
894 </div>
895 <div class="admonitionblock note">
896 <table>
897 <tr>
898 <td class="icon">
899 <div class="title">Note</div>
900 </td>
901 <td class="content">
902 Again, the above is for sake of brevity in this tutorial. In a real change
903 you should not use <code>-m</code> but instead use the editor to write a meaningful
904 message.
905 </td>
906 </tr>
907 </table>
908 </div>
909 <div class="paragraph">
910 <p>Still, it&#8217;d be nice to know what the user&#8217;s working context is like. Let&#8217;s see
911 if we can print the name of the user&#8217;s current branch. We can mimic the
912 <code>git status</code> implementation; the printer is located in <code>wt-status.c</code> and we can
913 see that the branch is held in a <code>struct wt_status</code>.</p>
914 </div>
915 <div class="paragraph">
916 <p><code>wt_status_print()</code> gets invoked by <code>cmd_status()</code> in <code>builtin/commit.c</code>.
917 Looking at that implementation we see the status config being populated like so:</p>
918 </div>
919 <div class="listingblock">
920 <div class="content">
921 <pre>status_init_config(&amp;s, git_status_config);</pre>
922 </div>
923 </div>
924 <div class="paragraph">
925 <p>But as we drill down, we can find that <code>status_init_config()</code> wraps a call
926 to <code>git_config()</code>. Let&#8217;s modify the code we wrote in the previous commit.</p>
927 </div>
928 <div class="paragraph">
929 <p>Be sure to include the header to allow you to use <code>struct wt_status</code>:</p>
930 </div>
931 <div class="listingblock">
932 <div class="content">
933 <pre>#include "wt-status.h"</pre>
934 </div>
935 </div>
936 <div class="paragraph">
937 <p>Then modify your <code>cmd_psuh</code> implementation to declare your <code>struct wt_status</code>,
938 prepare it, and print its contents:</p>
939 </div>
940 <div class="listingblock">
941 <div class="content">
942 <pre> struct wt_status status;
946 wt_status_prepare(the_repository, &amp;status);
947 git_config(git_default_config, &amp;status);
951 printf(_("Your current branch: %s\n"), status.branch);</pre>
952 </div>
953 </div>
954 <div class="paragraph">
955 <p>Run it again. Check it out - here&#8217;s the (verbose) name of your current branch!</p>
956 </div>
957 <div class="paragraph">
958 <p>Let&#8217;s commit this as well.</p>
959 </div>
960 <div class="listingblock">
961 <div class="content">
962 <pre>$ git add builtin/psuh.c
963 $ git commit -sm "psuh: print the current branch"</pre>
964 </div>
965 </div>
966 <div class="paragraph">
967 <p>Now let&#8217;s see if we can get some info about a specific commit.</p>
968 </div>
969 <div class="paragraph">
970 <p>Luckily, there are some helpers for us here. <code>commit.h</code> has a function called
971 <code>lookup_commit_reference_by_name</code> to which we can simply provide a hardcoded
972 string; <code>pretty.h</code> has an extremely handy <code>pp_commit_easy()</code> call which doesn&#8217;t
973 require a full format object to be passed.</p>
974 </div>
975 <div class="paragraph">
976 <p>Add the following includes:</p>
977 </div>
978 <div class="listingblock">
979 <div class="content">
980 <pre>#include "commit.h"
981 #include "pretty.h"</pre>
982 </div>
983 </div>
984 <div class="paragraph">
985 <p>Then, add the following lines within your implementation of <code>cmd_psuh()</code> near
986 the declarations and the logic, respectively.</p>
987 </div>
988 <div class="listingblock">
989 <div class="content">
990 <pre> struct commit *c = NULL;
991 struct strbuf commitline = STRBUF_INIT;
995 c = lookup_commit_reference_by_name("origin/master");
997 if (c != NULL) {
998 pp_commit_easy(CMIT_FMT_ONELINE, c, &amp;commitline);
999 printf(_("Current commit: %s\n"), commitline.buf);
1000 }</pre>
1001 </div>
1002 </div>
1003 <div class="paragraph">
1004 <p>The <code>struct strbuf</code> provides some safety belts to your basic <code>char*</code>, one of
1005 which is a length member to prevent buffer overruns. It needs to be initialized
1006 nicely with <code>STRBUF_INIT</code>. Keep it in mind when you need to pass around <code>char*</code>.</p>
1007 </div>
1008 <div class="paragraph">
1009 <p><code>lookup_commit_reference_by_name</code> resolves the name you pass it, so you can play
1010 with the value there and see what kind of things you can come up with.</p>
1011 </div>
1012 <div class="paragraph">
1013 <p><code>pp_commit_easy</code> is a convenience wrapper in <code>pretty.h</code> that takes a single
1014 format enum shorthand, rather than an entire format struct. It then
1015 pretty-prints the commit according to that shorthand. These are similar to the
1016 formats available with <code>--pretty=FOO</code> in many Git commands.</p>
1017 </div>
1018 <div class="paragraph">
1019 <p>Build it and run, and if you&#8217;re using the same name in the example, you should
1020 see the subject line of the most recent commit in <code>origin/master</code> that you know
1021 about. Neat! Let&#8217;s commit that as well.</p>
1022 </div>
1023 <div class="listingblock">
1024 <div class="content">
1025 <pre>$ git add builtin/psuh.c
1026 $ git commit -sm "psuh: display the top of origin/master"</pre>
1027 </div>
1028 </div>
1029 </div>
1030 <div class="sect2">
1031 <h3 id="add-documentation"><a class="anchor" href="#add-documentation"></a>Adding Documentation</h3>
1032 <div class="paragraph">
1033 <p>Awesome! You&#8217;ve got a fantastic new command that you&#8217;re ready to share with the
1034 community. But hang on just a minute - this isn&#8217;t very user-friendly. Run the
1035 following:</p>
1036 </div>
1037 <div class="listingblock">
1038 <div class="content">
1039 <pre>$ ./bin-wrappers/git help psuh</pre>
1040 </div>
1041 </div>
1042 <div class="paragraph">
1043 <p>Your new command is undocumented! Let&#8217;s fix that.</p>
1044 </div>
1045 <div class="paragraph">
1046 <p>Take a look at <code>Documentation/git-*.txt</code>. These are the manpages for the
1047 subcommands that Git knows about. You can open these up and take a look to get
1048 acquainted with the format, but then go ahead and make a new file
1049 <code>Documentation/git-psuh.txt</code>. Like with most of the documentation in the Git
1050 project, help pages are written with AsciiDoc (see CodingGuidelines, "Writing
1051 Documentation" section). Use the following template to fill out your own
1052 manpage:</p>
1053 </div>
1054 <div class="listingblock">
1055 <div class="content">
1056 <pre>git-psuh(1)
1057 ===========
1059 NAME
1060 ----
1061 git-psuh - Delight users' typo with a shy horse
1064 SYNOPSIS
1065 --------
1066 [verse]
1067 'git-psuh [&lt;arg&gt;...]'
1069 DESCRIPTION
1070 -----------
1073 OPTIONS[[OPTIONS]]
1074 ------------------
1077 OUTPUT
1078 ------
1083 Part of the linkgit:git[1] suite</pre>
1084 </div>
1085 </div>
1086 <div class="paragraph">
1087 <p>The most important pieces of this to note are the file header, underlined by =,
1088 the NAME section, and the SYNOPSIS, which would normally contain the grammar if
1089 your command took arguments. Try to use well-established manpage headers so your
1090 documentation is consistent with other Git and UNIX manpages; this makes life
1091 easier for your user, who can skip to the section they know contains the
1092 information they need.</p>
1093 </div>
1094 <div class="admonitionblock note">
1095 <table>
1096 <tr>
1097 <td class="icon">
1098 <div class="title">Note</div>
1099 </td>
1100 <td class="content">
1101 Before trying to build the docs, make sure you have the package <code>asciidoc</code>
1102 installed.
1103 </td>
1104 </tr>
1105 </table>
1106 </div>
1107 <div class="paragraph">
1108 <p>Now that you&#8217;ve written your manpage, you&#8217;ll need to build it explicitly. We
1109 convert your AsciiDoc to troff which is man-readable like so:</p>
1110 </div>
1111 <div class="listingblock">
1112 <div class="content">
1113 <pre>$ make all doc
1114 $ man Documentation/git-psuh.1</pre>
1115 </div>
1116 </div>
1117 <div class="paragraph">
1118 <p>or</p>
1119 </div>
1120 <div class="listingblock">
1121 <div class="content">
1122 <pre>$ make -C Documentation/ git-psuh.1
1123 $ man Documentation/git-psuh.1</pre>
1124 </div>
1125 </div>
1126 <div class="paragraph">
1127 <p>While this isn&#8217;t as satisfying as running through <code>git help</code>, you can at least
1128 check that your help page looks right.</p>
1129 </div>
1130 <div class="paragraph">
1131 <p>You can also check that the documentation coverage is good (that is, the project
1132 sees that your command has been implemented as well as documented) by running
1133 <code>make check-docs</code> from the top-level.</p>
1134 </div>
1135 <div class="paragraph">
1136 <p>Go ahead and commit your new documentation change.</p>
1137 </div>
1138 </div>
1139 <div class="sect2">
1140 <h3 id="add-usage"><a class="anchor" href="#add-usage"></a>Adding Usage Text</h3>
1141 <div class="paragraph">
1142 <p>Try and run <code>./bin-wrappers/git psuh -h</code>. Your command should crash at the end.
1143 That&#8217;s because <code>-h</code> is a special case which your command should handle by
1144 printing usage.</p>
1145 </div>
1146 <div class="paragraph">
1147 <p>Take a look at <code>Documentation/technical/api-parse-options.txt</code>. This is a handy
1148 tool for pulling out options you need to be able to handle, and it takes a
1149 usage string.</p>
1150 </div>
1151 <div class="paragraph">
1152 <p>In order to use it, we&#8217;ll need to prepare a NULL-terminated array of usage
1153 strings and a <code>builtin_psuh_options</code> array.</p>
1154 </div>
1155 <div class="paragraph">
1156 <p>Add a line to <code>#include "parse-options.h"</code>.</p>
1157 </div>
1158 <div class="paragraph">
1159 <p>At global scope, add your array of usage strings:</p>
1160 </div>
1161 <div class="listingblock">
1162 <div class="content">
1163 <pre>static const char * const psuh_usage[] = {
1164 N_("git psuh [&lt;arg&gt;...]"),
1165 NULL,
1166 };</pre>
1167 </div>
1168 </div>
1169 <div class="paragraph">
1170 <p>Then, within your <code>cmd_psuh()</code> implementation, we can declare and populate our
1171 <code>option</code> struct. Ours is pretty boring but you can add more to it if you want to
1172 explore <code>parse_options()</code> in more detail:</p>
1173 </div>
1174 <div class="listingblock">
1175 <div class="content">
1176 <pre> struct option options[] = {
1177 OPT_END()
1178 };</pre>
1179 </div>
1180 </div>
1181 <div class="paragraph">
1182 <p>Finally, before you print your args and prefix, add the call to
1183 <code>parse-options()</code>:</p>
1184 </div>
1185 <div class="listingblock">
1186 <div class="content">
1187 <pre> argc = parse_options(argc, argv, prefix, options, psuh_usage, 0);</pre>
1188 </div>
1189 </div>
1190 <div class="paragraph">
1191 <p>This call will modify your <code>argv</code> parameter. It will strip the options you
1192 specified in <code>options</code> from <code>argv</code> and the locations pointed to from <code>options</code>
1193 entries will be updated. Be sure to replace your <code>argc</code> with the result from
1194 <code>parse_options()</code>, or you will be confused if you try to parse <code>argv</code> later.</p>
1195 </div>
1196 <div class="paragraph">
1197 <p>It&#8217;s worth noting the special argument <code>--</code>. As you may be aware, many Unix
1198 commands use <code>--</code> to indicate "end of named parameters" - all parameters after
1199 the <code>--</code> are interpreted merely as positional arguments. (This can be handy if
1200 you want to pass as a parameter something which would usually be interpreted as
1201 a flag.) <code>parse_options()</code> will terminate parsing when it reaches <code>--</code> and give
1202 you the rest of the options afterwards, untouched.</p>
1203 </div>
1204 <div class="paragraph">
1205 <p>Now that you have a usage hint, you can teach Git how to show it in the general
1206 command list shown by <code>git help git</code> or <code>git help -a</code>, which is generated from
1207 <code>command-list.txt</code>. Find the line for <em>git-pull</em> so you can add your <em>git-psuh</em>
1208 line above it in alphabetical order. Now, we can add some attributes about the
1209 command which impacts where it shows up in the aforementioned help commands. The
1210 top of <code>command-list.txt</code> shares some information about what each attribute
1211 means; in those help pages, the commands are sorted according to these
1212 attributes. <code>git psuh</code> is user-facing, or porcelain - so we will mark it as
1213 "mainporcelain". For "mainporcelain" commands, the comments at the top of
1214 <code>command-list.txt</code> indicate we can also optionally add an attribute from another
1215 list; since <code>git psuh</code> shows some information about the user&#8217;s workspace but
1216 doesn&#8217;t modify anything, let&#8217;s mark it as "info". Make sure to keep your
1217 attributes in the same style as the rest of <code>command-list.txt</code> using spaces to
1218 align and delineate them:</p>
1219 </div>
1220 <div class="listingblock">
1221 <div class="content">
1222 <pre>git-prune-packed plumbingmanipulators
1223 git-psuh mainporcelain info
1224 git-pull mainporcelain remote
1225 git-push mainporcelain remote</pre>
1226 </div>
1227 </div>
1228 <div class="paragraph">
1229 <p>Build again. Now, when you run with <code>-h</code>, you should see your usage printed and
1230 your command terminated before anything else interesting happens. Great!</p>
1231 </div>
1232 <div class="paragraph">
1233 <p>Go ahead and commit this one, too.</p>
1234 </div>
1235 </div>
1236 </div>
1237 </div>
1238 <div class="sect1">
1239 <h2 id="testing"><a class="anchor" href="#testing"></a>Testing</h2>
1240 <div class="sectionbody">
1241 <div class="paragraph">
1242 <p>It&#8217;s important to test your code - even for a little toy command like this one.
1243 Moreover, your patch won&#8217;t be accepted into the Git tree without tests. Your
1244 tests should:</p>
1245 </div>
1246 <div class="ulist">
1247 <ul>
1248 <li>
1249 <p>Illustrate the current behavior of the feature</p>
1250 </li>
1251 <li>
1252 <p>Prove the current behavior matches the expected behavior</p>
1253 </li>
1254 <li>
1255 <p>Ensure the externally-visible behavior isn&#8217;t broken in later changes</p>
1256 </li>
1257 </ul>
1258 </div>
1259 <div class="paragraph">
1260 <p>So let&#8217;s write some tests.</p>
1261 </div>
1262 <div class="paragraph">
1263 <p>Related reading: <code>t/README</code></p>
1264 </div>
1265 <div class="sect2">
1266 <h3 id="overview-test-structure"><a class="anchor" href="#overview-test-structure"></a>Overview of Testing Structure</h3>
1267 <div class="paragraph">
1268 <p>The tests in Git live in <code>t/</code> and are named with a 4-digit decimal number using
1269 the schema shown in the Naming Tests section of <code>t/README</code>.</p>
1270 </div>
1271 </div>
1272 <div class="sect2">
1273 <h3 id="write-new-test"><a class="anchor" href="#write-new-test"></a>Writing Your Test</h3>
1274 <div class="paragraph">
1275 <p>Since this a toy command, let&#8217;s go ahead and name the test with t9999. However,
1276 as many of the family/subcmd combinations are full, best practice seems to be
1277 to find a command close enough to the one you&#8217;ve added and share its naming
1278 space.</p>
1279 </div>
1280 <div class="paragraph">
1281 <p>Create a new file <code>t/t9999-psuh-tutorial.sh</code>. Begin with the header as so (see
1282 "Writing Tests" and "Source <em>test-lib.sh</em>" in <code>t/README</code>):</p>
1283 </div>
1284 <div class="listingblock">
1285 <div class="content">
1286 <pre>#!/bin/sh
1288 test_description='git-psuh test
1290 This test runs git-psuh and makes sure it does not crash.'
1292 . ./test-lib.sh</pre>
1293 </div>
1294 </div>
1295 <div class="paragraph">
1296 <p>Tests are framed inside of a <code>test_expect_success</code> in order to output TAP
1297 formatted results. Let&#8217;s make sure that <code>git psuh</code> doesn&#8217;t exit poorly and does
1298 mention the right animal somewhere:</p>
1299 </div>
1300 <div class="listingblock">
1301 <div class="content">
1302 <pre>test_expect_success 'runs correctly with no args and good output' '
1303 git psuh &gt;actual &amp;&amp;
1304 grep Pony actual
1305 '</pre>
1306 </div>
1307 </div>
1308 <div class="paragraph">
1309 <p>Indicate that you&#8217;ve run everything you wanted by adding the following at the
1310 bottom of your script:</p>
1311 </div>
1312 <div class="listingblock">
1313 <div class="content">
1314 <pre>test_done</pre>
1315 </div>
1316 </div>
1317 <div class="paragraph">
1318 <p>Make sure you mark your test script executable:</p>
1319 </div>
1320 <div class="listingblock">
1321 <div class="content">
1322 <pre>$ chmod +x t/t9999-psuh-tutorial.sh</pre>
1323 </div>
1324 </div>
1325 <div class="paragraph">
1326 <p>You can get an idea of whether you created your new test script successfully
1327 by running <code>make -C t test-lint</code>, which will check for things like test number
1328 uniqueness, executable bit, and so on.</p>
1329 </div>
1330 </div>
1331 <div class="sect2">
1332 <h3 id="local-test"><a class="anchor" href="#local-test"></a>Running Locally</h3>
1333 <div class="paragraph">
1334 <p>Let&#8217;s try and run locally:</p>
1335 </div>
1336 <div class="listingblock">
1337 <div class="content">
1338 <pre>$ make
1339 $ cd t/ &amp;&amp; prove t9999-psuh-tutorial.sh</pre>
1340 </div>
1341 </div>
1342 <div class="paragraph">
1343 <p>You can run the full test suite and ensure <code>git-psuh</code> didn&#8217;t break anything:</p>
1344 </div>
1345 <div class="listingblock">
1346 <div class="content">
1347 <pre>$ cd t/
1348 $ prove -j$(nproc) --shuffle t[0-9]*.sh</pre>
1349 </div>
1350 </div>
1351 <div class="admonitionblock note">
1352 <table>
1353 <tr>
1354 <td class="icon">
1355 <div class="title">Note</div>
1356 </td>
1357 <td class="content">
1358 You can also do this with <code>make test</code> or use any testing harness which can
1359 speak TAP. <code>prove</code> can run concurrently. <code>shuffle</code> randomizes the order the
1360 tests are run in, which makes them resilient against unwanted inter-test
1361 dependencies. <code>prove</code> also makes the output nicer.
1362 </td>
1363 </tr>
1364 </table>
1365 </div>
1366 <div class="paragraph">
1367 <p>Go ahead and commit this change, as well.</p>
1368 </div>
1369 </div>
1370 </div>
1371 </div>
1372 <div class="sect1">
1373 <h2 id="ready-to-share"><a class="anchor" href="#ready-to-share"></a>Getting Ready to Share: Anatomy of a Patch Series</h2>
1374 <div class="sectionbody">
1375 <div class="paragraph">
1376 <p>You may have noticed already that the Git project performs its code reviews via
1377 emailed patches, which are then applied by the maintainer when they are ready
1378 and approved by the community. The Git project does not accept contributions from
1379 pull requests, and the patches emailed for review need to be formatted a
1380 specific way.</p>
1381 </div>
1382 <div class="paragraph">
1383 <p>Before taking a look at how to convert your commits into emailed patches,
1384 let&#8217;s analyze what the end result, a "patch series", looks like. Here is an
1385 <a href="https://lore.kernel.org/git/pull.1218.git.git.1645209647.gitgitgadget@gmail.com/">example</a> of the summary view for a patch series on the web interface of
1386 the <a href="https://lore.kernel.org/git/">Git mailing list archive</a>:</p>
1387 </div>
1388 <div class="listingblock">
1389 <div class="content">
1390 <pre>2022-02-18 18:40 [PATCH 0/3] libify reflog John Cai via GitGitGadget
1391 2022-02-18 18:40 ` [PATCH 1/3] reflog: libify delete reflog function and helpers John Cai via GitGitGadget
1392 2022-02-18 19:10 ` Ævar Arnfjörð Bjarmason [this message]
1393 2022-02-18 19:39 ` Taylor Blau
1394 2022-02-18 19:48 ` Ævar Arnfjörð Bjarmason
1395 2022-02-18 19:35 ` Taylor Blau
1396 2022-02-21 1:43 ` John Cai
1397 2022-02-21 1:50 ` Taylor Blau
1398 2022-02-23 19:50 ` John Cai
1399 2022-02-18 20:00 ` // other replies elided
1400 2022-02-18 18:40 ` [PATCH 2/3] reflog: call reflog_delete from reflog.c John Cai via GitGitGadget
1401 2022-02-18 19:15 ` Ævar Arnfjörð Bjarmason
1402 2022-02-18 20:26 ` Junio C Hamano
1403 2022-02-18 18:40 ` [PATCH 3/3] stash: call reflog_delete from reflog.c John Cai via GitGitGadget
1404 2022-02-18 19:20 ` Ævar Arnfjörð Bjarmason
1405 2022-02-19 0:21 ` Taylor Blau
1406 2022-02-22 2:36 ` John Cai
1407 2022-02-22 10:51 ` Ævar Arnfjörð Bjarmason
1408 2022-02-18 19:29 ` [PATCH 0/3] libify reflog Ævar Arnfjörð Bjarmason
1409 2022-02-22 18:30 ` [PATCH v2 0/3] libify reflog John Cai via GitGitGadget
1410 2022-02-22 18:30 ` [PATCH v2 1/3] stash: add test to ensure reflog --rewrite --updatref behavior John Cai via GitGitGadget
1411 2022-02-23 8:54 ` Ævar Arnfjörð Bjarmason
1412 2022-02-23 21:27 ` Junio C Hamano
1413 // continued</pre>
1414 </div>
1415 </div>
1416 <div class="paragraph">
1417 <p>We can note a few things:</p>
1418 </div>
1419 <div class="ulist">
1420 <ul>
1421 <li>
1422 <p>Each commit is sent as a separate email, with the commit message title as
1423 subject, prefixed with "[PATCH <em>i</em>/<em>n</em>]" for the <em>i</em>-th commit of an
1424 <em>n</em>-commit series.</p>
1425 </li>
1426 <li>
1427 <p>Each patch is sent as a reply to an introductory email called the <em>cover
1428 letter</em> of the series, prefixed "[PATCH 0/<em>n</em>]".</p>
1429 </li>
1430 <li>
1431 <p>Subsequent iterations of the patch series are labelled "PATCH v2", "PATCH
1432 v3", etc. in place of "PATCH". For example, "[PATCH v2 1/3]" would be the first of
1433 three patches in the second iteration. Each iteration is sent with a new cover
1434 letter (like "[PATCH v2 0/3]" above), itself a reply to the cover letter of the
1435 previous iteration (more on that below).</p>
1436 </li>
1437 </ul>
1438 </div>
1439 <div class="admonitionblock note">
1440 <table>
1441 <tr>
1442 <td class="icon">
1443 <div class="title">Note</div>
1444 </td>
1445 <td class="content">
1446 A single-patch topic is sent with "[PATCH]", "[PATCH v2]", etc. without
1447 <em>i</em>/<em>n</em> numbering (in the above thread overview, no single-patch topic appears,
1448 though).
1449 </td>
1450 </tr>
1451 </table>
1452 </div>
1453 <div class="sect2">
1454 <h3 id="cover-letter"><a class="anchor" href="#cover-letter"></a>The cover letter</h3>
1455 <div class="paragraph">
1456 <p>In addition to an email per patch, the Git community also expects your patches
1457 to come with a cover letter. This is an important component of change
1458 submission as it explains to the community from a high level what you&#8217;re trying
1459 to do, and why, in a way that&#8217;s more apparent than just looking at your
1460 patches.</p>
1461 </div>
1462 <div class="paragraph">
1463 <p>The title of your cover letter should be something which succinctly covers the
1464 purpose of your entire topic branch. It&#8217;s often in the imperative mood, just
1465 like our commit message titles. Here is how we&#8217;ll title our series:</p>
1466 </div>
1467 <hr/>
1468 <div class="paragraph">
1469 <p>Add the <em>psuh</em> command
1470 ---</p>
1471 </div>
1472 <div class="paragraph">
1473 <p>The body of the cover letter is used to give additional context to reviewers.
1474 Be sure to explain anything your patches don&#8217;t make clear on their own, but
1475 remember that since the cover letter is not recorded in the commit history,
1476 anything that might be useful to future readers of the repository&#8217;s history
1477 should also be in your commit messages.</p>
1478 </div>
1479 <div class="paragraph">
1480 <p>Here&#8217;s an example body for <code>psuh</code>:</p>
1481 </div>
1482 <div class="listingblock">
1483 <div class="content">
1484 <pre>Our internal metrics indicate widespread interest in the command
1485 git-psuh - that is, many users are trying to use it, but finding it is
1486 unavailable, using some unknown workaround instead.
1488 The following handful of patches add the psuh command and implement some
1489 handy features on top of it.
1491 This patchset is part of the MyFirstContribution tutorial and should not
1492 be merged.</pre>
1493 </div>
1494 </div>
1495 <div class="paragraph">
1496 <p>At this point the tutorial diverges, in order to demonstrate two
1497 different methods of formatting your patchset and getting it reviewed.</p>
1498 </div>
1499 <div class="paragraph">
1500 <p>The first method to be covered is GitGitGadget, which is useful for those
1501 already familiar with GitHub&#8217;s common pull request workflow. This method
1502 requires a GitHub account.</p>
1503 </div>
1504 <div class="paragraph">
1505 <p>The second method to be covered is <code>git send-email</code>, which can give slightly
1506 more fine-grained control over the emails to be sent. This method requires some
1507 setup which can change depending on your system and will not be covered in this
1508 tutorial.</p>
1509 </div>
1510 <div class="paragraph">
1511 <p>Regardless of which method you choose, your engagement with reviewers will be
1512 the same; the review process will be covered after the sections on GitGitGadget
1513 and <code>git send-email</code>.</p>
1514 </div>
1515 </div>
1516 </div>
1517 </div>
1518 <div class="sect1">
1519 <h2 id="howto-ggg"><a class="anchor" href="#howto-ggg"></a>Sending Patches via GitGitGadget</h2>
1520 <div class="sectionbody">
1521 <div class="paragraph">
1522 <p>One option for sending patches is to follow a typical pull request workflow and
1523 send your patches out via GitGitGadget. GitGitGadget is a tool created by
1524 Johannes Schindelin to make life as a Git contributor easier for those used to
1525 the GitHub PR workflow. It allows contributors to open pull requests against its
1526 mirror of the Git project, and does some magic to turn the PR into a set of
1527 emails and send them out for you. It also runs the Git continuous integration
1528 suite for you. It&#8217;s documented at <a href="https://gitgitgadget.github.io/" class="bare">https://gitgitgadget.github.io/</a>.</p>
1529 </div>
1530 <div class="sect2">
1531 <h3 id="create-fork"><a class="anchor" href="#create-fork"></a>Forking <code>git/git</code> on GitHub</h3>
1532 <div class="paragraph">
1533 <p>Before you can send your patch off to be reviewed using GitGitGadget, you will
1534 need to fork the Git project and upload your changes. First thing - make sure
1535 you have a GitHub account.</p>
1536 </div>
1537 <div class="paragraph">
1538 <p>Head to the <a href="https://github.com/git/git">GitHub mirror</a> and look for the Fork
1539 button. Place your fork wherever you deem appropriate and create it.</p>
1540 </div>
1541 </div>
1542 <div class="sect2">
1543 <h3 id="upload-to-fork"><a class="anchor" href="#upload-to-fork"></a>Uploading to Your Own Fork</h3>
1544 <div class="paragraph">
1545 <p>To upload your branch to your own fork, you&#8217;ll need to add the new fork as a
1546 remote. You can use <code>git remote -v</code> to show the remotes you have added already.
1547 From your new fork&#8217;s page on GitHub, you can press "Clone or download" to get
1548 the URL; then you need to run the following to add, replacing your own URL and
1549 remote name for the examples provided:</p>
1550 </div>
1551 <div class="listingblock">
1552 <div class="content">
1553 <pre>$ git remote add remotename git@github.com:remotename/git.git</pre>
1554 </div>
1555 </div>
1556 <div class="paragraph">
1557 <p>or to use the HTTPS URL:</p>
1558 </div>
1559 <div class="listingblock">
1560 <div class="content">
1561 <pre>$ git remote add remotename https://github.com/remotename/git/.git</pre>
1562 </div>
1563 </div>
1564 <div class="paragraph">
1565 <p>Run <code>git remote -v</code> again and you should see the new remote showing up.
1566 <code>git fetch remotename</code> (with the real name of your remote replaced) in order to
1567 get ready to push.</p>
1568 </div>
1569 <div class="paragraph">
1570 <p>Next, double-check that you&#8217;ve been doing all your development in a new branch
1571 by running <code>git branch</code>. If you didn&#8217;t, now is a good time to move your new
1572 commits to their own branch.</p>
1573 </div>
1574 <div class="paragraph">
1575 <p>As mentioned briefly at the beginning of this document, we are basing our work
1576 on <code>master</code>, so go ahead and update as shown below, or using your preferred
1577 workflow.</p>
1578 </div>
1579 <div class="listingblock">
1580 <div class="content">
1581 <pre>$ git checkout master
1582 $ git pull -r
1583 $ git rebase master psuh</pre>
1584 </div>
1585 </div>
1586 <div class="paragraph">
1587 <p>Finally, you&#8217;re ready to push your new topic branch! (Due to our branch and
1588 command name choices, be careful when you type the command below.)</p>
1589 </div>
1590 <div class="listingblock">
1591 <div class="content">
1592 <pre>$ git push remotename psuh</pre>
1593 </div>
1594 </div>
1595 <div class="paragraph">
1596 <p>Now you should be able to go and check out your newly created branch on GitHub.</p>
1597 </div>
1598 </div>
1599 <div class="sect2">
1600 <h3 id="send-pr-ggg"><a class="anchor" href="#send-pr-ggg"></a>Sending a PR to GitGitGadget</h3>
1601 <div class="paragraph">
1602 <p>In order to have your code tested and formatted for review, you need to start by
1603 opening a Pull Request against <code>gitgitgadget/git</code>. Head to
1604 <a href="https://github.com/gitgitgadget/git" class="bare">https://github.com/gitgitgadget/git</a> and open a PR either with the "New pull
1605 request" button or the convenient "Compare &amp; pull request" button that may
1606 appear with the name of your newly pushed branch.</p>
1607 </div>
1608 <div class="paragraph">
1609 <p>Review the PR&#8217;s title and description, as they&#8217;re used by GitGitGadget
1610 respectively as the subject and body of the cover letter for your change. Refer
1611 to <a href="#cover-letter">"The cover letter"</a> above for advice on how to title your
1612 submission and what content to include in the description.</p>
1613 </div>
1614 <div class="admonitionblock note">
1615 <table>
1616 <tr>
1617 <td class="icon">
1618 <div class="title">Note</div>
1619 </td>
1620 <td class="content">
1621 For single-patch contributions, your commit message should already be
1622 meaningful and explain at a high level the purpose (what is happening and why)
1623 of your patch, so you usually do not need any additional context. In that case,
1624 remove the PR description that GitHub automatically generates from your commit
1625 message (your PR description should be empty). If you do need to supply even
1626 more context, you can do so in that space and it will be appended to the email
1627 that GitGitGadget will send, between the three-dash line and the diffstat
1628 (see <a href="#single-patch">Bonus Chapter: One-Patch Changes</a> for how this looks once
1629 submitted).
1630 </td>
1631 </tr>
1632 </table>
1633 </div>
1634 <div class="paragraph">
1635 <p>When you&#8217;re happy, submit your pull request.</p>
1636 </div>
1637 </div>
1638 <div class="sect2">
1639 <h3 id="run-ci-ggg"><a class="anchor" href="#run-ci-ggg"></a>Running CI and Getting Ready to Send</h3>
1640 <div class="paragraph">
1641 <p>If it&#8217;s your first time using GitGitGadget (which is likely, as you&#8217;re using
1642 this tutorial) then someone will need to give you permission to use the tool.
1643 As mentioned in the GitGitGadget documentation, you just need someone who
1644 already uses it to comment on your PR with <code>/allow &lt;username&gt;</code>. GitGitGadget
1645 will automatically run your PRs through the CI even without the permission given
1646 but you will not be able to <code>/submit</code> your changes until someone allows you to
1647 use the tool.</p>
1648 </div>
1649 <div class="admonitionblock note">
1650 <table>
1651 <tr>
1652 <td class="icon">
1653 <div class="title">Note</div>
1654 </td>
1655 <td class="content">
1656 You can typically find someone who can <code>/allow</code> you on GitGitGadget by
1657 either examining recent pull requests where someone has been granted <code>/allow</code>
1658 (<a href="https://github.com/gitgitgadget/git/pulls?utf8=%E2%9C%93&amp;q=is%3Apr+is%3Aopen+%22%2Fallow%22">Search:
1659 is:pr is:open "/allow"</a>), in which case both the author and the person who
1660 granted the <code>/allow</code> can now <code>/allow</code> you, or by inquiring on the
1661 <a href="https://web.libera.chat/#git-devel">#git-devel</a> IRC channel on Libera Chat
1662 linking your pull request and asking for someone to <code>/allow</code> you.
1663 </td>
1664 </tr>
1665 </table>
1666 </div>
1667 <div class="paragraph">
1668 <p>If the CI fails, you can update your changes with <code>git rebase -i</code> and push your
1669 branch again:</p>
1670 </div>
1671 <div class="listingblock">
1672 <div class="content">
1673 <pre>$ git push -f remotename psuh</pre>
1674 </div>
1675 </div>
1676 <div class="paragraph">
1677 <p>In fact, you should continue to make changes this way up until the point when
1678 your patch is accepted into <code>next</code>.</p>
1679 </div>
1680 </div>
1681 <div class="sect2">
1682 <h3 id="send-mail-ggg"><a class="anchor" href="#send-mail-ggg"></a>Sending Your Patches</h3>
1683 <div class="paragraph">
1684 <p>Now that your CI is passing and someone has granted you permission to use
1685 GitGitGadget with the <code>/allow</code> command, sending out for review is as simple as
1686 commenting on your PR with <code>/submit</code>.</p>
1687 </div>
1688 </div>
1689 <div class="sect2">
1690 <h3 id="responding-ggg"><a class="anchor" href="#responding-ggg"></a>Updating With Comments</h3>
1691 <div class="paragraph">
1692 <p>Skip ahead to <a href="#reviewing">Responding to Reviews</a> for information on how to
1693 reply to review comments you will receive on the mailing list.</p>
1694 </div>
1695 <div class="paragraph">
1696 <p>Once you have your branch again in the shape you want following all review
1697 comments, you can submit again:</p>
1698 </div>
1699 <div class="listingblock">
1700 <div class="content">
1701 <pre>$ git push -f remotename psuh</pre>
1702 </div>
1703 </div>
1704 <div class="paragraph">
1705 <p>Next, go look at your pull request against GitGitGadget; you should see the CI
1706 has been kicked off again. Now while the CI is running is a good time for you
1707 to modify your description at the top of the pull request thread; it will be
1708 used again as the cover letter. You should use this space to describe what
1709 has changed since your previous version, so that your reviewers have some idea
1710 of what they&#8217;re looking at. When the CI is done running, you can comment once
1711 more with <code>/submit</code> - GitGitGadget will automatically add a v2 mark to your
1712 changes.</p>
1713 </div>
1714 </div>
1715 </div>
1716 </div>
1717 <div class="sect1">
1718 <h2 id="howto-git-send-email"><a class="anchor" href="#howto-git-send-email"></a>Sending Patches with <code>git send-email</code></h2>
1719 <div class="sectionbody">
1720 <div class="paragraph">
1721 <p>If you don&#8217;t want to use GitGitGadget, you can also use Git itself to mail your
1722 patches. Some benefits of using Git this way include finer grained control of
1723 subject line (for example, being able to use the tag [RFC PATCH] in the subject)
1724 and being able to send a &#8220;dry run&#8221; mail to yourself to ensure it all looks
1725 good before going out to the list.</p>
1726 </div>
1727 <div class="sect2">
1728 <h3 id="setup-git-send-email"><a class="anchor" href="#setup-git-send-email"></a>Prerequisite: Setting Up <code>git send-email</code></h3>
1729 <div class="paragraph">
1730 <p>Configuration for <code>send-email</code> can vary based on your operating system and email
1731 provider, and so will not be covered in this tutorial, beyond stating that in
1732 many distributions of Linux, <code>git-send-email</code> is not packaged alongside the
1733 typical <code>git</code> install. You may need to install this additional package; there
1734 are a number of resources online to help you do so. You will also need to
1735 determine the right way to configure it to use your SMTP server; again, as this
1736 configuration can change significantly based on your system and email setup, it
1737 is out of scope for the context of this tutorial.</p>
1738 </div>
1739 </div>
1740 <div class="sect2">
1741 <h3 id="format-patch"><a class="anchor" href="#format-patch"></a>Preparing Initial Patchset</h3>
1742 <div class="paragraph">
1743 <p>Sending emails with Git is a two-part process; before you can prepare the emails
1744 themselves, you&#8217;ll need to prepare the patches. Luckily, this is pretty simple:</p>
1745 </div>
1746 <div class="listingblock">
1747 <div class="content">
1748 <pre>$ git format-patch --cover-letter -o psuh/ --base=auto psuh@{u}..psuh</pre>
1749 </div>
1750 </div>
1751 <div class="olist arabic">
1752 <ol class="arabic">
1753 <li>
1754 <p>The <code>--cover-letter</code> option tells <code>format-patch</code> to create a
1755 cover letter template for you. You will need to fill in the
1756 template before you&#8217;re ready to send - but for now, the template
1757 will be next to your other patches.</p>
1758 </li>
1759 <li>
1760 <p>The <code>-o psuh/</code> option tells <code>format-patch</code> to place the patch
1761 files into a directory. This is useful because <code>git send-email</code>
1762 can take a directory and send out all the patches from there.</p>
1763 </li>
1764 <li>
1765 <p>The <code>--base=auto</code> option tells the command to record the "base
1766 commit", on which the recipient is expected to apply the patch
1767 series. The <code>auto</code> value will cause <code>format-patch</code> to compute
1768 the base commit automatically, which is the merge base of tip
1769 commit of the remote-tracking branch and the specified revision
1770 range.</p>
1771 </li>
1772 <li>
1773 <p>The <code>psuh@{u}..psuh</code> option tells <code>format-patch</code> to generate
1774 patches for the commits you created on the <code>psuh</code> branch since it
1775 forked from its upstream (which is <code>origin/master</code> if you
1776 followed the example in the "Set up your workspace" section). If
1777 you are already on the <code>psuh</code> branch, you can just say <code>@{u}</code>,
1778 which means "commits on the current branch since it forked from
1779 its upstream", which is the same thing.</p>
1780 </li>
1781 </ol>
1782 </div>
1783 <div class="paragraph">
1784 <p>The command will make one patch file per commit. After you
1785 run, you can go have a look at each of the patches with your favorite text
1786 editor and make sure everything looks alright; however, it&#8217;s not recommended to
1787 make code fixups via the patch file. It&#8217;s a better idea to make the change the
1788 normal way using <code>git rebase -i</code> or by adding a new commit than by modifying a
1789 patch.</p>
1790 </div>
1791 <div class="admonitionblock note">
1792 <table>
1793 <tr>
1794 <td class="icon">
1795 <div class="title">Note</div>
1796 </td>
1797 <td class="content">
1798 Optionally, you can also use the <code>--rfc</code> flag to prefix your patch subject
1799 with &#8220;[RFC PATCH]&#8221; instead of &#8220;[PATCH]&#8221;. RFC stands for &#8220;request for
1800 comments&#8221; and indicates that while your code isn&#8217;t quite ready for submission,
1801 you&#8217;d like to begin the code review process. This can also be used when your
1802 patch is a proposal, but you aren&#8217;t sure whether the community wants to solve
1803 the problem with that approach or not - to conduct a sort of design review. You
1804 may also see on the list patches marked &#8220;WIP&#8221; - this means they are incomplete
1805 but want reviewers to look at what they have so far. You can add this flag with
1806 <code>--subject-prefix=WIP</code>.
1807 </td>
1808 </tr>
1809 </table>
1810 </div>
1811 <div class="paragraph">
1812 <p>Check and make sure that your patches and cover letter template exist in the
1813 directory you specified - you&#8217;re nearly ready to send out your review!</p>
1814 </div>
1815 </div>
1816 <div class="sect2">
1817 <h3 id="preparing-cover-letter"><a class="anchor" href="#preparing-cover-letter"></a>Preparing Email</h3>
1818 <div class="paragraph">
1819 <p>Since you invoked <code>format-patch</code> with <code>--cover-letter</code>, you&#8217;ve already got a
1820 cover letter template ready. Open it up in your favorite editor.</p>
1821 </div>
1822 <div class="paragraph">
1823 <p>You should see a number of headers present already. Check that your <code>From:</code>
1824 header is correct. Then modify your <code>Subject:</code> (see <a href="#cover-letter">above</a> for
1825 how to choose good title for your patch series):</p>
1826 </div>
1827 <div class="listingblock">
1828 <div class="content">
1829 <pre>Subject: [PATCH 0/7] Add the 'psuh' command</pre>
1830 </div>
1831 </div>
1832 <div class="paragraph">
1833 <p>Make sure you retain the &#8220;[PATCH 0/X]&#8221; part; that&#8217;s what indicates to the Git
1834 community that this email is the beginning of a patch series, and many
1835 reviewers filter their email for this type of flag.</p>
1836 </div>
1837 <div class="paragraph">
1838 <p>You&#8217;ll need to add some extra parameters when you invoke <code>git send-email</code> to add
1839 the cover letter.</p>
1840 </div>
1841 <div class="paragraph">
1842 <p>Next you&#8217;ll have to fill out the body of your cover letter. Again, see
1843 <a href="#cover-letter">above</a> for what content to include.</p>
1844 </div>
1845 <div class="paragraph">
1846 <p>The template created by <code>git format-patch --cover-letter</code> includes a diffstat.
1847 This gives reviewers a summary of what they&#8217;re in for when reviewing your topic.
1848 The one generated for <code>psuh</code> from the sample implementation looks like this:</p>
1849 </div>
1850 <div class="listingblock">
1851 <div class="content">
1852 <pre> Documentation/git-psuh.txt | 40 +++++++++++++++++++++
1853 Makefile | 1 +
1854 builtin.h | 1 +
1855 builtin/psuh.c | 73 ++++++++++++++++++++++++++++++++++++++
1856 git.c | 1 +
1857 t/t9999-psuh-tutorial.sh | 12 +++++++
1858 6 files changed, 128 insertions(+)
1859 create mode 100644 Documentation/git-psuh.txt
1860 create mode 100644 builtin/psuh.c
1861 create mode 100755 t/t9999-psuh-tutorial.sh</pre>
1862 </div>
1863 </div>
1864 <div class="paragraph">
1865 <p>Finally, the letter will include the version of Git used to generate the
1866 patches. You can leave that string alone.</p>
1867 </div>
1868 </div>
1869 <div class="sect2">
1870 <h3 id="sending-git-send-email"><a class="anchor" href="#sending-git-send-email"></a>Sending Email</h3>
1871 <div class="paragraph">
1872 <p>At this point you should have a directory <code>psuh/</code> which is filled with your
1873 patches and a cover letter. Time to mail it out! You can send it like this:</p>
1874 </div>
1875 <div class="listingblock">
1876 <div class="content">
1877 <pre>$ git send-email --to=target@example.com psuh/*.patch</pre>
1878 </div>
1879 </div>
1880 <div class="admonitionblock note">
1881 <table>
1882 <tr>
1883 <td class="icon">
1884 <div class="title">Note</div>
1885 </td>
1886 <td class="content">
1887 Check <code>git help send-email</code> for some other options which you may find
1888 valuable, such as changing the Reply-to address or adding more CC and BCC lines.
1889 </td>
1890 </tr>
1891 </table>
1892 </div>
1893 <div class="admonitionblock note">
1894 <table>
1895 <tr>
1896 <td class="icon">
1897 <div class="title">Note</div>
1898 </td>
1899 <td class="content">
1900 If you&#8217;re not sure whom to CC, running <code>contrib/contacts/git-contacts</code> can
1901 list potential reviewers. In addition, you can do <code>git send-email
1902 --cc-cmd='perl contrib/contacts/git-contacts' feature/*.patch</code><sup class="footnote" id="_footnote_contrib-scripts">[<a id="_footnoteref_1" class="footnote" href="#_footnotedef_1" title="View footnote.">1</a>]</sup> to
1903 automatically pass this list of emails to <code>send-email</code>.
1904 </td>
1905 </tr>
1906 </table>
1907 </div>
1908 <div class="admonitionblock note">
1909 <table>
1910 <tr>
1911 <td class="icon">
1912 <div class="title">Note</div>
1913 </td>
1914 <td class="content">
1915 When you are sending a real patch, it will go to <a href="mailto:git@vger.kernel.org">git@vger.kernel.org</a> - but
1916 please don&#8217;t send your patchset from the tutorial to the real mailing list! For
1917 now, you can send it to yourself, to make sure you understand how it will look.
1918 </td>
1919 </tr>
1920 </table>
1921 </div>
1922 <div class="paragraph">
1923 <p>After you run the command above, you will be presented with an interactive
1924 prompt for each patch that&#8217;s about to go out. This gives you one last chance to
1925 edit or quit sending something (but again, don&#8217;t edit code this way). Once you
1926 press <code>y</code> or <code>a</code> at these prompts your emails will be sent! Congratulations!</p>
1927 </div>
1928 <div class="paragraph">
1929 <p>Awesome, now the community will drop everything and review your changes. (Just
1930 kidding - be patient!)</p>
1931 </div>
1932 </div>
1933 <div class="sect2">
1934 <h3 id="v2-git-send-email"><a class="anchor" href="#v2-git-send-email"></a>Sending v2</h3>
1935 <div class="paragraph">
1936 <p>This section will focus on how to send a v2 of your patchset. To learn what
1937 should go into v2, skip ahead to <a href="#reviewing">Responding to Reviews</a> for
1938 information on how to handle comments from reviewers.</p>
1939 </div>
1940 <div class="paragraph">
1941 <p>We&#8217;ll reuse our <code>psuh</code> topic branch for v2. Before we make any changes, we&#8217;ll
1942 mark the tip of our v1 branch for easy reference:</p>
1943 </div>
1944 <div class="listingblock">
1945 <div class="content">
1946 <pre>$ git checkout psuh
1947 $ git branch psuh-v1</pre>
1948 </div>
1949 </div>
1950 <div class="paragraph">
1951 <p>Refine your patch series by using <code>git rebase -i</code> to adjust commits based upon
1952 reviewer comments. Once the patch series is ready for submission, generate your
1953 patches again, but with some new flags:</p>
1954 </div>
1955 <div class="listingblock">
1956 <div class="content">
1957 <pre>$ git format-patch -v2 --cover-letter -o psuh/ --range-diff master..psuh-v1 master..</pre>
1958 </div>
1959 </div>
1960 <div class="paragraph">
1961 <p>The <code>--range-diff master..psuh-v1</code> parameter tells <code>format-patch</code> to include a
1962 range-diff between <code>psuh-v1</code> and <code>psuh</code> in the cover letter (see
1963 <a href="git-range-diff.html">git-range-diff(1)</a>). This helps tell reviewers about the differences
1964 between your v1 and v2 patches.</p>
1965 </div>
1966 <div class="paragraph">
1967 <p>The <code>-v2</code> parameter tells <code>format-patch</code> to output your patches
1968 as version "2". For instance, you may notice that your v2 patches are
1969 all named like <code>v2-000n-my-commit-subject.patch</code>. <code>-v2</code> will also format
1970 your patches by prefixing them with "[PATCH v2]" instead of "[PATCH]",
1971 and your range-diff will be prefaced with "Range-diff against v1".</p>
1972 </div>
1973 <div class="paragraph">
1974 <p>After you run this command, <code>format-patch</code> will output the patches to the <code>psuh/</code>
1975 directory, alongside the v1 patches. Using a single directory makes it easy to
1976 refer to the old v1 patches while proofreading the v2 patches, but you will need
1977 to be careful to send out only the v2 patches. We will use a pattern like
1978 <code>psuh/v2-*.patch</code> (not <code>psuh/*.patch</code>, which would match v1 and v2 patches).</p>
1979 </div>
1980 <div class="paragraph">
1981 <p>Edit your cover letter again. Now is a good time to mention what&#8217;s different
1982 between your last version and now, if it&#8217;s something significant. You do not
1983 need the exact same body in your second cover letter; focus on explaining to
1984 reviewers the changes you&#8217;ve made that may not be as visible.</p>
1985 </div>
1986 <div class="paragraph">
1987 <p>You will also need to go and find the Message-ID of your previous cover letter.
1988 You can either note it when you send the first series, from the output of <code>git
1989 send-email</code>, or you can look it up on the
1990 <a href="https://lore.kernel.org/git">mailing list</a>. Find your cover letter in the
1991 archives, click on it, then click "permalink" or "raw" to reveal the Message-ID
1992 header. It should match:</p>
1993 </div>
1994 <div class="listingblock">
1995 <div class="content">
1996 <pre>Message-ID: &lt;foo.12345.author@example.com&gt;</pre>
1997 </div>
1998 </div>
1999 <div class="paragraph">
2000 <p>Your Message-ID is <code>&lt;foo.12345.author@example.com&gt;</code>. This example will be used
2001 below as well; make sure to replace it with the correct Message-ID for your
2002 <strong>previous cover letter</strong> - that is, if you&#8217;re sending v2, use the Message-ID
2003 from v1; if you&#8217;re sending v3, use the Message-ID from v2.</p>
2004 </div>
2005 <div class="paragraph">
2006 <p>While you&#8217;re looking at the email, you should also note who is CC&#8217;d, as it&#8217;s
2007 common practice in the mailing list to keep all CCs on a thread. You can add
2008 these CC lines directly to your cover letter with a line like so in the header
2009 (before the Subject line):</p>
2010 </div>
2011 <div class="listingblock">
2012 <div class="content">
2013 <pre>CC: author@example.com, Othe R &lt;other@example.com&gt;</pre>
2014 </div>
2015 </div>
2016 <div class="paragraph">
2017 <p>Now send the emails again, paying close attention to which messages you pass in
2018 to the command:</p>
2019 </div>
2020 <div class="listingblock">
2021 <div class="content">
2022 <pre>$ git send-email --to=target@example.com
2023 --in-reply-to="&lt;foo.12345.author@example.com&gt;"
2024 psuh/v2-*.patch</pre>
2025 </div>
2026 </div>
2027 </div>
2028 <div class="sect2">
2029 <h3 id="single-patch"><a class="anchor" href="#single-patch"></a>Bonus Chapter: One-Patch Changes</h3>
2030 <div class="paragraph">
2031 <p>In some cases, your very small change may consist of only one patch. When that
2032 happens, you only need to send one email. Your commit message should already be
2033 meaningful and explain at a high level the purpose (what is happening and why)
2034 of your patch, but if you need to supply even more context, you can do so below
2035 the <code>---</code> in your patch. Take the example below, which was generated with <code>git
2036 format-patch</code> on a single commit, and then edited to add the content between
2037 the <code>---</code> and the diffstat.</p>
2038 </div>
2039 <div class="listingblock">
2040 <div class="content">
2041 <pre>From 1345bbb3f7ac74abde040c12e737204689a72723 Mon Sep 17 00:00:00 2001
2042 From: A U Thor &lt;author@example.com&gt;
2043 Date: Thu, 18 Apr 2019 15:11:02 -0700
2044 Subject: [PATCH] README: change the grammar
2046 I think it looks better this way. This part of the commit message will
2047 end up in the commit-log.
2049 Signed-off-by: A U Thor &lt;author@example.com&gt;
2051 Let's have a wild discussion about grammar on the mailing list. This
2052 part of my email will never end up in the commit log. Here is where I
2053 can add additional context to the mailing list about my intent, outside
2054 of the context of the commit log. This section was added after `git
2055 format-patch` was run, by editing the patch file in a text editor.
2057 README.md | 2 +-
2058 1 file changed, 1 insertion(+), 1 deletion(-)
2060 diff --git a/README.md b/README.md
2061 index 88f126184c..38da593a60 100644
2062 --- a/README.md
2063 +++ b/README.md
2064 @@ -3,7 +3,7 @@
2065 Git - fast, scalable, distributed revision control system
2066 =========================================================
2068 -Git is a fast, scalable, distributed revision control system with an
2069 +Git is a fast, scalable, and distributed revision control system with an
2070 unusually rich command set that provides both high-level operations
2071 and full access to internals.
2074 2.21.0.392.gf8f6787159e-goog</pre>
2075 </div>
2076 </div>
2077 </div>
2078 </div>
2079 </div>
2080 <div class="sect1">
2081 <h2 id="now-what"><a class="anchor" href="#now-what"></a>My Patch Got Emailed - Now What?</h2>
2082 <div class="sectionbody">
2083 <div class="paragraph">
2084 <p>Please give reviewers enough time to process your initial patch before
2085 sending an updated version. That is, resist the temptation to send a new
2086 version immediately, because others may have already started reviewing
2087 your initial version.</p>
2088 </div>
2089 <div class="paragraph">
2090 <p>While waiting for review comments, you may find mistakes in your initial
2091 patch, or perhaps realize a different and better way to achieve the goal
2092 of the patch. In this case you may communicate your findings to other
2093 reviewers as follows:</p>
2094 </div>
2095 <div class="ulist">
2096 <ul>
2097 <li>
2098 <p>If the mistakes you found are minor, send a reply to your patch as if
2099 you were a reviewer and mention that you will fix them in an
2100 updated version.</p>
2101 </li>
2102 <li>
2103 <p>On the other hand, if you think you want to change the course so
2104 drastically that reviews on the initial patch would be a waste of
2105 time (for everyone involved), retract the patch immediately with
2106 a reply like "I am working on a much better approach, so please
2107 ignore this patch and wait for the updated version."</p>
2108 </li>
2109 </ul>
2110 </div>
2111 <div class="paragraph">
2112 <p>Now, the above is a good practice if you sent your initial patch
2113 prematurely without polish. But a better approach of course is to avoid
2114 sending your patch prematurely in the first place.</p>
2115 </div>
2116 <div class="paragraph">
2117 <p>Please be considerate of the time needed by reviewers to examine each
2118 new version of your patch. Rather than seeing the initial version right
2119 now (followed by several "oops, I like this version better than the
2120 previous one" patches over 2 days), reviewers would strongly prefer if a
2121 single polished version came 2 days later instead, and that version with
2122 fewer mistakes were the only one they would need to review.</p>
2123 </div>
2124 <div class="sect2">
2125 <h3 id="reviewing"><a class="anchor" href="#reviewing"></a>Responding to Reviews</h3>
2126 <div class="paragraph">
2127 <p>After a few days, you will hopefully receive a reply to your patchset with some
2128 comments. Woohoo! Now you can get back to work.</p>
2129 </div>
2130 <div class="paragraph">
2131 <p>It&#8217;s good manners to reply to each comment, notifying the reviewer that you have
2132 made the change suggested, feel the original is better, or that the comment
2133 inspired you to do something a new way which is superior to both the original
2134 and the suggested change. This way reviewers don&#8217;t need to inspect your v2 to
2135 figure out whether you implemented their comment or not.</p>
2136 </div>
2137 <div class="paragraph">
2138 <p>Reviewers may ask you about what you wrote in the patchset, either in
2139 the proposed commit log message or in the changes themselves. You
2140 should answer these questions in your response messages, but often the
2141 reason why reviewers asked these questions to understand what you meant
2142 to write is because your patchset needed clarification to be understood.</p>
2143 </div>
2144 <div class="paragraph">
2145 <p>Do not be satisfied by just answering their questions in your response
2146 and hear them say that they now understand what you wanted to say.
2147 Update your patches to clarify the points reviewers had trouble with,
2148 and prepare your v2; the words you used to explain your v1 to answer
2149 reviewers' questions may be useful thing to use. Your goal is to make
2150 your v2 clear enough so that it becomes unnecessary for you to give the
2151 same explanation to the next person who reads it.</p>
2152 </div>
2153 <div class="paragraph">
2154 <p>If you are going to push back on a comment, be polite and explain why you feel
2155 your original is better; be prepared that the reviewer may still disagree with
2156 you, and the rest of the community may weigh in on one side or the other. As
2157 with all code reviews, it&#8217;s important to keep an open mind to doing something a
2158 different way than you originally planned; other reviewers have a different
2159 perspective on the project than you do, and may be thinking of a valid side
2160 effect which had not occurred to you. It is always okay to ask for clarification
2161 if you aren&#8217;t sure why a change was suggested, or what the reviewer is asking
2162 you to do.</p>
2163 </div>
2164 <div class="paragraph">
2165 <p>Make sure your email client has a plaintext email mode and it is turned on; the
2166 Git list rejects HTML email. Please also follow the mailing list etiquette
2167 outlined in the
2168 <a href="https://kernel.googlesource.com/pub/scm/git/git/+/todo/MaintNotes">Maintainer&#8217;s
2169 Note</a>, which are similar to etiquette rules in most open source communities
2170 surrounding bottom-posting and inline replies.</p>
2171 </div>
2172 <div class="paragraph">
2173 <p>When you&#8217;re making changes to your code, it is cleanest - that is, the resulting
2174 commits are easiest to look at - if you use <code>git rebase -i</code> (interactive
2175 rebase). Take a look at this
2176 <a href="https://www.oreilly.com/library/view/git-pocket-guide/9781449327507/ch10.html">overview</a>
2177 from O&#8217;Reilly. The general idea is to modify each commit which requires changes;
2178 this way, instead of having a patch A with a mistake, a patch B which was fine
2179 and required no upstream reviews in v1, and a patch C which fixes patch A for
2180 v2, you can just ship a v2 with a correct patch A and correct patch B. This is
2181 changing history, but since it&#8217;s local history which you haven&#8217;t shared with
2182 anyone, that is okay for now! (Later, it may not make sense to do this; take a
2183 look at the section below this one for some context.)</p>
2184 </div>
2185 </div>
2186 <div class="sect2">
2187 <h3 id="after-approval"><a class="anchor" href="#after-approval"></a>After Review Approval</h3>
2188 <div class="paragraph">
2189 <p>The Git project has four integration branches: <code>seen</code>, <code>next</code>, <code>master</code>, and
2190 <code>maint</code>. Your change will be placed into <code>seen</code> fairly early on by the maintainer
2191 while it is still in the review process; from there, when it is ready for wider
2192 testing, it will be merged into <code>next</code>. Plenty of early testers use <code>next</code> and
2193 may report issues. Eventually, changes in <code>next</code> will make it to <code>master</code>,
2194 which is typically considered stable. Finally, when a new release is cut,
2195 <code>maint</code> is used to base bugfixes onto. As mentioned at the beginning of this
2196 document, you can read <code>Documents/SubmittingPatches</code> for some more info about
2197 the use of the various integration branches.</p>
2198 </div>
2199 <div class="paragraph">
2200 <p>Back to now: your code has been lauded by the upstream reviewers. It is perfect.
2201 It is ready to be accepted. You don&#8217;t need to do anything else; the maintainer
2202 will merge your topic branch to <code>next</code> and life is good.</p>
2203 </div>
2204 <div class="paragraph">
2205 <p>However, if you discover it isn&#8217;t so perfect after this point, you may need to
2206 take some special steps depending on where you are in the process.</p>
2207 </div>
2208 <div class="paragraph">
2209 <p>If the maintainer has announced in the "What&#8217;s cooking in git.git" email that
2210 your topic is marked for <code>next</code> - that is, that they plan to merge it to <code>next</code>
2211 but have not yet done so - you should send an email asking the maintainer to
2212 wait a little longer: "I&#8217;ve sent v4 of my series and you marked it for <code>next</code>,
2213 but I need to change this and that - please wait for v5 before you merge it."</p>
2214 </div>
2215 <div class="paragraph">
2216 <p>If the topic has already been merged to <code>next</code>, rather than modifying your
2217 patches with <code>git rebase -i</code>, you should make further changes incrementally -
2218 that is, with another commit, based on top of the maintainer&#8217;s topic branch as
2219 detailed in <a href="https://github.com/gitster/git" class="bare">https://github.com/gitster/git</a>. Your work is still in the same topic
2220 but is now incremental, rather than a wholesale rewrite of the topic branch.</p>
2221 </div>
2222 <div class="paragraph">
2223 <p>The topic branches in the maintainer&#8217;s GitHub are mirrored in GitGitGadget, so
2224 if you&#8217;re sending your reviews out that way, you should be sure to open your PR
2225 against the appropriate GitGitGadget/Git branch.</p>
2226 </div>
2227 <div class="paragraph">
2228 <p>If you&#8217;re using <code>git send-email</code>, you can use it the same way as before, but you
2229 should generate your diffs from <code>&lt;topic&gt;..&lt;mybranch&gt;</code> and base your work on
2230 <code>&lt;topic&gt;</code> instead of <code>master</code>.</p>
2231 </div>
2232 </div>
2233 </div>
2234 </div>
2235 </div>
2236 <div id="footnotes">
2237 <hr/>
2238 <div class="footnote" id="_footnotedef_1">
2239 <a href="#_footnoteref_1">1</a>. Scripts under `contrib/` are not part of the core `git` binary and must be called directly. Clone the Git codebase and run `perl contrib/contacts/git-contacts`.
2240 </div>
2241 </div>
2242 <div id="footer">
2243 <div id="footer-text">
2244 Last updated 2024-05-01 10:56:52 -0700
2245 </div>
2246 </div>
2247 </body>
2248 </html>