blob: 996287c95260ca9d236e55cd14b8ab50047203e6 [file] [log] [blame]
Junio C Hamano7d06a8a2008-10-20 05:42:331<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
2 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6<meta name="generator" content="AsciiDoc 8.2.5" />
7<style type="text/css">
8/* Debug borders */
9p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
10/*
11 border: 1px solid red;
12*/
13}
14
15body {
16 margin: 1em 5% 1em 5%;
17}
18
19a {
20 color: blue;
21 text-decoration: underline;
22}
23a:visited {
24 color: fuchsia;
25}
26
27em {
28 font-style: italic;
29}
30
31strong {
32 font-weight: bold;
33}
34
35tt {
36 color: navy;
37}
38
39h1, h2, h3, h4, h5, h6 {
40 color: #527bbd;
41 font-family: sans-serif;
42 margin-top: 1.2em;
43 margin-bottom: 0.5em;
44 line-height: 1.3;
45}
46
47h1, h2, h3 {
48 border-bottom: 2px solid silver;
49}
50h2 {
51 padding-top: 0.5em;
52}
53h3 {
54 float: left;
55}
56h3 + * {
57 clear: left;
58}
59
60div.sectionbody {
61 font-family: serif;
62 margin-left: 0;
63}
64
65hr {
66 border: 1px solid silver;
67}
68
69p {
70 margin-top: 0.5em;
71 margin-bottom: 0.5em;
72}
73
74pre {
75 padding: 0;
76 margin: 0;
77}
78
79span#author {
80 color: #527bbd;
81 font-family: sans-serif;
82 font-weight: bold;
83 font-size: 1.1em;
84}
85span#email {
86}
87span#revision {
88 font-family: sans-serif;
89}
90
91div#footer {
92 font-family: sans-serif;
93 font-size: small;
94 border-top: 2px solid silver;
95 padding-top: 0.5em;
96 margin-top: 4.0em;
97}
98div#footer-text {
99 float: left;
100 padding-bottom: 0.5em;
101}
102div#footer-badges {
103 float: right;
104 padding-bottom: 0.5em;
105}
106
107div#preamble,
108div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
109div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
110div.admonitionblock {
111 margin-right: 10%;
112 margin-top: 1.5em;
113 margin-bottom: 1.5em;
114}
115div.admonitionblock {
116 margin-top: 2.5em;
117 margin-bottom: 2.5em;
118}
119
120div.content { /* Block element content. */
121 padding: 0;
122}
123
124/* Block element titles. */
125div.title, caption.title {
126 font-family: sans-serif;
127 font-weight: bold;
128 text-align: left;
129 margin-top: 1.0em;
130 margin-bottom: 0.5em;
131}
132div.title + * {
133 margin-top: 0;
134}
135
136td div.title:first-child {
137 margin-top: 0.0em;
138}
139div.content div.title:first-child {
140 margin-top: 0.0em;
141}
142div.content + div.title {
143 margin-top: 0.0em;
144}
145
146div.sidebarblock > div.content {
147 background: #ffffee;
148 border: 1px solid silver;
149 padding: 0.5em;
150}
151
152div.listingblock {
153 margin-right: 0%;
154}
155div.listingblock > div.content {
156 border: 1px solid silver;
157 background: #f4f4f4;
158 padding: 0.5em;
159}
160
161div.quoteblock > div.content {
162 padding-left: 2.0em;
163}
164
165div.attribution {
166 text-align: right;
167}
168div.verseblock + div.attribution {
169 text-align: left;
170}
171
172div.admonitionblock .icon {
173 vertical-align: top;
174 font-size: 1.1em;
175 font-weight: bold;
176 text-decoration: underline;
177 color: #527bbd;
178 padding-right: 0.5em;
179}
180div.admonitionblock td.content {
181 padding-left: 0.5em;
182 border-left: 2px solid silver;
183}
184
185div.exampleblock > div.content {
186 border-left: 2px solid silver;
187 padding: 0.5em;
188}
189
190div.verseblock div.content {
191 white-space: pre;
192}
193
194div.imageblock div.content { padding-left: 0; }
195div.imageblock img { border: 1px solid silver; }
196span.image img { border-style: none; }
197
198dl {
199 margin-top: 0.8em;
200 margin-bottom: 0.8em;
201}
202dt {
203 margin-top: 0.5em;
204 margin-bottom: 0;
205 font-style: italic;
206}
207dd > *:first-child {
208 margin-top: 0;
209}
210
211ul, ol {
212 list-style-position: outside;
213}
214div.olist2 ol {
215 list-style-type: lower-alpha;
216}
217
218div.tableblock > table {
219 border: 3px solid #527bbd;
220}
221thead {
222 font-family: sans-serif;
223 font-weight: bold;
224}
225tfoot {
226 font-weight: bold;
227}
228
229div.hlist {
230 margin-top: 0.8em;
231 margin-bottom: 0.8em;
232}
233div.hlist td {
234 padding-bottom: 5px;
235}
236td.hlist1 {
237 vertical-align: top;
238 font-style: italic;
239 padding-right: 0.8em;
240}
241td.hlist2 {
242 vertical-align: top;
243}
244
245@media print {
246 div#footer-badges { display: none; }
247}
248
249div#toctitle {
250 color: #527bbd;
251 font-family: sans-serif;
252 font-size: 1.1em;
253 font-weight: bold;
254 margin-top: 1.0em;
255 margin-bottom: 0.1em;
256}
257
258div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
259 margin-top: 0;
260 margin-bottom: 0;
261}
262div.toclevel2 {
263 margin-left: 2em;
264 font-size: 0.9em;
265}
266div.toclevel3 {
267 margin-left: 4em;
268 font-size: 0.9em;
269}
270div.toclevel4 {
271 margin-left: 6em;
272 font-size: 0.9em;
273}
274include1::./stylesheets/xhtml11-manpage.css[]
275/* Workarounds for IE6's broken and incomplete CSS2. */
276
277div.sidebar-content {
278 background: #ffffee;
279 border: 1px solid silver;
280 padding: 0.5em;
281}
282div.sidebar-title, div.image-title {
283 font-family: sans-serif;
284 font-weight: bold;
285 margin-top: 0.0em;
286 margin-bottom: 0.5em;
287}
288
289div.listingblock div.content {
290 border: 1px solid silver;
291 background: #f4f4f4;
292 padding: 0.5em;
293}
294
295div.quoteblock-content {
296 padding-left: 2.0em;
297}
298
299div.exampleblock-content {
300 border-left: 2px solid silver;
301 padding-left: 0.5em;
302}
303
304/* IE6 sets dynamically generated links as visited. */
305div#toc a:visited { color: blue; }
306</style>
307<title>gitworkflows(7)</title>
308</head>
309<body>
310<div id="header">
311<h1>
312gitworkflows(7) Manual Page
313</h1>
314<h2>NAME</h2>
315<div class="sectionbody">
316<p>gitworkflows -
317 An overview of recommended workflows with git
318</p>
319</div>
320</div>
321<h2>SYNOPSIS</h2>
322<div class="sectionbody">
323<div class="para"><p>git *</p></div>
324</div>
325<h2 id="_description">DESCRIPTION</h2>
326<div class="sectionbody">
327<div class="para"><p>This document attempts to write down and motivate some of the workflow
328elements used for <tt>git.git</tt> itself. Many ideas apply in general,
329though the full workflow is rarely required for smaller projects with
330fewer people involved.</p></div>
331<div class="para"><p>We formulate a set of <em>rules</em> for quick reference, while the prose
332tries to motivate each of them. Do not always take them literally;
333you should value good reasons for your actions higher than manpages
334such as this one.</p></div>
335</div>
336<h2 id="_separate_changes">SEPARATE CHANGES</h2>
337<div class="sectionbody">
338<div class="para"><p>As a general rule, you should try to split your changes into small
339logical steps, and commit each of them. They should be consistent,
340working independently of any later commits, pass the test suite, etc.
341This makes the review process much easier, and the history much more
342useful for later inspection and analysis, for example with
343<a href="git-blame.html">git-blame(1)</a> and <a href="git-bisect.html">git-bisect(1)</a>.</p></div>
344<div class="para"><p>To achieve this, try to split your work into small steps from the very
345beginning. It is always easier to squash a few commits together than
346to split one big commit into several. Don't be afraid of making too
347small or imperfect steps along the way. You can always go back later
348and edit the commits with <tt>git rebase --interactive</tt> before you
349publish them. You can use <tt>git stash save --keep-index</tt> to run the
350test suite independent of other uncommitted changes; see the EXAMPLES
351section of <a href="git-stash.html">git-stash(1)</a>.</p></div>
352</div>
353<h2 id="_managing_branches">MANAGING BRANCHES</h2>
354<div class="sectionbody">
355<div class="para"><p>There are two main tools that can be used to include changes from one
356branch on another: <a href="git-merge.html">git-merge(1)</a> and
357<a href="git-cherry-pick.html">git-cherry-pick(1)</a>.</p></div>
358<div class="para"><p>Merges have many advantages, so we try to solve as many problems as
359possible with merges alone. Cherry-picking is still occasionally
360useful; see "Merging upwards" below for an example.</p></div>
361<div class="para"><p>Most importantly, merging works at the branch level, while
362cherry-picking works at the commit level. This means that a merge can
363carry over the changes from 1, 10, or 1000 commits with equal ease,
364which in turn means the workflow scales much better to a large number
365of contributors (and contributions). Merges are also easier to
366understand because a merge commit is a "promise" that all changes from
367all its parents are now included.</p></div>
368<div class="para"><p>There is a tradeoff of course: merges require a more careful branch
369management. The following subsections discuss the important points.</p></div>
370<h3 id="_graduation">Graduation</h3><div style="clear:left"></div>
371<div class="para"><p>As a given feature goes from experimental to stable, it also
372"graduates" between the corresponding branches of the software.
373<tt>git.git</tt> uses the following <em>integration branches</em>:</p></div>
374<div class="ilist"><ul>
375<li>
376<p>
377<em>maint</em> tracks the commits that should go into the next "maintenance
378 release", i.e., update of the last released stable version;
379</p>
380</li>
381<li>
382<p>
383<em>master</em> tracks the commits that should go into the next release;
384</p>
385</li>
386<li>
387<p>
388<em>next</em> is intended as a testing branch for topics being tested for
389 stability for master.
390</p>
391</li>
392</ul></div>
393<div class="para"><p>There is a fourth official branch that is used slightly differently:</p></div>
394<div class="ilist"><ul>
395<li>
396<p>
397<em>pu</em> (proposed updates) is an integration branch for things that are
398 not quite ready for inclusion yet (see "Integration Branches"
399 below).
400</p>
401</li>
402</ul></div>
403<div class="para"><p>Each of the four branches is usually a direct descendant of the one
404above it.</p></div>
405<div class="para"><p>Conceptually, the feature enters at an unstable branch (usually <em>next</em>
406or <em>pu</em>), and "graduates" to <em>master</em> for the next release once it is
407considered stable enough.</p></div>
408<h3 id="_merging_upwards">Merging upwards</h3><div style="clear:left"></div>
409<div class="para"><p>The "downwards graduation" discussed above cannot be done by actually
410merging downwards, however, since that would merge <em>all</em> changes on
411the unstable branch into the stable one. Hence the following:</p></div>
412<div class="exampleblock">
413<div class="title">Rule: Merge upwards</div>
414<div class="exampleblock-content">
415<div class="para"><p>Always commit your fixes to the oldest supported branch that require
416them. Then (periodically) merge the integration branches upwards into each
417other.</p></div>
418</div></div>
419<div class="para"><p>This gives a very controlled flow of fixes. If you notice that you
420have applied a fix to e.g. <em>master</em> that is also required in <em>maint</em>,
421you will need to cherry-pick it (using <a href="git-cherry-pick.html">git-cherry-pick(1)</a>)
422downwards. This will happen a few times and is nothing to worry about
423unless you do it very frequently.</p></div>
424<h3 id="_topic_branches">Topic branches</h3><div style="clear:left"></div>
425<div class="para"><p>Any nontrivial feature will require several patches to implement, and
426may get extra bugfixes or improvements during its lifetime.</p></div>
427<div class="para"><p>Committing everything directly on the integration branches leads to many
428problems: Bad commits cannot be undone, so they must be reverted one
429by one, which creates confusing histories and further error potential
430when you forget to revert part of a group of changes. Working in
431parallel mixes up the changes, creating further confusion.</p></div>
432<div class="para"><p>Use of "topic branches" solves these problems. The name is pretty
433self explanatory, with a caveat that comes from the "merge upwards"
434rule above:</p></div>
435<div class="exampleblock">
436<div class="title">Rule: Topic branches</div>
437<div class="exampleblock-content">
438<div class="para"><p>Make a side branch for every topic (feature, bugfix, &#8230;). Fork it off
439at the oldest integration branch that you will eventually want to merge it
440into.</p></div>
441</div></div>
442<div class="para"><p>Many things can then be done very naturally:</p></div>
443<div class="ilist"><ul>
444<li>
445<p>
446To get the feature/bugfix into an integration branch, simply merge
447 it. If the topic has evolved further in the meantime, merge again.
448 (Note that you do not necessarily have to merge it to the oldest
449 integration branch first. For example, you can first merge a bugfix
450 to <em>next</em>, give it some testing time, and merge to <em>maint</em> when you
451 know it is stable.)
452</p>
453</li>
454<li>
455<p>
456If you find you need new features from the branch <em>other</em> to continue
457 working on your topic, merge <em>other</em> to <em>topic</em>. (However, do not
458 do this "just habitually", see below.)
459</p>
460</li>
461<li>
462<p>
463If you find you forked off the wrong branch and want to move it
464 "back in time", use <a href="git-rebase.html">git-rebase(1)</a>.
465</p>
466</li>
467</ul></div>
468<div class="para"><p>Note that the last point clashes with the other two: a topic that has
469been merged elsewhere should not be rebased. See the section on
470RECOVERING FROM UPSTREAM REBASE in <a href="git-rebase.html">git-rebase(1)</a>.</p></div>
471<div class="para"><p>We should point out that "habitually" (regularly for no real reason)
472merging an integration branch into your topics &#8212; and by extension,
473merging anything upstream into anything downstream on a regular basis
474&#8212; is frowned upon:</p></div>
475<div class="exampleblock">
476<div class="title">Rule: Merge to downstream only at well-defined points</div>
477<div class="exampleblock-content">
478<div class="para"><p>Do not merge to downstream except with a good reason: upstream API
479changes affect your branch; your branch no longer merges to upstream
480cleanly; etc.</p></div>
481</div></div>
482<div class="para"><p>Otherwise, the topic that was merged to suddenly contains more than a
483single (well-separated) change. The many resulting small merges will
484greatly clutter up history. Anyone who later investigates the history
485of a file will have to find out whether that merge affected the topic
486in development. An upstream might even inadvertently be merged into a
487"more stable" branch. And so on.</p></div>
488<h3 id="_throw_away_integration">Throw-away integration</h3><div style="clear:left"></div>
489<div class="para"><p>If you followed the last paragraph, you will now have many small topic
490branches, and occasionally wonder how they interact. Perhaps the
491result of merging them does not even work? But on the other hand, we
492want to avoid merging them anywhere "stable" because such merges
493cannot easily be undone.</p></div>
494<div class="para"><p>The solution, of course, is to make a merge that we can undo: merge
495into a throw-away branch.</p></div>
496<div class="exampleblock">
497<div class="title">Rule: Throw-away integration branches</div>
498<div class="exampleblock-content">
499<div class="para"><p>To test the interaction of several topics, merge them into a
500throw-away branch. You must never base any work on such a branch!</p></div>
501</div></div>
502<div class="para"><p>If you make it (very) clear that this branch is going to be deleted
503right after the testing, you can even publish this branch, for example
504to give the testers a chance to work with it, or other developers a
505chance to see if their in-progress work will be compatible. <tt>git.git</tt>
506has such an official throw-away integration branch called <em>pu</em>.</p></div>
507</div>
508<h2 id="_distributed_workflows">DISTRIBUTED WORKFLOWS</h2>
509<div class="sectionbody">
510<div class="para"><p>After the last section, you should know how to manage topics. In
511general, you will not be the only person working on the project, so
512you will have to share your work.</p></div>
513<div class="para"><p>Roughly speaking, there are two important workflows: merge and patch.
514The important difference is that the merge workflow can propagate full
515history, including merges, while patches cannot. Both workflows can
516be used in parallel: in <tt>git.git</tt>, only subsystem maintainers use
517the merge workflow, while everyone else sends patches.</p></div>
518<div class="para"><p>Note that the maintainer(s) may impose restrictions, such as
519"Signed-off-by" requirements, that all commits/patches submitted for
520inclusion must adhere to. Consult your project's documentation for
521more information.</p></div>
522<h3 id="_merge_workflow">Merge workflow</h3><div style="clear:left"></div>
523<div class="para"><p>The merge workflow works by copying branches between upstream and
524downstream. Upstream can merge contributions into the official
525history; downstream base their work on the official history.</p></div>
526<div class="para"><p>There are three main tools that can be used for this:</p></div>
527<div class="ilist"><ul>
528<li>
529<p>
530<a href="git-push.html">git-push(1)</a> copies your branches to a remote repository,
531 usually to one that can be read by all involved parties;
532</p>
533</li>
534<li>
535<p>
536<a href="git-fetch.html">git-fetch(1)</a> that copies remote branches to your repository;
537 and
538</p>
539</li>
540<li>
541<p>
542<a href="git-pull.html">git-pull(1)</a> that does fetch and merge in one go.
543</p>
544</li>
545</ul></div>
546<div class="para"><p>Note the last point. Do <em>not</em> use <em>git-pull</em> unless you actually want
547to merge the remote branch.</p></div>
548<div class="para"><p>Getting changes out is easy:</p></div>
549<div class="exampleblock">
550<div class="title">Recipe: Push/pull: Publishing branches/topics</div>
551<div class="exampleblock-content">
552<div class="para"><p><tt>git push &lt;remote&gt; &lt;branch&gt;</tt> and tell everyone where they can fetch
553from.</p></div>
554</div></div>
555<div class="para"><p>You will still have to tell people by other means, such as mail. (Git
Junio C Hamano845880c2008-10-21 19:04:45556provides the <a href="git-request-pull.html">git-request-pull(1)</a> to send preformatted pull
Junio C Hamano7d06a8a2008-10-20 05:42:33557requests to upstream maintainers to simplify this task.)</p></div>
558<div class="para"><p>If you just want to get the newest copies of the integration branches,
559staying up to date is easy too:</p></div>
560<div class="exampleblock">
561<div class="title">Recipe: Push/pull: Staying up to date</div>
562<div class="exampleblock-content">
563<div class="para"><p>Use <tt>git fetch &lt;remote&gt;</tt> or <tt>git remote update</tt> to stay up to date.</p></div>
564</div></div>
565<div class="para"><p>Then simply fork your topic branches from the stable remotes as
566explained earlier.</p></div>
567<div class="para"><p>If you are a maintainer and would like to merge other people's topic
568branches to the integration branches, they will typically send a
569request to do so by mail. Such a request looks like</p></div>
570<div class="listingblock">
571<div class="content">
572<pre><tt>Please pull from
573 &lt;url&gt; &lt;branch&gt;</tt></pre>
574</div></div>
575<div class="para"><p>In that case, <em>git-pull</em> can do the fetch and merge in one go, as
576follows.</p></div>
577<div class="exampleblock">
578<div class="title">Recipe: Push/pull: Merging remote topics</div>
579<div class="exampleblock-content">
580<div class="para"><p><tt>git pull &lt;url&gt; &lt;branch&gt;</tt></p></div>
581</div></div>
582<div class="para"><p>Occasionally, the maintainer may get merge conflicts when he tries to
583pull changes from downstream. In this case, he can ask downstream to
584do the merge and resolve the conflicts themselves (perhaps they will
585know better how to resolve them). It is one of the rare cases where
586downstream <em>should</em> merge from upstream.</p></div>
587<h3 id="_patch_workflow">Patch workflow</h3><div style="clear:left"></div>
588<div class="para"><p>If you are a contributor that sends changes upstream in the form of
589emails, you should use topic branches as usual (see above). Then use
590<a href="git-format-patch.html">git-format-patch(1)</a> to generate the corresponding emails
591(highly recommended over manually formatting them because it makes the
592maintainer's life easier).</p></div>
593<div class="exampleblock">
594<div class="title">Recipe: format-patch/am: Publishing branches/topics</div>
595<div class="exampleblock-content">
596<div class="ilist"><ul>
597<li>
598<p>
599<tt>git format-patch -M upstream..topic</tt> to turn them into preformatted
600 patch files
601</p>
602</li>
603<li>
604<p>
605<tt>git send-email --to=&lt;recipient&gt; &lt;patches&gt;</tt>
606</p>
607</li>
608</ul></div>
609</div></div>
610<div class="para"><p>See the <a href="git-format-patch.html">git-format-patch(1)</a> and <a href="git-send-email.html">git-send-email(1)</a>
611manpages for further usage notes.</p></div>
612<div class="para"><p>If the maintainer tells you that your patch no longer applies to the
613current upstream, you will have to rebase your topic (you cannot use a
614merge because you cannot format-patch merges):</p></div>
615<div class="exampleblock">
616<div class="title">Recipe: format-patch/am: Keeping topics up to date</div>
617<div class="exampleblock-content">
618<div class="para"><p><tt>git pull --rebase &lt;url&gt; &lt;branch&gt;</tt></p></div>
619</div></div>
620<div class="para"><p>You can then fix the conflicts during the rebase. Presumably you have
621not published your topic other than by mail, so rebasing it is not a
622problem.</p></div>
623<div class="para"><p>If you receive such a patch series (as maintainer, or perhaps as a
624reader of the mailing list it was sent to), save the mails to files,
625create a new topic branch and use <em>git-am</em> to import the commits:</p></div>
626<div class="exampleblock">
627<div class="title">Recipe: format-patch/am: Importing patches</div>
628<div class="exampleblock-content">
629<div class="para"><p><tt>git am &lt; patch</tt></p></div>
630</div></div>
631<div class="para"><p>One feature worth pointing out is the three-way merge, which can help
632if you get conflicts: <tt>git am -3</tt> will use index information contained
633in patches to figure out the merge base. See <a href="git-am.html">git-am(1)</a> for
634other options.</p></div>
635</div>
636<h2 id="_see_also">SEE ALSO</h2>
637<div class="sectionbody">
638<div class="para"><p><a href="gittutorial.html">gittutorial(7)</a>,
639<a href="git-push.html">git-push(1)</a>,
640<a href="git-pull.html">git-pull(1)</a>,
641<a href="git-merge.html">git-merge(1)</a>,
642<a href="git-rebase.html">git-rebase(1)</a>,
643<a href="git-format-patch.html">git-format-patch(1)</a>,
644<a href="git-send-email.html">git-send-email(1)</a>,
645<a href="git-am.html">git-am(1)</a></p></div>
646</div>
647<h2 id="_git">GIT</h2>
648<div class="sectionbody">
649<div class="para"><p>Part of the <a href="git.html">git(1)</a> suite.</p></div>
650</div>
651<div id="footer">
652<div id="footer-text">
Junio C Hamano9572e922009-04-02 06:52:03653Last updated 2009-04-02 06:50:12 UTC
Junio C Hamano7d06a8a2008-10-20 05:42:33654</div>
655</div>
656</body>
657</html>