1dgit-maint-debrebase(7)              dgit              dgit-maint-debrebase(7)
2
3
4

NAME

6       dgit - tutorial for package maintainers, using a workflow centered
7       around git-debrebase(1)
8

INTRODUCTION

10       This document describes elements of a workflow for maintaining a non-
11       native Debian package using dgit.  We maintain the Debian delta as a
12       series of git commits on our master branch.  We use git-debrebase(1) to
13       shuffle our branch such that this series of git commits appears at the
14       end of the branch.  All the public git history is fast-forwarding,
15       i.e., we do not rewrite and force-push.
16
17       Some advantages of this workflow:
18
19       •   Manipulate the delta queue using the full power of git-rebase(1),
20           instead of relying on quilt(1), and without having to switch back
21           and forth between patches-applied and patches-unapplied branches
22           when committing changes and trying to build, as with gbp-pq(1).
23
24       •   If you are using 3.0 (quilt), provide your delta queue as a
25           properly separated series of quilt patches in the source package
26           that you upload to the archive (unlike with dgit-maint-merge(7)).
27
28       •   Avoid the git tree being dirtied by the application or
29           unapplication of patches, as they are always applied.
30
31       •   Benefit from dgit's safety catches.  In particular, ensure that
32           your upload always matches exactly your git HEAD.
33
34       •   Provide your full git history in a standard format on dgit-repos,
35           where it can benefit downstream dgit users, such as people using
36           dgit to do an NMU (see dgit-nmu-simple(7) and dgit-user(7)).
37
38       •   Minimise the amount you need to know about 3.0 (quilt) in order to
39           maintain Debian source packages which use that format.
40
41       This workflow is appropriate for packages where the Debian delta
42       contains multiple pieces which interact, or which you don't expect to
43       be able to upstream soon.  For packages with simple and/or short-lived
44       Debian deltas, use of git-debrebase(1) introduces unneeded complexity.
45       For such packages, consider the workflow described in
46       dgit-maint-merge(7).
47

INITIAL DEBIANISATION

49       This section explains how to start using this workflow with a new
50       package.  It should be skipped when converting an existing package to
51       this workflow.
52
53   When upstream tags releases in git
54       Suppose that the latest stable upstream release is 1.2.2, and this has
55       been tagged '1.2.2' by upstream.
56
57           % git clone -oupstream https://some.upstream/foo.git
58           % cd foo
59           % git verify-tag 1.2.2
60           % git reset --hard 1.2.2
61           % git branch --unset-upstream
62
63       The final command detaches your master branch from the upstream remote,
64       so that git doesn't try to push anything there, or merge unreleased
65       upstream commits.  To maintain a copy of your packaging branch on
66       salsa.debian.org in addition to dgit-repos, you can do something like
67       this:
68
69           % git remote add -f origin salsa.debian.org:Debian/foo.git
70           % git push --follow-tags -u origin master
71
72       Now go ahead and Debianise your package.  Make commits on the master
73       branch, adding things in the debian/ directory, or patching the
74       upstream source.  For technical reasons, it is essential that your
75       first commit introduces the debian/ directory containing at least one
76       file, and does nothing else. In other words, make a commit introducing
77       debian/ before patching the upstream source.
78
79       Finally, you need an orig tarball:
80
81           % git deborig
82
83       See git-deborig(1) if this fails.
84
85       This tarball is ephemeral and easily regenerated, so we don't commit it
86       anywhere (e.g. with tools like pristine-tar(1)).
87
88       Comparing upstream's tarball releases
89
90           The above assumes that you know how to build the package from git
91           and that doing so is straightforward.
92
93           If, as a user of the upstream source, you usually build from
94           upstream tarball releases, rather than upstream git tags, you will
95           sometimes find that the git tree doesn't contain everything that is
96           in the tarball.
97
98           Additional build steps may be needed.  For example, you may need
99           your debian/rules to run autotools.
100
101           You can compare the upstream tarball release, and upstream git tag,
102           within git, by importing the tarball into git as described in the
103           next section, using a different value for 'upstream-tag', and then
104           using git-diff(1) to compare the imported tarball to the release
105           tag.
106
107       Using untagged upstream commits
108
109           Sometimes upstream does not tag their releases, or you want to
110           package an unreleased git snapshot.  In such a case you can create
111           your own upstream release tag, of the form upstream/ver, where ver
112           is the upstream version you plan to put in debian/changelog.  The
113           upstream/ prefix ensures that your tag will not clash with any tags
114           upstream later creates.
115
116           For example, suppose that the latest upstream release is 1.2.2 and
117           you want to package git commit ab34c21 which was made on
118           2013-12-11.  A common convention is to use the upstream version
119           number 1.2.2+git20131211.ab34c21 and so you could use
120
121               % git tag -s upstream/1.2.2+git20131211.ab34c21 ab34c21
122
123           to obtain a release tag, and then proceed as above.
124
125           One can generate such a versioned tag using git show's --pretty
126           option. e.g.:
127
128               % git tag -s upstream/$(git show --date=format:%Y%m%d --pretty=format:"1.2.2+git%cd.%h" --quiet upstream/main) upstream/main
129
130   When upstream releases only tarballs
131       Because we want to work in git, we need a virtual upstream branch with
132       virtual release tags.  gbp-import-orig(1) can manage this for us.  To
133       begin
134
135           % mkdir foo
136           % cd foo
137           % git init
138           % git checkout -b upstream
139           % gbp import-orig \
140               --upstream-branch=upstream --debian-branch=master \
141               --upstream-tag='upstream/%(version)s' \
142               --sign-tags --no-pristine-tar \
143               ../foo_1.2.2.orig.tar.xz
144           % git branch -f upstream
145
146       This should leave you on the master branch.  Next, our upstream branch
147       cannot be pushed to dgit-repos, but since we will need it whenever we
148       import a new upstream version, we must push it somewhere.  The usual
149       choice is salsa.debian.org:
150
151           % git remote add -f origin salsa.debian.org:Debian/foo.git
152           % git push --follow-tags -u origin master upstream
153
154       You are now ready to proceed as above, making commits to the debian/
155       directory and to the upstream source.  As above, for technical reasons,
156       it is essential that your first commit introduces the debian/ directory
157       containing at least one file, and does nothing else.  In other words,
158       make a commit introducing debian/ before patching the upstream source.
159
160       A convenient way to ensure this requirement is satisfied is to start by
161       creating debian/gbp.conf:
162
163           [DEFAULT]
164           upstream-branch = upstream
165           debian-branch = master
166           upstream-tag = upstream/%(version)s
167
168           sign-tags = True
169           pristine-tar = False
170           pristine-tar-commit = False
171
172           [import-orig]
173           merge = False
174
175       and commit that:
176
177           % git add debian/gbp.conf && git commit -m "create gbp.conf"
178
179       Note that we couldn't create debian/gbp.conf before now for the same
180       technical reasons which require our first commit to introduce debian/
181       without patching the upstream source.  That's why we had to pass a lot
182       of options to our first call to gbp-import-orig(1).
183

CONVERTING AN EXISTING PACKAGE

185       This section explains how to convert an existing Debian package to this
186       workflow.  It should be skipped when debianising a new package.
187
188       If you have an existing git history that you have pushed to an ordinary
189       git server like salsa.debian.org, we start with that.  If you don't
190       already have it locally, you'll need to clone it, and obtain the
191       corresponding orig.tar from the archive:
192
193           % git clone salsa.debian.org:Debian/foo
194           % cd foo
195           % dgit setup-new-tree
196           % origtargz
197
198       If you don't have any existing git history, or you have history only on
199       the special dgit-repos server, we start with dgit clone:
200
201           % dgit clone foo
202           % cd foo
203
204       Then we make new upstream tags available:
205
206           % git remote add -f upstream https://some.upstream/foo.git
207
208       We now use a git debrebase convert-from-* command to convert your
209       existing history to the git-debrebase(5) data model.  Which command you
210       should use depends on some facts about your repository:
211
212       (A) There is no delta queue.
213           If there do not exist any Debian patches, use
214
215               % git debrebase convert-from-gbp
216
217       (B) There is a delta queue, and patches are unapplied.
218           This is the standard git-buildpackage(1) workflow: there are Debian
219           patches, but the upstream source is committed to git without those
220           patches applied.  Use
221
222               % git debrebase convert-from-gbp
223
224           If you were not previously using dgit to upload your package (i.e.
225           you were not using the workflow described in dgit-maint-gbp(7)),
226           and you happen to have run dgit fetch sid in this clone of the
227           repository, you will need to pass --fdiverged to this command.
228
229       (C) There is a delta queue, and patches are applied.
230           Use
231
232               % git debrebase convert-from-dgit-view
233
234       Finally, you need to ensure that your git HEAD is dgit-compatible,
235       i.e., it is exactly what you would get if you deleted .git, invoked
236       dpkg-buildpackage -S, and then unpacked the resultant source package.
237
238       To achieve this, you might need to delete debian/source/local-options.
239       One way to have dgit check your progress is to run dgit build-source.
240

GIT CONFIGURATION

242       git-debrebase(1) does not yet support using git merge to merge
243       divergent branches of development (see "OTHER MERGES" in
244       git-debrebase(5)).  You should configure git such that git pull does
245       not try to merge:
246
247           % git config --local pull.rebase true
248
249       Now when you pull work from other Debian contributors, git will rebase
250       your work on top of theirs.
251
252       If you use this clone for upstream development in addition to Debian
253       packaging work, you may not want to set this global setting.  Instead,
254       see the branch.autoSetupRebase and branch.<name>.rebase settings in
255       git-config(5).
256

IMPORTING NEW UPSTREAM RELEASES

258       There are two steps: obtaining git refs that correspond to the new
259       release, and importing that release using git-debrebase(1).
260
261   Obtaining the release
262       When upstream tags releases in git
263
264           % git fetch --tags upstream
265
266       If you want to package an untagged upstream commit (because upstream
267       does not tag releases or because you want to package an upstream
268       development snapshot), see "Using untagged upstream commits" above.
269
270       When upstream releases only tarballs
271
272       You will need the debian/gbp.conf from "When upstream releases only
273       tarballs", above.  You will also need your upstream branch.  Above, we
274       pushed this to salsa.debian.org.  You will need to clone or fetch from
275       there, instead of relying on dgit clone/dgit fetch alone.
276
277       Then, either
278
279           % gbp import-orig ../foo_1.2.3.orig.tar.xz
280
281       or if you have a working watch file
282
283           % gbp import-orig --uscan
284
285   Importing the release
286           % git debrebase new-upstream 1.2.3
287
288       This invocation of git-debrebase(1) involves a git rebase.  You may
289       need to resolve conflicts if the Debian delta queue does not apply
290       cleanly to the new upstream source.
291
292       If all went well, you can now review the merge of the new upstream
293       release:
294
295           git diff debian/1.2.2-1..HEAD -- . ':!debian'
296
297       Also, diff with --name-status and --diff-filter=ADR to see just the
298       list of added or removed files, which is useful to determine whether
299       there are any new or deleted files that may need accounting for in your
300       copyright file.
301
302       If you obtained a tarball from upstream, you are ready to try a build.
303       If you merged a git tag from upstream, you will first need to generate
304       a tarball:
305
306           % git deborig
307

EDITING THE DEBIAN PACKAGING

309       Just make commits on master that change the contents of debian/.
310

EDITING THE DELTA QUEUE

312   Adding new patches
313       Adding new patches is straightforward: just make commits touching only
314       files outside of the debian/ directory.  You can also use tools like
315       git-revert(1), git-am(1) and git-cherry-pick(1).
316
317   Editing patches: starting a debrebase
318       git-debrebase(1) is a wrapper around git-rebase(1) which allows us to
319       edit, re-order and delete patches.  Run
320
321           % git debrebase -i
322
323       to start an interactive rebase.  You can edit, re-order and delete
324       commits just as you would during git rebase -i.
325
326   Editing patches: finishing a debrebase
327       After completing the git rebase, your branch will not be a fast-forward
328       of the git HEAD you had before the rebase.  This means that we cannot
329       push the branch anywhere.  If you are ready to upload, dgit push-source
330       (or dgit push-built) will take care of fixing this up for you.
331
332       If you are not yet ready to upload, and want to push your branch to a
333       git remote such as salsa.debian.org,
334
335           % git debrebase conclude
336
337       Note that each time you conclude a debrebase you introduce a
338       pseudomerge into your git history, which may make it harder to read.
339       Try to do all of the editing of the delta queue that you think will be
340       needed for this editing session in a single debrebase, so that there is
341       a single debrebase stitch.
342

BUILDING AND UPLOADING

344       You can use dpkg-buildpackage(1) for test builds.  When you are ready
345       to build for an upload, use dgit sbuild, dgit pbuilder or dgit
346       cowbuilder.
347
348       Upload with dgit push-source or dgit push-built.  Remember to pass
349       --new if the package is new in the target suite.
350
351       In some cases where you used git debrebase convert-from-gbp since the
352       last upload, it is not possible for dgit to make your history fast-
353       forwarding from the history on dgit-repos.  In such cases you will have
354       to pass --overwrite to dgit.  git-debrebase will normally tell you if
355       this will be needed.
356
357       If you want to upload with git-debpush(1), for the first upload you
358       should pass the --quilt=linear quilt mode option (see git-debpush(1)).
359
360       Right before uploading, if you did not just already do so, you might
361       want to have git-debrebase(1) shuffle your branch such that the Debian
362       delta queue appears right at the tip of the branch you will push:
363
364           % git debrebase
365           % dgit push-source
366
367       Note that this will introduce a new pseudomerge.
368
369       After dgit pushing, be sure to git push to salsa.debian.org, if you're
370       using that.
371

HANDLING DFSG-NON-FREE MATERIAL

373   Illegal material
374       Here we explain how to handle material that is merely DFSG-non-free.
375       Material which is legally dangerous (for example, files which are
376       actually illegal) cannot be handled this way.
377
378       If you encounter possibly-legally-dangerous material in the upstream
379       source code you should seek advice.  It is often best not to make a
380       fuss on a public mailing list (at least, not at first).  Instead, email
381       your archive administrators.  For Debian that is
382        To: dgit-owner@debian.org, ftpmaster@ftp-master.debian.org
383
384   DFSG-non-free: When upstream tags releases in git
385       Our approach is to maintain a DFSG-clean upstream branch, and create
386       tags on this branch for each release that we want to import.  We then
387       import those tags per "Importing the release", above.  In the case of a
388       new package, we base our initial Debianisation on our first DFSG-clean
389       tag.
390
391       For the first upstream release that requires DFSG filtering:
392
393           % git checkout -b upstream-dfsg 1.2.3
394           % git rm evil.bin
395           % git commit -m "upstream version 1.2.3 DFSG-cleaned"
396           % git tag -s 1.2.3+dfsg
397           % git checkout master
398
399       Now either proceed with "Importing the release" on the 1.2.3+dfsg tag,
400       or in the case of a new package,
401
402           % git branch --unset-upstream
403           % git reset --hard 1.2.3+dfsg
404
405       and proceed with "INITIAL DEBIANISATION".
406
407       For subsequent releases (whether or not they require additional
408       filtering):
409
410           % git checkout upstream-dfsg
411           % git merge 1.2.4
412           % git rm further-evil.bin # if needed
413           % git commit -m "upstream version 1.2.4 DFSG-cleaned" # if needed
414           % git tag -s 1.2.4+dfsg
415           % git checkout master
416           % # proceed with "Importing the release" on 1.2.4+dfsg tag
417
418       Our upstream-dfsg branch cannot be pushed to dgit-repos, but since we
419       will need it whenever we import a new upstream version, we must push it
420       somewhere.  Assuming that you have already set up an origin remote per
421       the above,
422
423           % git push --follow-tags -u origin master upstream-dfsg
424
425   DFSG-non-free: When upstream releases only tarballs
426       The easiest way to handle this is to add a Files-Excluded field to
427       debian/copyright, and a uversionmangle setting in debian/watch.  See
428       uscan(1).  Alternatively, see the --filter option detailed in
429       gbp-import-orig(1).
430

INCORPORATING NMUS

432       In the simplest case,
433
434           % dgit fetch
435           % git merge --ff-only dgit/dgit/sid
436
437       If that fails, because your branch and the NMUers' work represent
438       divergent branches of development, you have a number of options.  Here
439       we describe the two simplest.
440
441       Note that you should not try to resolve the divergent branches by
442       editing files in debian/patches.  Changes there would either cause
443       trouble, or be overwritten by git-debrebase(1).
444
445   Rebasing your work onto the NMU
446           % git rebase dgit/dgit/sid
447
448       If the NMUer added new commits modifying the upstream source, you will
449       probably want to debrebase before your next upload to tidy those up.
450
451       For example, the NMUer might have used git-revert(1) to unapply one of
452       your patches.  A debrebase can be used to strip both the patch and the
453       reversion from the delta queue.
454
455   Manually applying the debdiff
456       If you cannot rebase because you have already pushed to
457       salsa.debian.org, say, you can manually apply the NMU debdiff, commit
458       and debrebase.  The next dgit push will require --overwrite.
459

HINTS AND TIPS

461   Minimising pseudomerges
462       Above we noted that each time you conclude a debrebase, you introduce a
463       pseudomerge into your git history, which may make it harder to read.
464
465       A simple convention you can use to minimise the number of pseudomerges
466       is to git debrebase conclude only right before you upload or push to
467       salsa.debian.org.
468
469       It is possible, though much less convenient, to reduce the number of
470       pseudomerges yet further.  We debrebase only (i) when importing a new
471       release, and (ii) right before uploading.  Instead of editing the
472       existing delta queue, you append fixup commits (and reversions of
473       commits) that alter the upstream source to the required state.  You can
474       push and pull to and from salsa.debian.org during this.  Just before
475       uploading, you debrebase, once, to tidy everything up.
476
477   The debian/patches directory
478       In this workflow, debian/patches is purely an output of
479       git-debrebase(1).  You should not make changes there.  They will either
480       cause trouble, or be ignored and overwritten by git-debrebase(1).
481
482       debian/patches will often be out-of-date because git-debrebase(1) will
483       only regenerate it when it needs to.  So you should not rely on the
484       information in that directory.  When preparing patches to forward
485       upstream, you should use git-format-patch(1) on git commits, rather
486       than sending files from debian/patches.
487
488   Upstream branches
489       In this workflow, we specify upstream tags rather than any branches.
490
491       Except when (i) upstream releases only tarballs, (ii) we require DFSG
492       filtering, or (iii) you also happen to be involved in upstream
493       development, we do not maintain any local branch corresponding to
494       upstream, except temporary branches used to prepare patches for
495       forwarding, and the like.
496
497       The idea here is that from Debian's point of view, upstream releases
498       are immutable points in history.  We want to make sure that we are
499       basing our Debian package on a properly identified upstream version,
500       rather than some arbitrary commit on some branch.  Tags are more useful
501       for this.
502
503       Upstream's branches remain available as the git remote tracking
504       branches for your upstream remote, e.g. remotes/upstream/master.
505
506   The first ever dgit push
507       If this is the first ever dgit push of the package, consider passing
508       --deliberately-not-fast-forward instead of --overwrite.  This avoids
509       introducing a new origin commit into your git history.  (This origin
510       commit would represent the most recent non-dgit upload of the package,
511       but this should already be represented in your git history.)
512
513   Inspecting the history
514       The git history made by git-debrebase can seem complicated.  Here are
515       some suggestions for helpful invocations of gitk and git.  They can be
516       adapted for other tools like tig(1), git-log(1), magit, etc.
517
518       History of package in Debian, disregarding history from upstream:
519
520           % gitk --first-parent
521
522           In a laundered branch, the delta queue is at the top.
523
524       History of the packaging, excluding the delta queue:
525
526           % gitk :/debian :!/debian/patches
527
528       Just the delta queue (i.e. Debian's changes to upstream):
529
530           % gitk --first-parent -- :/ :!/debian
531
532       Full history including old versions of the delta queue:
533
534           % gitk --date-order
535
536           The "Declare fast forward" commits you see have an older history
537           (usually, an older delta queue) as one parent, and a newer history
538           as the other.  --date-order makes gitk show the delta queues in the
539           right order.
540
541       Complete diff since the last upload:
542
543           % git diff dgit/dgit/sid..HEAD -- :/ :!/debian/patches
544
545           This includes changes to upstream files.
546
547       Interdiff of delta queue since last upload, if you really want it:
548
549           % git debrebase make-patches
550           % git diff dgit/dgit/sid..HEAD -- debian/patches
551
552       And of course there is:
553
554           % git debrebase status
555
556   Alternative ways to start a debrebase
557       Above we started an interactive debrebase by invoking git-debrebase(1)
558       like this:
559
560           % git debrebase -i
561
562       It is also possible to perform a non-interactive rebase, like this:
563
564           % git debrebase -- [git-rebase options...]
565
566       A third alternative is to have git-debrebase(1) shuffle all the Debian
567       changes to the end of your branch, and then manipulate them yourself
568       using git-rebase(1) directly.  For example,
569
570           % git debrebase
571           % git rebase -i HEAD~5      # there are 4 Debian patches
572
573       If you take this approach, you should be very careful not to start the
574       rebase too early, including before the most recent pseudomerge.  git-
575       rebase without a base argument will often start the rebase too early,
576       and should be avoided.  Run git-debrebase instead.  See also "ILLEGAL
577       OPERATIONS" in git-debrebase(5).
578

SEE ALSO

580       dgit(1), dgit(7), git-debrebase(1), git-debrebase(5)
581

AUTHOR

583       This tutorial was written and is maintained by Sean Whitton
584       <spwhitton@spwhitton.name>.  It contains contributions from other dgit
585       contributors too - see the dgit copyright file.
586
587
588
589perl v5.36.0                    Debian Project         dgit-maint-debrebase(7)
Impressum