Autogenerated HTML docs for v1.7.6-396-ge0613
[git/jnareb-git.git] / gitworkflows.html
blob950589c39f82c0bfd2c7bd0fbd3e886f5911cb93
1 <!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.4.5" />
7 <title>gitworkflows(7)</title>
8 <style type="text/css">
9 /* Debug borders */
10 p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
12 border: 1px solid red;
16 body {
17 margin: 1em 5% 1em 5%;
20 a {
21 color: blue;
22 text-decoration: underline;
24 a:visited {
25 color: fuchsia;
28 em {
29 font-style: italic;
30 color: navy;
33 strong {
34 font-weight: bold;
35 color: #083194;
38 tt {
39 color: navy;
42 h1, h2, h3, h4, h5, h6 {
43 color: #527bbd;
44 font-family: sans-serif;
45 margin-top: 1.2em;
46 margin-bottom: 0.5em;
47 line-height: 1.3;
50 h1, h2, h3 {
51 border-bottom: 2px solid silver;
53 h2 {
54 padding-top: 0.5em;
56 h3 {
57 float: left;
59 h3 + * {
60 clear: left;
63 div.sectionbody {
64 font-family: serif;
65 margin-left: 0;
68 hr {
69 border: 1px solid silver;
72 p {
73 margin-top: 0.5em;
74 margin-bottom: 0.5em;
77 ul, ol, li > p {
78 margin-top: 0;
81 pre {
82 padding: 0;
83 margin: 0;
86 span#author {
87 color: #527bbd;
88 font-family: sans-serif;
89 font-weight: bold;
90 font-size: 1.1em;
92 span#email {
94 span#revnumber, span#revdate, span#revremark {
95 font-family: sans-serif;
98 div#footer {
99 font-family: sans-serif;
100 font-size: small;
101 border-top: 2px solid silver;
102 padding-top: 0.5em;
103 margin-top: 4.0em;
105 div#footer-text {
106 float: left;
107 padding-bottom: 0.5em;
109 div#footer-badges {
110 float: right;
111 padding-bottom: 0.5em;
114 div#preamble {
115 margin-top: 1.5em;
116 margin-bottom: 1.5em;
118 div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
119 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
120 div.admonitionblock {
121 margin-top: 1.5em;
122 margin-bottom: 1.5em;
124 div.admonitionblock {
125 margin-top: 2.5em;
126 margin-bottom: 2.5em;
129 div.content { /* Block element content. */
130 padding: 0;
133 /* Block element titles. */
134 div.title, caption.title {
135 color: #527bbd;
136 font-family: sans-serif;
137 font-weight: bold;
138 text-align: left;
139 margin-top: 1.0em;
140 margin-bottom: 0.5em;
142 div.title + * {
143 margin-top: 0;
146 td div.title:first-child {
147 margin-top: 0.0em;
149 div.content div.title:first-child {
150 margin-top: 0.0em;
152 div.content + div.title {
153 margin-top: 0.0em;
156 div.sidebarblock > div.content {
157 background: #ffffee;
158 border: 1px solid silver;
159 padding: 0.5em;
162 div.listingblock > div.content {
163 border: 1px solid silver;
164 background: #f4f4f4;
165 padding: 0.5em;
168 div.quoteblock {
169 padding-left: 2.0em;
170 margin-right: 10%;
172 div.quoteblock > div.attribution {
173 padding-top: 0.5em;
174 text-align: right;
177 div.verseblock {
178 padding-left: 2.0em;
179 margin-right: 10%;
181 div.verseblock > div.content {
182 white-space: pre;
184 div.verseblock > div.attribution {
185 padding-top: 0.75em;
186 text-align: left;
188 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
189 div.verseblock + div.attribution {
190 text-align: left;
193 div.admonitionblock .icon {
194 vertical-align: top;
195 font-size: 1.1em;
196 font-weight: bold;
197 text-decoration: underline;
198 color: #527bbd;
199 padding-right: 0.5em;
201 div.admonitionblock td.content {
202 padding-left: 0.5em;
203 border-left: 2px solid silver;
206 div.exampleblock > div.content {
207 border-left: 2px solid silver;
208 padding: 0.5em;
211 div.imageblock div.content { padding-left: 0; }
212 span.image img { border-style: none; }
213 a.image:visited { color: white; }
215 dl {
216 margin-top: 0.8em;
217 margin-bottom: 0.8em;
219 dt {
220 margin-top: 0.5em;
221 margin-bottom: 0;
222 font-style: normal;
223 color: navy;
225 dd > *:first-child {
226 margin-top: 0.1em;
229 ul, ol {
230 list-style-position: outside;
232 ol.arabic {
233 list-style-type: decimal;
235 ol.loweralpha {
236 list-style-type: lower-alpha;
238 ol.upperalpha {
239 list-style-type: upper-alpha;
241 ol.lowerroman {
242 list-style-type: lower-roman;
244 ol.upperroman {
245 list-style-type: upper-roman;
248 div.compact ul, div.compact ol,
249 div.compact p, div.compact p,
250 div.compact div, div.compact div {
251 margin-top: 0.1em;
252 margin-bottom: 0.1em;
255 div.tableblock > table {
256 border: 3px solid #527bbd;
258 thead {
259 font-family: sans-serif;
260 font-weight: bold;
262 tfoot {
263 font-weight: bold;
265 td > div.verse {
266 white-space: pre;
268 p.table {
269 margin-top: 0;
271 /* Because the table frame attribute is overriden by CSS in most browsers. */
272 div.tableblock > table[frame="void"] {
273 border-style: none;
275 div.tableblock > table[frame="hsides"] {
276 border-left-style: none;
277 border-right-style: none;
279 div.tableblock > table[frame="vsides"] {
280 border-top-style: none;
281 border-bottom-style: none;
285 div.hdlist {
286 margin-top: 0.8em;
287 margin-bottom: 0.8em;
289 div.hdlist tr {
290 padding-bottom: 15px;
292 dt.hdlist1.strong, td.hdlist1.strong {
293 font-weight: bold;
295 td.hdlist1 {
296 vertical-align: top;
297 font-style: normal;
298 padding-right: 0.8em;
299 color: navy;
301 td.hdlist2 {
302 vertical-align: top;
304 div.hdlist.compact tr {
305 margin: 0;
306 padding-bottom: 0;
309 .comment {
310 background: yellow;
313 @media print {
314 div#footer-badges { display: none; }
317 div#toctitle {
318 color: #527bbd;
319 font-family: sans-serif;
320 font-size: 1.1em;
321 font-weight: bold;
322 margin-top: 1.0em;
323 margin-bottom: 0.1em;
326 div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
327 margin-top: 0;
328 margin-bottom: 0;
330 div.toclevel2 {
331 margin-left: 2em;
332 font-size: 0.9em;
334 div.toclevel3 {
335 margin-left: 4em;
336 font-size: 0.9em;
338 div.toclevel4 {
339 margin-left: 6em;
340 font-size: 0.9em;
342 /* Overrides for manpage documents */
343 h1 {
344 padding-top: 0.5em;
345 padding-bottom: 0.5em;
346 border-top: 2px solid silver;
347 border-bottom: 2px solid silver;
349 h2 {
350 border-style: none;
352 div.sectionbody {
353 margin-left: 5%;
356 @media print {
357 div#toc { display: none; }
360 /* Workarounds for IE6's broken and incomplete CSS2. */
362 div.sidebar-content {
363 background: #ffffee;
364 border: 1px solid silver;
365 padding: 0.5em;
367 div.sidebar-title, div.image-title {
368 color: #527bbd;
369 font-family: sans-serif;
370 font-weight: bold;
371 margin-top: 0.0em;
372 margin-bottom: 0.5em;
375 div.listingblock div.content {
376 border: 1px solid silver;
377 background: #f4f4f4;
378 padding: 0.5em;
381 div.quoteblock-attribution {
382 padding-top: 0.5em;
383 text-align: right;
386 div.verseblock-content {
387 white-space: pre;
389 div.verseblock-attribution {
390 padding-top: 0.75em;
391 text-align: left;
394 div.exampleblock-content {
395 border-left: 2px solid silver;
396 padding-left: 0.5em;
399 /* IE6 sets dynamically generated links as visited. */
400 div#toc a:visited { color: blue; }
401 </style>
402 </head>
403 <body>
404 <div id="header">
405 <h1>
406 gitworkflows(7) Manual Page
407 </h1>
408 <h2>NAME</h2>
409 <div class="sectionbody">
410 <p>gitworkflows -
411 An overview of recommended workflows with git
412 </p>
413 </div>
414 </div>
415 <h2 id="_synopsis">SYNOPSIS</h2>
416 <div class="sectionbody">
417 <div class="verseblock">
418 <div class="verseblock-content">git *</div>
419 <div class="verseblock-attribution">
420 </div></div>
421 </div>
422 <h2 id="_description">DESCRIPTION</h2>
423 <div class="sectionbody">
424 <div class="paragraph"><p>This document attempts to write down and motivate some of the workflow
425 elements used for <tt>git.git</tt> itself. Many ideas apply in general,
426 though the full workflow is rarely required for smaller projects with
427 fewer people involved.</p></div>
428 <div class="paragraph"><p>We formulate a set of <em>rules</em> for quick reference, while the prose
429 tries to motivate each of them. Do not always take them literally;
430 you should value good reasons for your actions higher than manpages
431 such as this one.</p></div>
432 </div>
433 <h2 id="_separate_changes">SEPARATE CHANGES</h2>
434 <div class="sectionbody">
435 <div class="paragraph"><p>As a general rule, you should try to split your changes into small
436 logical steps, and commit each of them. They should be consistent,
437 working independently of any later commits, pass the test suite, etc.
438 This makes the review process much easier, and the history much more
439 useful for later inspection and analysis, for example with
440 <a href="git-blame.html">git-blame(1)</a> and <a href="git-bisect.html">git-bisect(1)</a>.</p></div>
441 <div class="paragraph"><p>To achieve this, try to split your work into small steps from the very
442 beginning. It is always easier to squash a few commits together than
443 to split one big commit into several. Don&#8217;t be afraid of making too
444 small or imperfect steps along the way. You can always go back later
445 and edit the commits with <tt>git rebase --interactive</tt> before you
446 publish them. You can use <tt>git stash save --keep-index</tt> to run the
447 test suite independent of other uncommitted changes; see the EXAMPLES
448 section of <a href="git-stash.html">git-stash(1)</a>.</p></div>
449 </div>
450 <h2 id="_managing_branches">MANAGING BRANCHES</h2>
451 <div class="sectionbody">
452 <div class="paragraph"><p>There are two main tools that can be used to include changes from one
453 branch on another: <a href="git-merge.html">git-merge(1)</a> and
454 <a href="git-cherry-pick.html">git-cherry-pick(1)</a>.</p></div>
455 <div class="paragraph"><p>Merges have many advantages, so we try to solve as many problems as
456 possible with merges alone. Cherry-picking is still occasionally
457 useful; see "Merging upwards" below for an example.</p></div>
458 <div class="paragraph"><p>Most importantly, merging works at the branch level, while
459 cherry-picking works at the commit level. This means that a merge can
460 carry over the changes from 1, 10, or 1000 commits with equal ease,
461 which in turn means the workflow scales much better to a large number
462 of contributors (and contributions). Merges are also easier to
463 understand because a merge commit is a "promise" that all changes from
464 all its parents are now included.</p></div>
465 <div class="paragraph"><p>There is a tradeoff of course: merges require a more careful branch
466 management. The following subsections discuss the important points.</p></div>
467 <h3 id="_graduation">Graduation</h3><div style="clear:left"></div>
468 <div class="paragraph"><p>As a given feature goes from experimental to stable, it also
469 "graduates" between the corresponding branches of the software.
470 <tt>git.git</tt> uses the following <em>integration branches</em>:</p></div>
471 <div class="ulist"><ul>
472 <li>
474 <em>maint</em> tracks the commits that should go into the next "maintenance
475 release", i.e., update of the last released stable version;
476 </p>
477 </li>
478 <li>
480 <em>master</em> tracks the commits that should go into the next release;
481 </p>
482 </li>
483 <li>
485 <em>next</em> is intended as a testing branch for topics being tested for
486 stability for master.
487 </p>
488 </li>
489 </ul></div>
490 <div class="paragraph"><p>There is a fourth official branch that is used slightly differently:</p></div>
491 <div class="ulist"><ul>
492 <li>
494 <em>pu</em> (proposed updates) is an integration branch for things that are
495 not quite ready for inclusion yet (see "Integration Branches"
496 below).
497 </p>
498 </li>
499 </ul></div>
500 <div class="paragraph"><p>Each of the four branches is usually a direct descendant of the one
501 above it.</p></div>
502 <div class="paragraph"><p>Conceptually, the feature enters at an unstable branch (usually <em>next</em>
503 or <em>pu</em>), and "graduates" to <em>master</em> for the next release once it is
504 considered stable enough.</p></div>
505 <h3 id="_merging_upwards">Merging upwards</h3><div style="clear:left"></div>
506 <div class="paragraph"><p>The "downwards graduation" discussed above cannot be done by actually
507 merging downwards, however, since that would merge <em>all</em> changes on
508 the unstable branch into the stable one. Hence the following:</p></div>
509 <div class="exampleblock">
510 <div class="title">Rule: Merge upwards</div>
511 <div class="exampleblock-content">
512 <div class="paragraph"><p>Always commit your fixes to the oldest supported branch that require
513 them. Then (periodically) merge the integration branches upwards into each
514 other.</p></div>
515 </div></div>
516 <div class="paragraph"><p>This gives a very controlled flow of fixes. If you notice that you
517 have applied a fix to e.g. <em>master</em> that is also required in <em>maint</em>,
518 you will need to cherry-pick it (using <a href="git-cherry-pick.html">git-cherry-pick(1)</a>)
519 downwards. This will happen a few times and is nothing to worry about
520 unless you do it very frequently.</p></div>
521 <h3 id="_topic_branches">Topic branches</h3><div style="clear:left"></div>
522 <div class="paragraph"><p>Any nontrivial feature will require several patches to implement, and
523 may get extra bugfixes or improvements during its lifetime.</p></div>
524 <div class="paragraph"><p>Committing everything directly on the integration branches leads to many
525 problems: Bad commits cannot be undone, so they must be reverted one
526 by one, which creates confusing histories and further error potential
527 when you forget to revert part of a group of changes. Working in
528 parallel mixes up the changes, creating further confusion.</p></div>
529 <div class="paragraph"><p>Use of "topic branches" solves these problems. The name is pretty
530 self explanatory, with a caveat that comes from the "merge upwards"
531 rule above:</p></div>
532 <div class="exampleblock">
533 <div class="title">Rule: Topic branches</div>
534 <div class="exampleblock-content">
535 <div class="paragraph"><p>Make a side branch for every topic (feature, bugfix, &#8230;). Fork it off
536 at the oldest integration branch that you will eventually want to merge it
537 into.</p></div>
538 </div></div>
539 <div class="paragraph"><p>Many things can then be done very naturally:</p></div>
540 <div class="ulist"><ul>
541 <li>
543 To get the feature/bugfix into an integration branch, simply merge
544 it. If the topic has evolved further in the meantime, merge again.
545 (Note that you do not necessarily have to merge it to the oldest
546 integration branch first. For example, you can first merge a bugfix
547 to <em>next</em>, give it some testing time, and merge to <em>maint</em> when you
548 know it is stable.)
549 </p>
550 </li>
551 <li>
553 If you find you need new features from the branch <em>other</em> to continue
554 working on your topic, merge <em>other</em> to <em>topic</em>. (However, do not
555 do this "just habitually", see below.)
556 </p>
557 </li>
558 <li>
560 If you find you forked off the wrong branch and want to move it
561 "back in time", use <a href="git-rebase.html">git-rebase(1)</a>.
562 </p>
563 </li>
564 </ul></div>
565 <div class="paragraph"><p>Note that the last point clashes with the other two: a topic that has
566 been merged elsewhere should not be rebased. See the section on
567 RECOVERING FROM UPSTREAM REBASE in <a href="git-rebase.html">git-rebase(1)</a>.</p></div>
568 <div class="paragraph"><p>We should point out that "habitually" (regularly for no real reason)
569 merging an integration branch into your topics&#8201;&#8212;&#8201;and by extension,
570 merging anything upstream into anything downstream on a regular basis&#8201;&#8212;&#8201;is frowned upon:</p></div>
571 <div class="exampleblock">
572 <div class="title">Rule: Merge to downstream only at well-defined points</div>
573 <div class="exampleblock-content">
574 <div class="paragraph"><p>Do not merge to downstream except with a good reason: upstream API
575 changes affect your branch; your branch no longer merges to upstream
576 cleanly; etc.</p></div>
577 </div></div>
578 <div class="paragraph"><p>Otherwise, the topic that was merged to suddenly contains more than a
579 single (well-separated) change. The many resulting small merges will
580 greatly clutter up history. Anyone who later investigates the history
581 of a file will have to find out whether that merge affected the topic
582 in development. An upstream might even inadvertently be merged into a
583 "more stable" branch. And so on.</p></div>
584 <h3 id="_throw_away_integration">Throw-away integration</h3><div style="clear:left"></div>
585 <div class="paragraph"><p>If you followed the last paragraph, you will now have many small topic
586 branches, and occasionally wonder how they interact. Perhaps the
587 result of merging them does not even work? But on the other hand, we
588 want to avoid merging them anywhere "stable" because such merges
589 cannot easily be undone.</p></div>
590 <div class="paragraph"><p>The solution, of course, is to make a merge that we can undo: merge
591 into a throw-away branch.</p></div>
592 <div class="exampleblock">
593 <div class="title">Rule: Throw-away integration branches</div>
594 <div class="exampleblock-content">
595 <div class="paragraph"><p>To test the interaction of several topics, merge them into a
596 throw-away branch. You must never base any work on such a branch!</p></div>
597 </div></div>
598 <div class="paragraph"><p>If you make it (very) clear that this branch is going to be deleted
599 right after the testing, you can even publish this branch, for example
600 to give the testers a chance to work with it, or other developers a
601 chance to see if their in-progress work will be compatible. <tt>git.git</tt>
602 has such an official throw-away integration branch called <em>pu</em>.</p></div>
603 <h3 id="_branch_management_for_a_release">Branch management for a release</h3><div style="clear:left"></div>
604 <div class="paragraph"><p>Assuming you are using the merge approach discussed above, when you
605 are releasing your project you will need to do some additional branch
606 management work.</p></div>
607 <div class="paragraph"><p>A feature release is created from the <em>master</em> branch, since <em>master</em>
608 tracks the commits that should go into the next feature release.</p></div>
609 <div class="paragraph"><p>The <em>master</em> branch is supposed to be a superset of <em>maint</em>. If this
610 condition does not hold, then <em>maint</em> contains some commits that
611 are not included on <em>master</em>. The fixes represented by those commits
612 will therefore not be included in your feature release.</p></div>
613 <div class="paragraph"><p>To verify that <em>master</em> is indeed a superset of <em>maint</em>, use git log:</p></div>
614 <div class="exampleblock">
615 <div class="title">Recipe: Verify <em>master</em> is a superset of <em>maint</em></div>
616 <div class="exampleblock-content">
617 <div class="paragraph"><p><tt>git log master..maint</tt></p></div>
618 </div></div>
619 <div class="paragraph"><p>This command should not list any commits. Otherwise, check out
620 <em>master</em> and merge <em>maint</em> into it.</p></div>
621 <div class="paragraph"><p>Now you can proceed with the creation of the feature release. Apply a
622 tag to the tip of <em>master</em> indicating the release version:</p></div>
623 <div class="exampleblock">
624 <div class="title">Recipe: Release tagging</div>
625 <div class="exampleblock-content">
626 <div class="paragraph"><p><tt>git tag -s -m "GIT X.Y.Z" vX.Y.Z master</tt></p></div>
627 </div></div>
628 <div class="paragraph"><p>You need to push the new tag to a public git server (see
629 "DISTRIBUTED WORKFLOWS" below). This makes the tag available to
630 others tracking your project. The push could also trigger a
631 post-update hook to perform release-related items such as building
632 release tarballs and preformatted documentation pages.</p></div>
633 <div class="paragraph"><p>Similarly, for a maintenance release, <em>maint</em> is tracking the commits
634 to be released. Therefore, in the steps above simply tag and push
635 <em>maint</em> rather than <em>master</em>.</p></div>
636 <h3 id="_maintenance_branch_management_after_a_feature_release">Maintenance branch management after a feature release</h3><div style="clear:left"></div>
637 <div class="paragraph"><p>After a feature release, you need to manage your maintenance branches.</p></div>
638 <div class="paragraph"><p>First, if you wish to continue to release maintenance fixes for the
639 feature release made before the recent one, then you must create
640 another branch to track commits for that previous release.</p></div>
641 <div class="paragraph"><p>To do this, the current maintenance branch is copied to another branch
642 named with the previous release version number (e.g. maint-X.Y.(Z-1)
643 where X.Y.Z is the current release).</p></div>
644 <div class="exampleblock">
645 <div class="title">Recipe: Copy maint</div>
646 <div class="exampleblock-content">
647 <div class="paragraph"><p><tt>git branch maint-X.Y.(Z-1) maint</tt></p></div>
648 </div></div>
649 <div class="paragraph"><p>The <em>maint</em> branch should now be fast-forwarded to the newly released
650 code so that maintenance fixes can be tracked for the current release:</p></div>
651 <div class="exampleblock">
652 <div class="title">Recipe: Update maint to new release</div>
653 <div class="exampleblock-content">
654 <div class="ulist"><ul>
655 <li>
657 <tt>git checkout maint</tt>
658 </p>
659 </li>
660 <li>
662 <tt>git merge --ff-only master</tt>
663 </p>
664 </li>
665 </ul></div>
666 </div></div>
667 <div class="paragraph"><p>If the merge fails because it is not a fast-forward, then it is
668 possible some fixes on <em>maint</em> were missed in the feature release.
669 This will not happen if the content of the branches was verified as
670 described in the previous section.</p></div>
671 <h3 id="_branch_management_for_next_and_pu_after_a_feature_release">Branch management for next and pu after a feature release</h3><div style="clear:left"></div>
672 <div class="paragraph"><p>After a feature release, the integration branch <em>next</em> may optionally be
673 rewound and rebuilt from the tip of <em>master</em> using the surviving
674 topics on <em>next</em>:</p></div>
675 <div class="exampleblock">
676 <div class="title">Recipe: Rewind and rebuild next</div>
677 <div class="exampleblock-content">
678 <div class="ulist"><ul>
679 <li>
681 <tt>git checkout next</tt>
682 </p>
683 </li>
684 <li>
686 <tt>git reset --hard master</tt>
687 </p>
688 </li>
689 <li>
691 <tt>git merge ai/topic_in_next1</tt>
692 </p>
693 </li>
694 <li>
696 <tt>git merge ai/topic_in_next2</tt>
697 </p>
698 </li>
699 <li>
701 &#8230;
702 </p>
703 </li>
704 </ul></div>
705 </div></div>
706 <div class="paragraph"><p>The advantage of doing this is that the history of <em>next</em> will be
707 clean. For example, some topics merged into <em>next</em> may have initially
708 looked promising, but were later found to be undesirable or premature.
709 In such a case, the topic is reverted out of <em>next</em> but the fact
710 remains in the history that it was once merged and reverted. By
711 recreating <em>next</em>, you give another incarnation of such topics a clean
712 slate to retry, and a feature release is a good point in history to do
713 so.</p></div>
714 <div class="paragraph"><p>If you do this, then you should make a public announcement indicating
715 that <em>next</em> was rewound and rebuilt.</p></div>
716 <div class="paragraph"><p>The same rewind and rebuild process may be followed for <em>pu</em>. A public
717 announcement is not necessary since <em>pu</em> is a throw-away branch, as
718 described above.</p></div>
719 </div>
720 <h2 id="_distributed_workflows">DISTRIBUTED WORKFLOWS</h2>
721 <div class="sectionbody">
722 <div class="paragraph"><p>After the last section, you should know how to manage topics. In
723 general, you will not be the only person working on the project, so
724 you will have to share your work.</p></div>
725 <div class="paragraph"><p>Roughly speaking, there are two important workflows: merge and patch.
726 The important difference is that the merge workflow can propagate full
727 history, including merges, while patches cannot. Both workflows can
728 be used in parallel: in <tt>git.git</tt>, only subsystem maintainers use
729 the merge workflow, while everyone else sends patches.</p></div>
730 <div class="paragraph"><p>Note that the maintainer(s) may impose restrictions, such as
731 "Signed-off-by" requirements, that all commits/patches submitted for
732 inclusion must adhere to. Consult your project&#8217;s documentation for
733 more information.</p></div>
734 <h3 id="_merge_workflow">Merge workflow</h3><div style="clear:left"></div>
735 <div class="paragraph"><p>The merge workflow works by copying branches between upstream and
736 downstream. Upstream can merge contributions into the official
737 history; downstream base their work on the official history.</p></div>
738 <div class="paragraph"><p>There are three main tools that can be used for this:</p></div>
739 <div class="ulist"><ul>
740 <li>
742 <a href="git-push.html">git-push(1)</a> copies your branches to a remote repository,
743 usually to one that can be read by all involved parties;
744 </p>
745 </li>
746 <li>
748 <a href="git-fetch.html">git-fetch(1)</a> that copies remote branches to your repository;
750 </p>
751 </li>
752 <li>
754 <a href="git-pull.html">git-pull(1)</a> that does fetch and merge in one go.
755 </p>
756 </li>
757 </ul></div>
758 <div class="paragraph"><p>Note the last point. Do <em>not</em> use <em>git pull</em> unless you actually want
759 to merge the remote branch.</p></div>
760 <div class="paragraph"><p>Getting changes out is easy:</p></div>
761 <div class="exampleblock">
762 <div class="title">Recipe: Push/pull: Publishing branches/topics</div>
763 <div class="exampleblock-content">
764 <div class="paragraph"><p><tt>git push &lt;remote&gt; &lt;branch&gt;</tt> and tell everyone where they can fetch
765 from.</p></div>
766 </div></div>
767 <div class="paragraph"><p>You will still have to tell people by other means, such as mail. (Git
768 provides the <a href="git-request-pull.html">git-request-pull(1)</a> to send preformatted pull
769 requests to upstream maintainers to simplify this task.)</p></div>
770 <div class="paragraph"><p>If you just want to get the newest copies of the integration branches,
771 staying up to date is easy too:</p></div>
772 <div class="exampleblock">
773 <div class="title">Recipe: Push/pull: Staying up to date</div>
774 <div class="exampleblock-content">
775 <div class="paragraph"><p>Use <tt>git fetch &lt;remote&gt;</tt> or <tt>git remote update</tt> to stay up to date.</p></div>
776 </div></div>
777 <div class="paragraph"><p>Then simply fork your topic branches from the stable remotes as
778 explained earlier.</p></div>
779 <div class="paragraph"><p>If you are a maintainer and would like to merge other people&#8217;s topic
780 branches to the integration branches, they will typically send a
781 request to do so by mail. Such a request looks like</p></div>
782 <div class="listingblock">
783 <div class="content">
784 <pre><tt>Please pull from
785 &lt;url&gt; &lt;branch&gt;</tt></pre>
786 </div></div>
787 <div class="paragraph"><p>In that case, <em>git pull</em> can do the fetch and merge in one go, as
788 follows.</p></div>
789 <div class="exampleblock">
790 <div class="title">Recipe: Push/pull: Merging remote topics</div>
791 <div class="exampleblock-content">
792 <div class="paragraph"><p><tt>git pull &lt;url&gt; &lt;branch&gt;</tt></p></div>
793 </div></div>
794 <div class="paragraph"><p>Occasionally, the maintainer may get merge conflicts when he tries to
795 pull changes from downstream. In this case, he can ask downstream to
796 do the merge and resolve the conflicts themselves (perhaps they will
797 know better how to resolve them). It is one of the rare cases where
798 downstream <em>should</em> merge from upstream.</p></div>
799 <h3 id="_patch_workflow">Patch workflow</h3><div style="clear:left"></div>
800 <div class="paragraph"><p>If you are a contributor that sends changes upstream in the form of
801 emails, you should use topic branches as usual (see above). Then use
802 <a href="git-format-patch.html">git-format-patch(1)</a> to generate the corresponding emails
803 (highly recommended over manually formatting them because it makes the
804 maintainer&#8217;s life easier).</p></div>
805 <div class="exampleblock">
806 <div class="title">Recipe: format-patch/am: Publishing branches/topics</div>
807 <div class="exampleblock-content">
808 <div class="ulist"><ul>
809 <li>
811 <tt>git format-patch -M upstream..topic</tt> to turn them into preformatted
812 patch files
813 </p>
814 </li>
815 <li>
817 <tt>git send-email --to=&lt;recipient&gt; &lt;patches&gt;</tt>
818 </p>
819 </li>
820 </ul></div>
821 </div></div>
822 <div class="paragraph"><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>
823 manpages for further usage notes.</p></div>
824 <div class="paragraph"><p>If the maintainer tells you that your patch no longer applies to the
825 current upstream, you will have to rebase your topic (you cannot use a
826 merge because you cannot format-patch merges):</p></div>
827 <div class="exampleblock">
828 <div class="title">Recipe: format-patch/am: Keeping topics up to date</div>
829 <div class="exampleblock-content">
830 <div class="paragraph"><p><tt>git pull --rebase &lt;url&gt; &lt;branch&gt;</tt></p></div>
831 </div></div>
832 <div class="paragraph"><p>You can then fix the conflicts during the rebase. Presumably you have
833 not published your topic other than by mail, so rebasing it is not a
834 problem.</p></div>
835 <div class="paragraph"><p>If you receive such a patch series (as maintainer, or perhaps as a
836 reader of the mailing list it was sent to), save the mails to files,
837 create a new topic branch and use <em>git am</em> to import the commits:</p></div>
838 <div class="exampleblock">
839 <div class="title">Recipe: format-patch/am: Importing patches</div>
840 <div class="exampleblock-content">
841 <div class="paragraph"><p><tt>git am &lt; patch</tt></p></div>
842 </div></div>
843 <div class="paragraph"><p>One feature worth pointing out is the three-way merge, which can help
844 if you get conflicts: <tt>git am -3</tt> will use index information contained
845 in patches to figure out the merge base. See <a href="git-am.html">git-am(1)</a> for
846 other options.</p></div>
847 </div>
848 <h2 id="_see_also">SEE ALSO</h2>
849 <div class="sectionbody">
850 <div class="paragraph"><p><a href="gittutorial.html">gittutorial(7)</a>,
851 <a href="git-push.html">git-push(1)</a>,
852 <a href="git-pull.html">git-pull(1)</a>,
853 <a href="git-merge.html">git-merge(1)</a>,
854 <a href="git-rebase.html">git-rebase(1)</a>,
855 <a href="git-format-patch.html">git-format-patch(1)</a>,
856 <a href="git-send-email.html">git-send-email(1)</a>,
857 <a href="git-am.html">git-am(1)</a></p></div>
858 </div>
859 <h2 id="_git">GIT</h2>
860 <div class="sectionbody">
861 <div class="paragraph"><p>Part of the <a href="git.html">git(1)</a> suite.</p></div>
862 </div>
863 <div id="footer">
864 <div id="footer-text">
865 Last updated 2011-07-23 00:49:30 UTC
866 </div>
867 </div>
868 </body>
869 </html>