<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" | |
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<meta name="generator" content="AsciiDoc 8.2.5" /> | |
<style type="text/css"> | |
/* Debug borders */ | |
p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 { | |
/* | |
border: 1px solid red; | |
*/ | |
} | |
body { | |
margin: 1em 5% 1em 5%; | |
} | |
a { | |
color: blue; | |
text-decoration: underline; | |
} | |
a:visited { | |
color: fuchsia; | |
} | |
em { | |
font-style: italic; | |
} | |
strong { | |
font-weight: bold; | |
} | |
tt { | |
color: navy; | |
} | |
h1, h2, h3, h4, h5, h6 { | |
color: #527bbd; | |
font-family: sans-serif; | |
margin-top: 1.2em; | |
margin-bottom: 0.5em; | |
line-height: 1.3; | |
} | |
h1, h2, h3 { | |
border-bottom: 2px solid silver; | |
} | |
h2 { | |
padding-top: 0.5em; | |
} | |
h3 { | |
float: left; | |
} | |
h3 + * { | |
clear: left; | |
} | |
div.sectionbody { | |
font-family: serif; | |
margin-left: 0; | |
} | |
hr { | |
border: 1px solid silver; | |
} | |
p { | |
margin-top: 0.5em; | |
margin-bottom: 0.5em; | |
} | |
pre { | |
padding: 0; | |
margin: 0; | |
} | |
span#author { | |
color: #527bbd; | |
font-family: sans-serif; | |
font-weight: bold; | |
font-size: 1.1em; | |
} | |
span#email { | |
} | |
span#revision { | |
font-family: sans-serif; | |
} | |
div#footer { | |
font-family: sans-serif; | |
font-size: small; | |
border-top: 2px solid silver; | |
padding-top: 0.5em; | |
margin-top: 4.0em; | |
} | |
div#footer-text { | |
float: left; | |
padding-bottom: 0.5em; | |
} | |
div#footer-badges { | |
float: right; | |
padding-bottom: 0.5em; | |
} | |
div#preamble, | |
div.tableblock, div.imageblock, div.exampleblock, div.verseblock, | |
div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock, | |
div.admonitionblock { | |
margin-right: 10%; | |
margin-top: 1.5em; | |
margin-bottom: 1.5em; | |
} | |
div.admonitionblock { | |
margin-top: 2.5em; | |
margin-bottom: 2.5em; | |
} | |
div.content { /* Block element content. */ | |
padding: 0; | |
} | |
/* Block element titles. */ | |
div.title, caption.title { | |
font-family: sans-serif; | |
font-weight: bold; | |
text-align: left; | |
margin-top: 1.0em; | |
margin-bottom: 0.5em; | |
} | |
div.title + * { | |
margin-top: 0; | |
} | |
td div.title:first-child { | |
margin-top: 0.0em; | |
} | |
div.content div.title:first-child { | |
margin-top: 0.0em; | |
} | |
div.content + div.title { | |
margin-top: 0.0em; | |
} | |
div.sidebarblock > div.content { | |
background: #ffffee; | |
border: 1px solid silver; | |
padding: 0.5em; | |
} | |
div.listingblock { | |
margin-right: 0%; | |
} | |
div.listingblock > div.content { | |
border: 1px solid silver; | |
background: #f4f4f4; | |
padding: 0.5em; | |
} | |
div.quoteblock > div.content { | |
padding-left: 2.0em; | |
} | |
div.attribution { | |
text-align: right; | |
} | |
div.verseblock + div.attribution { | |
text-align: left; | |
} | |
div.admonitionblock .icon { | |
vertical-align: top; | |
font-size: 1.1em; | |
font-weight: bold; | |
text-decoration: underline; | |
color: #527bbd; | |
padding-right: 0.5em; | |
} | |
div.admonitionblock td.content { | |
padding-left: 0.5em; | |
border-left: 2px solid silver; | |
} | |
div.exampleblock > div.content { | |
border-left: 2px solid silver; | |
padding: 0.5em; | |
} | |
div.verseblock div.content { | |
white-space: pre; | |
} | |
div.imageblock div.content { padding-left: 0; } | |
div.imageblock img { border: 1px solid silver; } | |
span.image img { border-style: none; } | |
dl { | |
margin-top: 0.8em; | |
margin-bottom: 0.8em; | |
} | |
dt { | |
margin-top: 0.5em; | |
margin-bottom: 0; | |
font-style: italic; | |
} | |
dd > *:first-child { | |
margin-top: 0; | |
} | |
ul, ol { | |
list-style-position: outside; | |
} | |
div.olist2 ol { | |
list-style-type: lower-alpha; | |
} | |
div.tableblock > table { | |
border: 3px solid #527bbd; | |
} | |
thead { | |
font-family: sans-serif; | |
font-weight: bold; | |
} | |
tfoot { | |
font-weight: bold; | |
} | |
div.hlist { | |
margin-top: 0.8em; | |
margin-bottom: 0.8em; | |
} | |
div.hlist td { | |
padding-bottom: 5px; | |
} | |
td.hlist1 { | |
vertical-align: top; | |
font-style: italic; | |
padding-right: 0.8em; | |
} | |
td.hlist2 { | |
vertical-align: top; | |
} | |
@media print { | |
div#footer-badges { display: none; } | |
} | |
div#toctitle { | |
color: #527bbd; | |
font-family: sans-serif; | |
font-size: 1.1em; | |
font-weight: bold; | |
margin-top: 1.0em; | |
margin-bottom: 0.1em; | |
} | |
div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 { | |
margin-top: 0; | |
margin-bottom: 0; | |
} | |
div.toclevel2 { | |
margin-left: 2em; | |
font-size: 0.9em; | |
} | |
div.toclevel3 { | |
margin-left: 4em; | |
font-size: 0.9em; | |
} | |
div.toclevel4 { | |
margin-left: 6em; | |
font-size: 0.9em; | |
} | |
include1::./stylesheets/xhtml11-manpage.css[] | |
/* Workarounds for IE6's broken and incomplete CSS2. */ | |
div.sidebar-content { | |
background: #ffffee; | |
border: 1px solid silver; | |
padding: 0.5em; | |
} | |
div.sidebar-title, div.image-title { | |
font-family: sans-serif; | |
font-weight: bold; | |
margin-top: 0.0em; | |
margin-bottom: 0.5em; | |
} | |
div.listingblock div.content { | |
border: 1px solid silver; | |
background: #f4f4f4; | |
padding: 0.5em; | |
} | |
div.quoteblock-content { | |
padding-left: 2.0em; | |
} | |
div.exampleblock-content { | |
border-left: 2px solid silver; | |
padding-left: 0.5em; | |
} | |
/* IE6 sets dynamically generated links as visited. */ | |
div#toc a:visited { color: blue; } | |
</style> | |
<title>gitworkflows(7)</title> | |
</head> | |
<body> | |
<div id="header"> | |
<h1> | |
gitworkflows(7) Manual Page | |
</h1> | |
<h2>NAME</h2> | |
<div class="sectionbody"> | |
<p>gitworkflows - | |
An overview of recommended workflows with git | |
</p> | |
</div> | |
</div> | |
<h2>SYNOPSIS</h2> | |
<div class="sectionbody"> | |
<div class="para"><p>git *</p></div> | |
</div> | |
<h2 id="_description">DESCRIPTION</h2> | |
<div class="sectionbody"> | |
<div class="para"><p>This document attempts to write down and motivate some of the workflow | |
elements used for <tt>git.git</tt> itself. Many ideas apply in general, | |
though the full workflow is rarely required for smaller projects with | |
fewer people involved.</p></div> | |
<div class="para"><p>We formulate a set of <em>rules</em> for quick reference, while the prose | |
tries to motivate each of them. Do not always take them literally; | |
you should value good reasons for your actions higher than manpages | |
such as this one.</p></div> | |
</div> | |
<h2 id="_separate_changes">SEPARATE CHANGES</h2> | |
<div class="sectionbody"> | |
<div class="para"><p>As a general rule, you should try to split your changes into small | |
logical steps, and commit each of them. They should be consistent, | |
working independently of any later commits, pass the test suite, etc. | |
This makes the review process much easier, and the history much more | |
useful for later inspection and analysis, for example with | |
<a href="git-blame.html">git-blame(1)</a> and <a href="git-bisect.html">git-bisect(1)</a>.</p></div> | |
<div class="para"><p>To achieve this, try to split your work into small steps from the very | |
beginning. It is always easier to squash a few commits together than | |
to split one big commit into several. Don't be afraid of making too | |
small or imperfect steps along the way. You can always go back later | |
and edit the commits with <tt>git rebase --interactive</tt> before you | |
publish them. You can use <tt>git stash save --keep-index</tt> to run the | |
test suite independent of other uncommitted changes; see the EXAMPLES | |
section of <a href="git-stash.html">git-stash(1)</a>.</p></div> | |
</div> | |
<h2 id="_managing_branches">MANAGING BRANCHES</h2> | |
<div class="sectionbody"> | |
<div class="para"><p>There are two main tools that can be used to include changes from one | |
branch on another: <a href="git-merge.html">git-merge(1)</a> and | |
<a href="git-cherry-pick.html">git-cherry-pick(1)</a>.</p></div> | |
<div class="para"><p>Merges have many advantages, so we try to solve as many problems as | |
possible with merges alone. Cherry-picking is still occasionally | |
useful; see "Merging upwards" below for an example.</p></div> | |
<div class="para"><p>Most importantly, merging works at the branch level, while | |
cherry-picking works at the commit level. This means that a merge can | |
carry over the changes from 1, 10, or 1000 commits with equal ease, | |
which in turn means the workflow scales much better to a large number | |
of contributors (and contributions). Merges are also easier to | |
understand because a merge commit is a "promise" that all changes from | |
all its parents are now included.</p></div> | |
<div class="para"><p>There is a tradeoff of course: merges require a more careful branch | |
management. The following subsections discuss the important points.</p></div> | |
<h3 id="_graduation">Graduation</h3><div style="clear:left"></div> | |
<div class="para"><p>As a given feature goes from experimental to stable, it also | |
"graduates" between the corresponding branches of the software. | |
<tt>git.git</tt> uses the following <em>integration branches</em>:</p></div> | |
<div class="ilist"><ul> | |
<li> | |
<p> | |
<em>maint</em> tracks the commits that should go into the next "maintenance | |
release", i.e., update of the last released stable version; | |
</p> | |
</li> | |
<li> | |
<p> | |
<em>master</em> tracks the commits that should go into the next release; | |
</p> | |
</li> | |
<li> | |
<p> | |
<em>next</em> is intended as a testing branch for topics being tested for | |
stability for master. | |
</p> | |
</li> | |
</ul></div> | |
<div class="para"><p>There is a fourth official branch that is used slightly differently:</p></div> | |
<div class="ilist"><ul> | |
<li> | |
<p> | |
<em>pu</em> (proposed updates) is an integration branch for things that are | |
not quite ready for inclusion yet (see "Integration Branches" | |
below). | |
</p> | |
</li> | |
</ul></div> | |
<div class="para"><p>Each of the four branches is usually a direct descendant of the one | |
above it.</p></div> | |
<div class="para"><p>Conceptually, the feature enters at an unstable branch (usually <em>next</em> | |
or <em>pu</em>), and "graduates" to <em>master</em> for the next release once it is | |
considered stable enough.</p></div> | |
<h3 id="_merging_upwards">Merging upwards</h3><div style="clear:left"></div> | |
<div class="para"><p>The "downwards graduation" discussed above cannot be done by actually | |
merging downwards, however, since that would merge <em>all</em> changes on | |
the unstable branch into the stable one. Hence the following:</p></div> | |
<div class="exampleblock"> | |
<div class="title">Rule: Merge upwards</div> | |
<div class="exampleblock-content"> | |
<div class="para"><p>Always commit your fixes to the oldest supported branch that require | |
them. Then (periodically) merge the integration branches upwards into each | |
other.</p></div> | |
</div></div> | |
<div class="para"><p>This gives a very controlled flow of fixes. If you notice that you | |
have applied a fix to e.g. <em>master</em> that is also required in <em>maint</em>, | |
you will need to cherry-pick it (using <a href="git-cherry-pick.html">git-cherry-pick(1)</a>) | |
downwards. This will happen a few times and is nothing to worry about | |
unless you do it very frequently.</p></div> | |
<h3 id="_topic_branches">Topic branches</h3><div style="clear:left"></div> | |
<div class="para"><p>Any nontrivial feature will require several patches to implement, and | |
may get extra bugfixes or improvements during its lifetime.</p></div> | |
<div class="para"><p>Committing everything directly on the integration branches leads to many | |
problems: Bad commits cannot be undone, so they must be reverted one | |
by one, which creates confusing histories and further error potential | |
when you forget to revert part of a group of changes. Working in | |
parallel mixes up the changes, creating further confusion.</p></div> | |
<div class="para"><p>Use of "topic branches" solves these problems. The name is pretty | |
self explanatory, with a caveat that comes from the "merge upwards" | |
rule above:</p></div> | |
<div class="exampleblock"> | |
<div class="title">Rule: Topic branches</div> | |
<div class="exampleblock-content"> | |
<div class="para"><p>Make a side branch for every topic (feature, bugfix, …). Fork it off | |
at the oldest integration branch that you will eventually want to merge it | |
into.</p></div> | |
</div></div> | |
<div class="para"><p>Many things can then be done very naturally:</p></div> | |
<div class="ilist"><ul> | |
<li> | |
<p> | |
To get the feature/bugfix into an integration branch, simply merge | |
it. If the topic has evolved further in the meantime, merge again. | |
(Note that you do not necessarily have to merge it to the oldest | |
integration branch first. For example, you can first merge a bugfix | |
to <em>next</em>, give it some testing time, and merge to <em>maint</em> when you | |
know it is stable.) | |
</p> | |
</li> | |
<li> | |
<p> | |
If you find you need new features from the branch <em>other</em> to continue | |
working on your topic, merge <em>other</em> to <em>topic</em>. (However, do not | |
do this "just habitually", see below.) | |
</p> | |
</li> | |
<li> | |
<p> | |
If you find you forked off the wrong branch and want to move it | |
"back in time", use <a href="git-rebase.html">git-rebase(1)</a>. | |
</p> | |
</li> | |
</ul></div> | |
<div class="para"><p>Note that the last point clashes with the other two: a topic that has | |
been merged elsewhere should not be rebased. See the section on | |
RECOVERING FROM UPSTREAM REBASE in <a href="git-rebase.html">git-rebase(1)</a>.</p></div> | |
<div class="para"><p>We should point out that "habitually" (regularly for no real reason) | |
merging an integration branch into your topics — and by extension, | |
merging anything upstream into anything downstream on a regular basis | |
— is frowned upon:</p></div> | |
<div class="exampleblock"> | |
<div class="title">Rule: Merge to downstream only at well-defined points</div> | |
<div class="exampleblock-content"> | |
<div class="para"><p>Do not merge to downstream except with a good reason: upstream API | |
changes affect your branch; your branch no longer merges to upstream | |
cleanly; etc.</p></div> | |
</div></div> | |
<div class="para"><p>Otherwise, the topic that was merged to suddenly contains more than a | |
single (well-separated) change. The many resulting small merges will | |
greatly clutter up history. Anyone who later investigates the history | |
of a file will have to find out whether that merge affected the topic | |
in development. An upstream might even inadvertently be merged into a | |
"more stable" branch. And so on.</p></div> | |
<h3 id="_throw_away_integration">Throw-away integration</h3><div style="clear:left"></div> | |
<div class="para"><p>If you followed the last paragraph, you will now have many small topic | |
branches, and occasionally wonder how they interact. Perhaps the | |
result of merging them does not even work? But on the other hand, we | |
want to avoid merging them anywhere "stable" because such merges | |
cannot easily be undone.</p></div> | |
<div class="para"><p>The solution, of course, is to make a merge that we can undo: merge | |
into a throw-away branch.</p></div> | |
<div class="exampleblock"> | |
<div class="title">Rule: Throw-away integration branches</div> | |
<div class="exampleblock-content"> | |
<div class="para"><p>To test the interaction of several topics, merge them into a | |
throw-away branch. You must never base any work on such a branch!</p></div> | |
</div></div> | |
<div class="para"><p>If you make it (very) clear that this branch is going to be deleted | |
right after the testing, you can even publish this branch, for example | |
to give the testers a chance to work with it, or other developers a | |
chance to see if their in-progress work will be compatible. <tt>git.git</tt> | |
has such an official throw-away integration branch called <em>pu</em>.</p></div> | |
</div> | |
<h2 id="_distributed_workflows">DISTRIBUTED WORKFLOWS</h2> | |
<div class="sectionbody"> | |
<div class="para"><p>After the last section, you should know how to manage topics. In | |
general, you will not be the only person working on the project, so | |
you will have to share your work.</p></div> | |
<div class="para"><p>Roughly speaking, there are two important workflows: merge and patch. | |
The important difference is that the merge workflow can propagate full | |
history, including merges, while patches cannot. Both workflows can | |
be used in parallel: in <tt>git.git</tt>, only subsystem maintainers use | |
the merge workflow, while everyone else sends patches.</p></div> | |
<div class="para"><p>Note that the maintainer(s) may impose restrictions, such as | |
"Signed-off-by" requirements, that all commits/patches submitted for | |
inclusion must adhere to. Consult your project's documentation for | |
more information.</p></div> | |
<h3 id="_merge_workflow">Merge workflow</h3><div style="clear:left"></div> | |
<div class="para"><p>The merge workflow works by copying branches between upstream and | |
downstream. Upstream can merge contributions into the official | |
history; downstream base their work on the official history.</p></div> | |
<div class="para"><p>There are three main tools that can be used for this:</p></div> | |
<div class="ilist"><ul> | |
<li> | |
<p> | |
<a href="git-push.html">git-push(1)</a> copies your branches to a remote repository, | |
usually to one that can be read by all involved parties; | |
</p> | |
</li> | |
<li> | |
<p> | |
<a href="git-fetch.html">git-fetch(1)</a> that copies remote branches to your repository; | |
and | |
</p> | |
</li> | |
<li> | |
<p> | |
<a href="git-pull.html">git-pull(1)</a> that does fetch and merge in one go. | |
</p> | |
</li> | |
</ul></div> | |
<div class="para"><p>Note the last point. Do <em>not</em> use <em>git-pull</em> unless you actually want | |
to merge the remote branch.</p></div> | |
<div class="para"><p>Getting changes out is easy:</p></div> | |
<div class="exampleblock"> | |
<div class="title">Recipe: Push/pull: Publishing branches/topics</div> | |
<div class="exampleblock-content"> | |
<div class="para"><p><tt>git push <remote> <branch></tt> and tell everyone where they can fetch | |
from.</p></div> | |
</div></div> | |
<div class="para"><p>You will still have to tell people by other means, such as mail. (Git | |
provides the <a href="git-request-pull.html">git-request-pull(1)</a> to send preformatted pull | |
requests to upstream maintainers to simplify this task.)</p></div> | |
<div class="para"><p>If you just want to get the newest copies of the integration branches, | |
staying up to date is easy too:</p></div> | |
<div class="exampleblock"> | |
<div class="title">Recipe: Push/pull: Staying up to date</div> | |
<div class="exampleblock-content"> | |
<div class="para"><p>Use <tt>git fetch <remote></tt> or <tt>git remote update</tt> to stay up to date.</p></div> | |
</div></div> | |
<div class="para"><p>Then simply fork your topic branches from the stable remotes as | |
explained earlier.</p></div> | |
<div class="para"><p>If you are a maintainer and would like to merge other people's topic | |
branches to the integration branches, they will typically send a | |
request to do so by mail. Such a request looks like</p></div> | |
<div class="listingblock"> | |
<div class="content"> | |
<pre><tt>Please pull from | |
<url> <branch></tt></pre> | |
</div></div> | |
<div class="para"><p>In that case, <em>git-pull</em> can do the fetch and merge in one go, as | |
follows.</p></div> | |
<div class="exampleblock"> | |
<div class="title">Recipe: Push/pull: Merging remote topics</div> | |
<div class="exampleblock-content"> | |
<div class="para"><p><tt>git pull <url> <branch></tt></p></div> | |
</div></div> | |
<div class="para"><p>Occasionally, the maintainer may get merge conflicts when he tries to | |
pull changes from downstream. In this case, he can ask downstream to | |
do the merge and resolve the conflicts themselves (perhaps they will | |
know better how to resolve them). It is one of the rare cases where | |
downstream <em>should</em> merge from upstream.</p></div> | |
<h3 id="_patch_workflow">Patch workflow</h3><div style="clear:left"></div> | |
<div class="para"><p>If you are a contributor that sends changes upstream in the form of | |
emails, you should use topic branches as usual (see above). Then use | |
<a href="git-format-patch.html">git-format-patch(1)</a> to generate the corresponding emails | |
(highly recommended over manually formatting them because it makes the | |
maintainer's life easier).</p></div> | |
<div class="exampleblock"> | |
<div class="title">Recipe: format-patch/am: Publishing branches/topics</div> | |
<div class="exampleblock-content"> | |
<div class="ilist"><ul> | |
<li> | |
<p> | |
<tt>git format-patch -M upstream..topic</tt> to turn them into preformatted | |
patch files | |
</p> | |
</li> | |
<li> | |
<p> | |
<tt>git send-email --to=<recipient> <patches></tt> | |
</p> | |
</li> | |
</ul></div> | |
</div></div> | |
<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> | |
manpages for further usage notes.</p></div> | |
<div class="para"><p>If the maintainer tells you that your patch no longer applies to the | |
current upstream, you will have to rebase your topic (you cannot use a | |
merge because you cannot format-patch merges):</p></div> | |
<div class="exampleblock"> | |
<div class="title">Recipe: format-patch/am: Keeping topics up to date</div> | |
<div class="exampleblock-content"> | |
<div class="para"><p><tt>git pull --rebase <url> <branch></tt></p></div> | |
</div></div> | |
<div class="para"><p>You can then fix the conflicts during the rebase. Presumably you have | |
not published your topic other than by mail, so rebasing it is not a | |
problem.</p></div> | |
<div class="para"><p>If you receive such a patch series (as maintainer, or perhaps as a | |
reader of the mailing list it was sent to), save the mails to files, | |
create a new topic branch and use <em>git-am</em> to import the commits:</p></div> | |
<div class="exampleblock"> | |
<div class="title">Recipe: format-patch/am: Importing patches</div> | |
<div class="exampleblock-content"> | |
<div class="para"><p><tt>git am < patch</tt></p></div> | |
</div></div> | |
<div class="para"><p>One feature worth pointing out is the three-way merge, which can help | |
if you get conflicts: <tt>git am -3</tt> will use index information contained | |
in patches to figure out the merge base. See <a href="git-am.html">git-am(1)</a> for | |
other options.</p></div> | |
</div> | |
<h2 id="_see_also">SEE ALSO</h2> | |
<div class="sectionbody"> | |
<div class="para"><p><a href="gittutorial.html">gittutorial(7)</a>, | |
<a href="git-push.html">git-push(1)</a>, | |
<a href="git-pull.html">git-pull(1)</a>, | |
<a href="git-merge.html">git-merge(1)</a>, | |
<a href="git-rebase.html">git-rebase(1)</a>, | |
<a href="git-format-patch.html">git-format-patch(1)</a>, | |
<a href="git-send-email.html">git-send-email(1)</a>, | |
<a href="git-am.html">git-am(1)</a></p></div> | |
</div> | |
<h2 id="_git">GIT</h2> | |
<div class="sectionbody"> | |
<div class="para"><p>Part of the <a href="git.html">git(1)</a> suite.</p></div> | |
</div> | |
<div id="footer"> | |
<div id="footer-text"> | |
Last updated 2009-07-01 02:31:11 UTC | |
</div> | |
</div> | |
</body> | |
</html> |