git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
blob 21f6dc8fb2f00bad170395b17008cccb0e880b67 23552 bytes (raw)
name: Documentation/gitworkflows.txt 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
 
gitworkflows(7)
===============

NAME
----
gitworkflows - An overview of recommended workflows with Git

SYNOPSIS
--------
[verse]
git *


DESCRIPTION
-----------

This document attempts to write down and motivate some of the workflow
elements used for `git.git` itself.  Many ideas apply in general,
though the full workflow is rarely required for smaller projects with
fewer people involved.

We formulate a set of 'rules' 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.


SEPARATE CHANGES
----------------

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
linkgit:git-blame[1] and linkgit:git-bisect[1].

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 `git rebase --interactive` before you
publish them.  You can use `git stash push --keep-index` to run the
test suite independent of other uncommitted changes; see the EXAMPLES
section of linkgit:git-stash[1].


MANAGING BRANCHES
-----------------

There are two main tools that can be used to include changes from one
branch on another: linkgit:git-merge[1] and
linkgit:git-cherry-pick[1].

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.

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.

There is a tradeoff of course: merges require a more careful branch
management.  The following subsections discuss the important points.


Graduation
~~~~~~~~~~

As a given feature goes from experimental to stable, it also
"graduates" between the corresponding branches of the software.
`git.git` uses the following 'integration branches':

* 'maint' tracks the commits that should go into the next "maintenance
  release", i.e., update of the last released stable version;

* 'master' tracks the commits that should go into the next release;

* 'next' is intended as a testing branch for topics being tested for
  stability for master.

There is a fourth official branch that is used slightly differently:

* 'pu' (proposed updates) is an integration branch for things that are
  not quite ready for inclusion yet (see "Integration Branches"
  below).

Each of the four branches is usually a direct descendant of the one
above it.

Conceptually, the feature enters at an unstable branch (usually 'next'
or 'pu'), and "graduates" to 'master' for the next release once it is
considered stable enough.


Merging upwards
~~~~~~~~~~~~~~~

The "downwards graduation" discussed above cannot be done by actually
merging downwards, however, since that would merge 'all' changes on
the unstable branch into the stable one.  Hence the following:

.Merge upwards
[caption="Rule: "]
=====================================
Always commit your fixes to the oldest supported branch that require
them.  Then (periodically) merge the integration branches upwards into each
other.
=====================================

This gives a very controlled flow of fixes.  If you notice that you
have applied a fix to e.g. 'master' that is also required in 'maint',
you will need to cherry-pick it (using linkgit:git-cherry-pick[1])
downwards.  This will happen a few times and is nothing to worry about
unless you do it very frequently.


Topic branches
~~~~~~~~~~~~~~

Any nontrivial feature will require several patches to implement, and
may get extra bugfixes or improvements during its lifetime.

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.

Use of "topic branches" solves these problems.  The name is pretty
self explanatory, with a caveat that comes from the "merge upwards"
rule above:

.Topic branches
[caption="Rule: "]
=====================================
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.
=====================================

Many things can then be done very naturally:

* 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 'next', give it some testing time, and merge to 'maint' when you
  know it is stable.)

* If you find you need new features from the branch 'other' to continue
  working on your topic, merge 'other' to 'topic'.  (However, do not
  do this "just habitually", see below.)

* If you find you forked off the wrong branch and want to move it
  "back in time", use linkgit:git-rebase[1].

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 linkgit:git-rebase[1].

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:

.Merge to downstream only at well-defined points
[caption="Rule: "]
=====================================
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.
=====================================

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.


Throw-away integration
~~~~~~~~~~~~~~~~~~~~~~

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.

The solution, of course, is to make a merge that we can undo: merge
into a throw-away branch.

.Throw-away integration branches
[caption="Rule: "]
=====================================
To test the interaction of several topics, merge them into a
throw-away branch.  You must never base any work on such a branch!
=====================================

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.  `git.git`
has such an official throw-away integration branch called 'pu'.


Branch management for a release
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Assuming you are using the merge approach discussed above, when you
are releasing your project you will need to do some additional branch
management work.

A feature release is created from the 'master' branch, since 'master'
tracks the commits that should go into the next feature release.

The 'master' branch is supposed to be a superset of 'maint'. If this
condition does not hold, then 'maint' contains some commits that
are not included on 'master'. The fixes represented by those commits
will therefore not be included in your feature release.

To verify that 'master' is indeed a superset of 'maint', use git log:

.Verify 'master' is a superset of 'maint'
[caption="Recipe: "]
=====================================
`git log master..maint`
=====================================

This command should not list any commits.  Otherwise, check out
'master' and merge 'maint' into it.

Now you can proceed with the creation of the feature release. Apply a
tag to the tip of 'master' indicating the release version:

.Release tagging
[caption="Recipe: "]
=====================================
`git tag -s -m "Git X.Y.Z" vX.Y.Z master`
=====================================

You need to push the new tag to a public Git server (see
"DISTRIBUTED WORKFLOWS" below). This makes the tag available to
others tracking your project. The push could also trigger a
post-update hook to perform release-related items such as building
release tarballs and preformatted documentation pages.

Similarly, for a maintenance release, 'maint' is tracking the commits
to be released. Therefore, in the steps above simply tag and push
'maint' rather than 'master'.


Maintenance branch management after a feature release
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

After a feature release, you need to manage your maintenance branches.

First, if you wish to continue to release maintenance fixes for the
feature release made before the recent one, then you must create
another branch to track commits for that previous release.

To do this, the current maintenance branch is copied to another branch
named with the previous release version number (e.g. maint-X.Y.(Z-1)
where X.Y.Z is the current release).

.Copy maint
[caption="Recipe: "]
=====================================
`git branch maint-X.Y.(Z-1) maint`
=====================================

The 'maint' branch should now be fast-forwarded to the newly released
code so that maintenance fixes can be tracked for the current release:

.Update maint to new release
[caption="Recipe: "]
=====================================
* `git checkout maint`
* `git merge --ff-only master`
=====================================

If the merge fails because it is not a fast-forward, then it is
possible some fixes on 'maint' were missed in the feature release.
This will not happen if the content of the branches was verified as
described in the previous section.


Branch management for next and pu after a feature release
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

After a feature release, the integration branch 'next' may optionally be
rewound and rebuilt from the tip of 'master' using the surviving
topics on 'next':

.Rewind and rebuild next
[caption="Recipe: "]
=====================================
* `git checkout next`
* `git reset --hard master`
* `git merge ai/topic_in_next1`
* `git merge ai/topic_in_next2`
* ...
=====================================

The advantage of doing this is that the history of 'next' will be
clean. For example, some topics merged into 'next' may have initially
looked promising, but were later found to be undesirable or premature.
In such a case, the topic is reverted out of 'next' but the fact
remains in the history that it was once merged and reverted. By
recreating 'next', you give another incarnation of such topics a clean
slate to retry, and a feature release is a good point in history to do
so.

If you do this, then you should make a public announcement indicating
that 'next' was rewound and rebuilt.

The same rewind and rebuild process may be followed for 'pu'. A public
announcement is not necessary since 'pu' is a throw-away branch, as
described above.


DISTRIBUTED WORKFLOWS
---------------------

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.

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 `git.git`, only subsystem maintainers use
the merge workflow, while everyone else sends patches.

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.


Merge workflow
~~~~~~~~~~~~~~

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.

There are three main tools that can be used for this:

* linkgit:git-push[1] copies your branches to a remote repository,
  usually to one that can be read by all involved parties;

* linkgit:git-fetch[1] that copies remote branches to your repository;
  and

* linkgit:git-pull[1] that does fetch and merge in one go.

Note the last point.  Do 'not' use 'git pull' unless you actually want
to merge the remote branch.

Getting changes out is easy:

.Push/pull: Publishing branches/topics
[caption="Recipe: "]
=====================================
`git push <remote> <branch>` and tell everyone where they can fetch
from.
=====================================

You will still have to tell people by other means, such as mail.  (Git
provides the linkgit:git-request-pull[1] to send preformatted pull
requests to upstream maintainers to simplify this task.)

If you just want to get the newest copies of the integration branches,
staying up to date is easy too:

.Push/pull: Staying up to date
[caption="Recipe: "]
=====================================
Use `git fetch <remote>` or `git remote update` to stay up to date.
=====================================

Then simply fork your topic branches from the stable remotes as
explained earlier.

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

-------------------------------------
Please pull from
    <url> <branch>
-------------------------------------

In that case, 'git pull' can do the fetch and merge in one go, as
follows.

.Push/pull: Merging remote topics
[caption="Recipe: "]
=====================================
`git pull <url> <branch>`
=====================================

Occasionally, the maintainers may get merge conflicts when they try to
pull changes from downstream.  In this case, they 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 'should' merge from upstream.


Patch workflow
~~~~~~~~~~~~~~

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
linkgit:git-format-patch[1] to generate the corresponding emails
(highly recommended over manually formatting them because it makes the
maintainer's life easier).

.format-patch/am: Publishing branches/topics
[caption="Recipe: "]
=====================================
* `git format-patch -M upstream..topic` to turn them into preformatted
  patch files
* `git send-email --to=<recipient> <patches>`
=====================================

See the linkgit:git-format-patch[1] and linkgit:git-send-email[1]
manpages for further usage notes.

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):

.format-patch/am: Keeping topics up to date
[caption="Recipe: "]
=====================================
`git pull --rebase <url> <branch>`
=====================================

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.

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 'git am' to import the commits:

.format-patch/am: Importing patches
[caption="Recipe: "]
=====================================
`git am < patch`
=====================================

One feature worth pointing out is the three-way merge, which can help
if you get conflicts: `git am -3` will use index information contained
in patches to figure out the merge base.  See linkgit:git-am[1] for
other options.


TRIANGULAR WORKFLOW
-------------------

Introduction
~~~~~~~~~~~~

In some projects, contributors cannot push directly to the project but
have to suggest their commits to the maintainer (e.g. pull requests).
For these projects, it's common to use what's called a *triangular
workflow*:

- The project maintainer publishes a repository, called **UPSTREAM** in
this document, which is a read-only for contributors. They can clone and
fetch from this repository.
- Contributors publish their modifications by pushing to a repository,
called **PUBLISH** in this document, and request a merge.
- Opening a pull request
- If the maintainers accept the changes, they merge them into the
  **UPSTREAM** repository.

This workflow is commonly used on different platforms like BitBucket,
GitHub or GitLab which provide a dedicated mechanism for requesting merges.

........................................
------------------               -----------------
| UPSTREAM       |  maintainer   | PUBLISH       |
|                |- - - - - - - -|               |
------------------      <-       -----------------
              \                     /
               \                   /
        fetch | \                 / ^ push
              v  \               /  |
                  \             /
                   -------------
                   |   LOCAL   |
                   -------------
........................................

Motivations
~~~~~~~~~~~

* Allows contributors to work with Git even if they don't have
write access to **UPSTREAM**.

With the triangular workflow, the contributors have the write 
access on **PUBLISH** and push their code there.  Only the
maintainers merge from **PUBLISH** to **UPSTREAM**.

* Code review is done before integration.

In a triangular workflow the rest of the community or the company
can review the code before it's in production. Everyone can read on
**PUBLISH** so everyone can review code before the maintainer merge
it to **UPSTREAM**.  In free software, anyone can
propose code.  Reviewers accept the code when everyone agrees
with it.

* Encourages clean history by using `rebase -i` and `push --force` to
the public fork before the code is merged.

This is just a side-effect of the "review before merge" mentioned
above, but this is still a good point.


Here are the configuration variables you will need to arrange your
workflow.

Preparation as a contributor
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Cloning from **UPSTREAM**.

======================
`git clone <UPSTREAM_url>`
======================

If **PUBLISH** doesn't exist, a contributor can publish his own repository.
**PUBLISH** contains modifications before integration.

============================
* `git clone <UPSTREAM_url>`
* `git remote add <PUBLISH>`
* `git push`
============================

Adding **UPSTREAM** remote:

===================================
`git remote add upstream <UPSTREAM_url>`
===================================

With the `remote add` above, using `git pull upstream` pulls there,
instead of saying its URL. In addition, the `git pull` command
(without argument) can be used to pull from **UPSTREAM**.

For each branch requiring a triangular workflow, set
`branch.<branch>.remote` and `branch.<branch>.pushRemote` to set up
the **UPSTREAM** and **PUBLISH** repositories.

Example with master as <branch>:
===================================
* `git config branch.master.remote upstream`
* `git config branch.master.pushRemote origin`
===================================

Making your work available
~~~~~~~~~~~~~~~~~~~~~~~~~~

The `git push` command sends commits to the **PUBLISH** repository and not to
the **UPSTREAM** thanks to the configuration you did earlier with the
`git config remote.pushdefault origin` command.

When a contributor pushes something, the `git config push.default
current` command can be used to specify that the name of the
**PUBLISH** branch is the same as the name of the **LOCAL** one.

.Display the name of the push remote:
[caption="Recipe: "]

The shorthand `<branch>@{push}` denotes the remote-tracking branch
where the <branch> would be pushed to. If no <branch> is specified,
<branch> takes the value of the current branch.

=================================
`git rev-parse --abbrev-ref @{push}`
=================================

.Display the fetch remote's name:
[caption="Recipe: "]

===================================
`git rev-parse --abbrev-ref @{upstream}`
===================================

The shorthand `<branch>@{upstream}` substitutes the upstream name of
the branch. If no <branch> is specified, <branch> takes the value of
the current branch.

.Display commits added to the current branch since last push:
[caption="Recipe: "]

===============
`git log @{push}..`
===============

.Display commits added to a specific branch since last push:
[caption="Recipe: "]

============================
`git log <branch_name>@{push}..`
============================

Staying up-to-date
~~~~~~~~~~~~~~~~~~

Retrieve updates from **UPSTREAM** with `git pull` and send them to
**PUBLISH** with `git push`.

Alternatively
~~~~~~~~~~~~~

Cloning from **UPSTREAM**
[caption="Recipe: "]

In the preparation above, a clone from **PUBLISH** was used. Starting
with a clone of **UPSTREAM** is possible too.

Cloning from **UPSTREAM**

======================
`git clone <UPSTREAM_url>`
======================

Setting the behavior of push for the triangular workflow:

===========================
`git config push.default current`
===========================

Because modifications will be often pushed into the **PUBLISH** repository,
instead of having to type its URL every time, a short name can be used
to call it.

Adding **PUBLISH** remote:

===================================
`git remote add publish <PUBLISH_url>`
===================================

With the `remote add` above, using `git push publish` pushes there,
instead of saying its URL. In addition, `git push` without argument
pushes to **PUBLISH**.

Example with master as <branch>:
===================================
`git config branch.master.pushRemote publish`
===================================


SEE ALSO
--------
linkgit:gittutorial[7],
linkgit:git-push[1],
linkgit:git-pull[1],
linkgit:git-merge[1],
linkgit:git-rebase[1],
linkgit:git-format-patch[1],
linkgit:git-send-email[1],
linkgit:git-am[1]

GIT
---
Part of the linkgit:git[1] suite

debug log:

solving 21f6dc8 ...
found 21f6dc8 in https://public-inbox.org/git/1512034932-14499-1-git-send-email-timothee.albertin@etu.univ-lyon1.fr/
found 02569d0 in https://80x24.org/mirrors/git.git
preparing index
index prepared:
100644 02569d0614773276841a1d91a7b90cb353b8ba5e	Documentation/gitworkflows.txt

applying [1/1] https://public-inbox.org/git/1512034932-14499-1-git-send-email-timothee.albertin@etu.univ-lyon1.fr/
diff --git a/Documentation/gitworkflows.txt b/Documentation/gitworkflows.txt
index 02569d0..21f6dc8 100644

1:64: trailing whitespace.
With the triangular workflow, the contributors have the write 
Checking patch Documentation/gitworkflows.txt...
Applied patch Documentation/gitworkflows.txt cleanly.
warning: 1 line adds whitespace errors.

index at:
100644 21f6dc8fb2f00bad170395b17008cccb0e880b67	Documentation/gitworkflows.txt

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).