make some more strings translatable
[TortoiseGit.git] / doc / source / en / TortoiseGit / git_doc / gitworkflows.html.xml
blobbd0665419a97333c1d72f2e16e607723413dd15e
1 <?xml version="1.0" encoding="UTF-8"?>\r
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">\r
3 \r
4 <article lang="en" id="gitworkflows(7)">\r
5 <articleinfo>\r
6     <title>gitworkflows(7)</title>\r
7         <indexterm>\r
8                 <primary>gitworkflows(7)</primary>\r
9         </indexterm>\r
10 </articleinfo>\r
11 <simplesect id="_name">\r
12 <title>NAME</title>\r
13 <simpara>gitworkflows - An overview of recommended workflows with git</simpara>\r
14 </simplesect>\r
15 <simplesect id="_synopsis">\r
16 <title>SYNOPSIS</title>\r
17 <simpara>git *</simpara>\r
18 </simplesect>\r
19 <simplesect id="_description">\r
20 <title>DESCRIPTION</title>\r
21 <simpara>This document attempts to write down and motivate some of the workflow\r
22 elements used for <literal>git.git</literal> itself.  Many ideas apply in general,\r
23 though the full workflow is rarely required for smaller projects with\r
24 fewer people involved.</simpara>\r
25 <simpara>We formulate a set of <emphasis>rules</emphasis> for quick reference, while the prose\r
26 tries to motivate each of them.  Do not always take them literally;\r
27 you should value good reasons for your actions higher than manpages\r
28 such as this one.</simpara>\r
29 </simplesect>\r
30 <simplesect id="_separate_changes">\r
31 <title>SEPARATE CHANGES</title>\r
32 <simpara>As a general rule, you should try to split your changes into small\r
33 logical steps, and commit each of them.  They should be consistent,\r
34 working independently of any later commits, pass the test suite, etc.\r
35 This makes the review process much easier, and the history much more\r
36 useful for later inspection and analysis, for example with\r
37 <xref linkend="git-blame(1)"/> and <xref linkend="git-bisect(1)"/>.</simpara>\r
38 <simpara>To achieve this, try to split your work into small steps from the very\r
39 beginning. It is always easier to squash a few commits together than\r
40 to split one big commit into several.  Don&#8217;t be afraid of making too\r
41 small or imperfect steps along the way. You can always go back later\r
42 and edit the commits with <literal>git rebase --interactive</literal> before you\r
43 publish them.  You can use <literal>git stash save --keep-index</literal> to run the\r
44 test suite independent of other uncommitted changes; see the EXAMPLES\r
45 section of <xref linkend="git-stash(1)"/>.</simpara>\r
46 </simplesect>\r
47 <simplesect id="_managing_branches">\r
48 <title>MANAGING BRANCHES</title>\r
49 <simpara>There are two main tools that can be used to include changes from one\r
50 branch on another: <xref linkend="git-merge(1)"/> and\r
51 <xref linkend="git-cherry-pick(1)"/>.</simpara>\r
52 <simpara>Merges have many advantages, so we try to solve as many problems as\r
53 possible with merges alone.  Cherry-picking is still occasionally\r
54 useful; see "Merging upwards" below for an example.</simpara>\r
55 <simpara>Most importantly, merging works at the branch level, while\r
56 cherry-picking works at the commit level.  This means that a merge can\r
57 carry over the changes from 1, 10, or 1000 commits with equal ease,\r
58 which in turn means the workflow scales much better to a large number\r
59 of contributors (and contributions).  Merges are also easier to\r
60 understand because a merge commit is a "promise" that all changes from\r
61 all its parents are now included.</simpara>\r
62 <simpara>There is a tradeoff of course: merges require a more careful branch\r
63 management.  The following subsections discuss the important points.</simpara>\r
64 <simplesect id="_graduation">\r
65 <title>Graduation</title>\r
66 <simpara>As a given feature goes from experimental to stable, it also\r
67 "graduates" between the corresponding branches of the software.\r
68 <literal>git.git</literal> uses the following <emphasis>integration branches</emphasis>:</simpara>\r
69 <itemizedlist>\r
70 <listitem>\r
71 <simpara>\r
72 <emphasis>maint</emphasis> tracks the commits that should go into the next "maintenance\r
73   release", i.e., update of the last released stable version;\r
74 </simpara>\r
75 </listitem>\r
76 <listitem>\r
77 <simpara>\r
78 <emphasis>master</emphasis> tracks the commits that should go into the next release;\r
79 </simpara>\r
80 </listitem>\r
81 <listitem>\r
82 <simpara>\r
83 <emphasis>next</emphasis> is intended as a testing branch for topics being tested for\r
84   stability for master.\r
85 </simpara>\r
86 </listitem>\r
87 </itemizedlist>\r
88 <simpara>There is a fourth official branch that is used slightly differently:</simpara>\r
89 <itemizedlist>\r
90 <listitem>\r
91 <simpara>\r
92 <emphasis>pu</emphasis> (proposed updates) is an integration branch for things that are\r
93   not quite ready for inclusion yet (see "Integration Branches"\r
94   below).\r
95 </simpara>\r
96 </listitem>\r
97 </itemizedlist>\r
98 <simpara>Each of the four branches is usually a direct descendant of the one\r
99 above it.</simpara>\r
100 <simpara>Conceptually, the feature enters at an unstable branch (usually <emphasis>next</emphasis>\r
101 or <emphasis>pu</emphasis>), and "graduates" to <emphasis>master</emphasis> for the next release once it is\r
102 considered stable enough.</simpara>\r
103 </simplesect>\r
104 <simplesect id="_merging_upwards">\r
105 <title>Merging upwards</title>\r
106 <simpara>The "downwards graduation" discussed above cannot be done by actually\r
107 merging downwards, however, since that would merge <emphasis>all</emphasis> changes on\r
108 the unstable branch into the stable one.  Hence the following:</simpara>\r
109 <example>\r
110 <title>Merge upwards</title>\r
111 <simpara>Always commit your fixes to the oldest supported branch that require\r
112 them.  Then (periodically) merge the integration branches upwards into each\r
113 other.</simpara>\r
114 </example>\r
115 <simpara>This gives a very controlled flow of fixes.  If you notice that you\r
116 have applied a fix to e.g. <emphasis>master</emphasis> that is also required in <emphasis>maint</emphasis>,\r
117 you will need to cherry-pick it (using <xref linkend="git-cherry-pick(1)"/>)\r
118 downwards.  This will happen a few times and is nothing to worry about\r
119 unless you do it very frequently.</simpara>\r
120 </simplesect>\r
121 <simplesect id="_topic_branches">\r
122 <title>Topic branches</title>\r
123 <simpara>Any nontrivial feature will require several patches to implement, and\r
124 may get extra bugfixes or improvements during its lifetime.</simpara>\r
125 <simpara>Committing everything directly on the integration branches leads to many\r
126 problems: Bad commits cannot be undone, so they must be reverted one\r
127 by one, which creates confusing histories and further error potential\r
128 when you forget to revert part of a group of changes.  Working in\r
129 parallel mixes up the changes, creating further confusion.</simpara>\r
130 <simpara>Use of "topic branches" solves these problems.  The name is pretty\r
131 self explanatory, with a caveat that comes from the "merge upwards"\r
132 rule above:</simpara>\r
133 <example>\r
134 <title>Topic branches</title>\r
135 <simpara>Make a side branch for every topic (feature, bugfix, &#8230;). Fork it off\r
136 at the oldest integration branch that you will eventually want to merge it\r
137 into.</simpara>\r
138 </example>\r
139 <simpara>Many things can then be done very naturally:</simpara>\r
140 <itemizedlist>\r
141 <listitem>\r
142 <simpara>\r
143 To get the feature/bugfix into an integration branch, simply merge\r
144   it.  If the topic has evolved further in the meantime, merge again.\r
145   (Note that you do not necessarily have to merge it to the oldest\r
146   integration branch first.  For example, you can first merge a bugfix\r
147   to <emphasis>next</emphasis>, give it some testing time, and merge to <emphasis>maint</emphasis> when you\r
148   know it is stable.)\r
149 </simpara>\r
150 </listitem>\r
151 <listitem>\r
152 <simpara>\r
153 If you find you need new features from the branch <emphasis>other</emphasis> to continue\r
154   working on your topic, merge <emphasis>other</emphasis> to <emphasis>topic</emphasis>.  (However, do not\r
155   do this "just habitually", see below.)\r
156 </simpara>\r
157 </listitem>\r
158 <listitem>\r
159 <simpara>\r
160 If you find you forked off the wrong branch and want to move it\r
161   "back in time", use <xref linkend="git-rebase(1)"/>.\r
162 </simpara>\r
163 </listitem>\r
164 </itemizedlist>\r
165 <simpara>Note that the last point clashes with the other two: a topic that has\r
166 been merged elsewhere should not be rebased.  See the section on\r
167 RECOVERING FROM UPSTREAM REBASE in <xref linkend="git-rebase(1)"/>.</simpara>\r
168 <simpara>We should point out that "habitually" (regularly for no real reason)\r
169 merging an integration branch into your topics&#8201;&#8212;&#8201;and by extension,\r
170 merging anything upstream into anything downstream on a regular basis&#8201;&#8212;&#8201;is frowned upon:</simpara>\r
171 <example>\r
172 <title>Merge to downstream only at well-defined points</title>\r
173 <simpara>Do not merge to downstream except with a good reason: upstream API\r
174 changes affect your branch; your branch no longer merges to upstream\r
175 cleanly; etc.</simpara>\r
176 </example>\r
177 <simpara>Otherwise, the topic that was merged to suddenly contains more than a\r
178 single (well-separated) change.  The many resulting small merges will\r
179 greatly clutter up history.  Anyone who later investigates the history\r
180 of a file will have to find out whether that merge affected the topic\r
181 in development.  An upstream might even inadvertently be merged into a\r
182 "more stable" branch.  And so on.</simpara>\r
183 </simplesect>\r
184 <simplesect id="_throw_away_integration">\r
185 <title>Throw-away integration</title>\r
186 <simpara>If you followed the last paragraph, you will now have many small topic\r
187 branches, and occasionally wonder how they interact.  Perhaps the\r
188 result of merging them does not even work?  But on the other hand, we\r
189 want to avoid merging them anywhere "stable" because such merges\r
190 cannot easily be undone.</simpara>\r
191 <simpara>The solution, of course, is to make a merge that we can undo: merge\r
192 into a throw-away branch.</simpara>\r
193 <example>\r
194 <title>Throw-away integration branches</title>\r
195 <simpara>To test the interaction of several topics, merge them into a\r
196 throw-away branch.  You must never base any work on such a branch!</simpara>\r
197 </example>\r
198 <simpara>If you make it (very) clear that this branch is going to be deleted\r
199 right after the testing, you can even publish this branch, for example\r
200 to give the testers a chance to work with it, or other developers a\r
201 chance to see if their in-progress work will be compatible.  <literal>git.git</literal>\r
202 has such an official throw-away integration branch called <emphasis>pu</emphasis>.</simpara>\r
203 </simplesect>\r
204 </simplesect>\r
205 <simplesect id="_distributed_workflows">\r
206 <title>DISTRIBUTED WORKFLOWS</title>\r
207 <simpara>After the last section, you should know how to manage topics.  In\r
208 general, you will not be the only person working on the project, so\r
209 you will have to share your work.</simpara>\r
210 <simpara>Roughly speaking, there are two important workflows: merge and patch.\r
211 The important difference is that the merge workflow can propagate full\r
212 history, including merges, while patches cannot.  Both workflows can\r
213 be used in parallel: in <literal>git.git</literal>, only subsystem maintainers use\r
214 the merge workflow, while everyone else sends patches.</simpara>\r
215 <simpara>Note that the maintainer(s) may impose restrictions, such as\r
216 "Signed-off-by" requirements, that all commits/patches submitted for\r
217 inclusion must adhere to.  Consult your project&#8217;s documentation for\r
218 more information.</simpara>\r
219 <simplesect id="_merge_workflow">\r
220 <title>Merge workflow</title>\r
221 <simpara>The merge workflow works by copying branches between upstream and\r
222 downstream.  Upstream can merge contributions into the official\r
223 history; downstream base their work on the official history.</simpara>\r
224 <simpara>There are three main tools that can be used for this:</simpara>\r
225 <itemizedlist>\r
226 <listitem>\r
227 <simpara>\r
228 <xref linkend="git-push(1)"/> copies your branches to a remote repository,\r
229   usually to one that can be read by all involved parties;\r
230 </simpara>\r
231 </listitem>\r
232 <listitem>\r
233 <simpara>\r
234 <xref linkend="git-fetch(1)"/> that copies remote branches to your repository;\r
235   and\r
236 </simpara>\r
237 </listitem>\r
238 <listitem>\r
239 <simpara>\r
240 <xref linkend="git-pull(1)"/> that does fetch and merge in one go.\r
241 </simpara>\r
242 </listitem>\r
243 </itemizedlist>\r
244 <simpara>Note the last point.  Do <emphasis>not</emphasis> use <emphasis>git-pull</emphasis> unless you actually want\r
245 to merge the remote branch.</simpara>\r
246 <simpara>Getting changes out is easy:</simpara>\r
247 <example>\r
248 <title>Push/pull: Publishing branches/topics</title>\r
249 <simpara><literal>git push &lt;remote&gt; &lt;branch&gt;</literal> and tell everyone where they can fetch\r
250 from.</simpara>\r
251 </example>\r
252 <simpara>You will still have to tell people by other means, such as mail.  (Git\r
253 provides the <xref linkend="git-request-pull(1)"/> to send preformatted pull\r
254 requests to upstream maintainers to simplify this task.)</simpara>\r
255 <simpara>If you just want to get the newest copies of the integration branches,\r
256 staying up to date is easy too:</simpara>\r
257 <example>\r
258 <title>Push/pull: Staying up to date</title>\r
259 <simpara>Use <literal>git fetch &lt;remote&gt;</literal> or <literal>git remote update</literal> to stay up to date.</simpara>\r
260 </example>\r
261 <simpara>Then simply fork your topic branches from the stable remotes as\r
262 explained earlier.</simpara>\r
263 <simpara>If you are a maintainer and would like to merge other people&#8217;s topic\r
264 branches to the integration branches, they will typically send a\r
265 request to do so by mail.  Such a request looks like</simpara>\r
266 <literallayout>Please pull from\r
267     &lt;url&gt; &lt;branch&gt;</literallayout>\r
268 <simpara>In that case, <emphasis>git-pull</emphasis> can do the fetch and merge in one go, as\r
269 follows.</simpara>\r
270 <example>\r
271 <title>Push/pull: Merging remote topics</title>\r
272 <simpara><literal>git pull &lt;url&gt; &lt;branch&gt;</literal></simpara>\r
273 </example>\r
274 <simpara>Occasionally, the maintainer may get merge conflicts when he tries to\r
275 pull changes from downstream.  In this case, he can ask downstream to\r
276 do the merge and resolve the conflicts themselves (perhaps they will\r
277 know better how to resolve them).  It is one of the rare cases where\r
278 downstream <emphasis>should</emphasis> merge from upstream.</simpara>\r
279 </simplesect>\r
280 <simplesect id="_patch_workflow">\r
281 <title>Patch workflow</title>\r
282 <simpara>If you are a contributor that sends changes upstream in the form of\r
283 emails, you should use topic branches as usual (see above).  Then use\r
284 <xref linkend="git-format-patch(1)"/> to generate the corresponding emails\r
285 (highly recommended over manually formatting them because it makes the\r
286 maintainer&#8217;s life easier).</simpara>\r
287 <example>\r
288 <title>format-patch/am: Publishing branches/topics</title>\r
289 <itemizedlist>\r
290 <listitem>\r
291 <simpara>\r
292 <literal>git format-patch -M upstream..topic</literal> to turn them into preformatted\r
293   patch files\r
294 </simpara>\r
295 </listitem>\r
296 <listitem>\r
297 <simpara>\r
298 <literal>git send-email --to=&lt;recipient&gt; &lt;patches&gt;</literal>\r
299 </simpara>\r
300 </listitem>\r
301 </itemizedlist>\r
302 </example>\r
303 <simpara>See the <xref linkend="git-format-patch(1)"/> and <xref linkend="git-send-email(1)"/>\r
304 manpages for further usage notes.</simpara>\r
305 <simpara>If the maintainer tells you that your patch no longer applies to the\r
306 current upstream, you will have to rebase your topic (you cannot use a\r
307 merge because you cannot format-patch merges):</simpara>\r
308 <example>\r
309 <title>format-patch/am: Keeping topics up to date</title>\r
310 <simpara><literal>git pull --rebase &lt;url&gt; &lt;branch&gt;</literal></simpara>\r
311 </example>\r
312 <simpara>You can then fix the conflicts during the rebase.  Presumably you have\r
313 not published your topic other than by mail, so rebasing it is not a\r
314 problem.</simpara>\r
315 <simpara>If you receive such a patch series (as maintainer, or perhaps as a\r
316 reader of the mailing list it was sent to), save the mails to files,\r
317 create a new topic branch and use <emphasis>git-am</emphasis> to import the commits:</simpara>\r
318 <example>\r
319 <title>format-patch/am: Importing patches</title>\r
320 <simpara><literal>git am &lt; patch</literal></simpara>\r
321 </example>\r
322 <simpara>One feature worth pointing out is the three-way merge, which can help\r
323 if you get conflicts: <literal>git am -3</literal> will use index information contained\r
324 in patches to figure out the merge base.  See <xref linkend="git-am(1)"/> for\r
325 other options.</simpara>\r
326 </simplesect>\r
327 </simplesect>\r
328 <simplesect id="_see_also">\r
329 <title>SEE ALSO</title>\r
330 <simpara><xref linkend="gittutorial(7)"/>,\r
331 <xref linkend="git-push(1)"/>,\r
332 <xref linkend="git-pull(1)"/>,\r
333 <xref linkend="git-merge(1)"/>,\r
334 <xref linkend="git-rebase(1)"/>,\r
335 <xref linkend="git-format-patch(1)"/>,\r
336 <xref linkend="git-send-email(1)"/>,\r
337 <xref linkend="git-am(1)"/></simpara>\r
338 </simplesect>\r
339 <simplesect id="_git">\r
340 <title>GIT</title>\r
341 <simpara>Part of the <xref linkend="git(1)"/> suite.</simpara>\r
342 </simplesect>\r
343 </article>\r