3 dgit - tutorial for package maintainers, using a workflow centered around git-debrebase(1)
7 This document describes elements of a workflow for maintaining a
8 non-native Debian package using B<dgit>. We maintain the Debian delta
9 as a series of git commits on our master branch. We use
10 git-debrebase(1) to shuffle our branch such that this series of git
11 commits appears at the end of the branch. All the public git history
12 is fast-forwarding, i.e., we do not rewrite and force-push.
14 Some advantages of this workflow:
20 Manipulate the delta queue using the full power of git-rebase(1),
21 instead of relying on quilt(1), and without having to switch back and
22 forth between patches-applied and patches-unapplied branches when
23 committing changes and trying to build, as with gbp-pq(1).
27 If you are using 3.0 (quilt), provide your delta queue as a properly
28 separated series of quilt patches in the source package that you
29 upload to the archive (unlike with dgit-maint-merge(7)).
33 Avoid the git tree being dirtied by the application or unapplication
34 of patches, as they are always applied.
38 Benefit from dgit's safety catches. In particular, ensure that your
39 upload always matches exactly your git HEAD.
43 Provide your full git history in a standard format on B<dgit-repos>,
44 where it can benefit downstream dgit users, such as people using dgit
45 to do an NMU (see dgit-nmu-simple(7) and dgit-user(7)).
49 Minimise the amount you need to know about 3.0 (quilt) in order to
50 maintain Debian source packages which use that format.
54 This workflow is appropriate for packages where the Debian delta
55 contains multiple pieces which interact, or which you don't expect to
56 be able to upstream soon. For packages with simple and/or short-lived
57 Debian deltas, use of git-debrebase(1) introduces unneeded complexity.
58 For such packages, consider the workflow described in
61 =head1 INITIAL DEBIANISATION
63 This section explains how to start using this workflow with a new
64 package. It should be skipped when converting an existing package to
67 =head2 When upstream tags releases in git
69 Suppose that the latest stable upstream release is 1.2.2, and this has
70 been tagged '1.2.2' by upstream.
74 % git clone -oupstream https://some.upstream/foo.git
76 % git verify-tag 1.2.2
77 % git reset --hard 1.2.2
78 % git branch --unset-upstream
82 The final command detaches your master branch from the upstream
83 remote, so that git doesn't try to push anything there, or merge
84 unreleased upstream commits. To maintain a copy of your packaging
85 branch on B<salsa.debian.org> in addition to B<dgit-repos>, you can do
90 % git remote add -f origin salsa.debian.org:Debian/foo.git
91 % git push --follow-tags -u origin master
95 Now go ahead and Debianise your package. Make commits on the master
96 branch, adding things in the I<debian/> directory, or patching the
97 upstream source. For technical reasons, B<it is essential that your
98 first commit introduces the debian/ directory containing at least one
99 file, and does nothing else.> In other words, make a commit
100 introducing I<debian/> before patching the upstream source.
102 Finally, you need an orig tarball:
110 See git-deborig(1) if this fails.
112 This tarball is ephemeral and easily regenerated, so we don't commit
113 it anywhere (e.g. with tools like pristine-tar(1)).
115 =head3 Comparing upstream's tarball releases
119 The above assumes that you know how to build the package from git and
120 that doing so is straightforward.
122 If, as a user of the upstream source, you usually build from upstream
123 tarball releases, rather than upstream git tags, you will sometimes
124 find that the git tree doesn't contain everything that is in the
127 Additional build steps may be needed. For example, you may need your
128 I<debian/rules> to run autotools.
130 You can compare the upstream tarball release, and upstream git tag,
131 within git, by importing the tarball into git as described in the
132 next section, using a different value for 'upstream-tag', and then
133 using git-diff(1) to compare the imported tarball to the release tag.
137 =head2 When upstream releases only tarballs
139 Because we want to work in git, we need a virtual upstream branch with
140 virtual release tags. gbp-import-orig(1) can manage this for us. To
151 Now create I<debian/gbp.conf>:
156 upstream-branch = upstream
157 debian-branch = master
158 upstream-tag = %(version)s
162 pristine-tar-commit = False
169 gbp-import-orig(1) requires a pre-existing upstream branch:
173 % git add debian/gbp.conf && git commit -m "create gbp.conf"
174 % git checkout --orphan upstream
176 % git commit --allow-empty -m "initial, empty branch for upstream source"
177 % git checkout -f master
181 Then we can import the upstream version:
185 % gbp import-orig --merge-mode=replace ../foo_1.2.2.orig.tar.xz
189 Our upstream branch cannot be pushed to B<dgit-repos>, but since we
190 will need it whenever we import a new upstream version, we must push
191 it somewhere. The usual choice is B<salsa.debian.org>:
195 % git remote add -f origin salsa.debian.org:Debian/foo.git
196 % git push --follow-tags -u origin master upstream
200 You are now ready to proceed as above, making commits to the
201 I<debian/> directory and to the upstream source. As above, for
202 technical reasons, B<it is essential that your first commit introduces
203 the debian/ directory containing at least one file, and does nothing
204 else.> In other words, make a commit introducing I<debian/> before
205 patching the upstream source.
207 =head1 CONVERTING AN EXISTING PACKAGE
209 This section explains how to convert an existing Debian package to
210 this workflow. It should be skipped when debianising a new package.
212 =head2 No existing git history
218 % git remote add -f upstream https://some.upstream/foo.git
222 =head2 Existing git history using another workflow
224 First, if you don't already have the git history locally, clone it,
225 and obtain the corresponding orig.tar from the archive:
229 % git clone salsa.debian.org:Debian/foo
235 If your tree is patches-unapplied, some conversion work is needed.
240 git debrebase convert-from-gbp
244 Then make new upstream tags available:
248 % git remote add -f upstream https://some.upstream/foo.git
252 Now you simply need to ensure that your git HEAD is dgit-compatible,
253 i.e., it is exactly what you would get if you deleted .git, invoked
254 B<dpkg-buildpackage -S>, and then unpacked the resultant source
257 To achieve this, you might need to delete
258 I<debian/source/local-options>. One way to have dgit check your
259 progress is to run B<dgit build-source>.
261 The first dgit push will require I<--overwrite>.
263 =head1 GIT CONFIGURATION
265 git-debrebase(1) does not yet support using B<git merge> to merge
266 divergent branches of development (see "OTHER MERGES" in
267 git-debrebase(5)). You should configure git such that B<git pull>
268 does not try to merge:
272 % git config --local pull.rebase true
276 Now when you pull work from other Debian contributors, git will rebase
277 your work on top of theirs.
279 If you use this clone for upstream development in addition to
280 Debian packaging work, you may not want to set this global setting.
281 Instead, see the B<branch.autoSetupRebase> and
282 B<branch.E<lt>nameE<gt>.rebase> settings in git-config(5).
284 =head1 IMPORTING NEW UPSTREAM RELEASES
286 There are two steps: obtaining git refs that correspond to the new
287 release, and importing that release using git-debrebase(1).
289 =head2 Obtaining the release
291 =head3 When upstream tags releases in git
299 =head3 When upstream releases only tarballs
301 You will need the I<debian/gbp.conf> from "When upstream releases only
302 tarballs", above. You will also need your upstream branch. Above, we
303 pushed this to B<salsa.debian.org>. You will need to clone or fetch
304 from there, instead of relying on B<dgit clone>/B<dgit fetch> alone.
310 % gbp import-orig --no-merge ../foo_1.2.3.orig.tar.xz
314 or if you have a working watch file
318 % gbp import-orig --no-merge --uscan
322 =head2 Importing the release
326 % git debrebase new-upstream 1.2.3
330 This invocation of git-debrebase(1) involves a git rebase. You may
331 need to resolve conflicts if the Debian delta queue does not apply
332 cleanly to the new upstream source.
334 If all went well, you can now review the merge of the new upstream
339 git diff debian/1.2.2-1..HEAD -- . ':!debian'
343 Pass I<--stat> just to see the list of changed files, which is useful
344 to determine whether there are any new or deleted files to may need
345 accounting for in your copyright file.
347 If you obtained a tarball from upstream, you are ready to try a build.
348 If you merged a git tag from upstream, you will first need to generate
357 =head1 EDITING THE DEBIAN PACKAGING
359 Just make commits on master that change the contents of I<debian/>.
361 =head1 EDITING THE DELTA QUEUE
363 =head2 Adding new patches
365 Adding new patches is straightforward: just make commits touching only
366 files outside of the I<debian/> directory. You can also use tools
367 like git-revert(1), git-am(1) and git-cherry-pick(1).
369 =head2 Editing patches: starting a debrebase
371 git-debrebase(1) is a wrapper around git-rebase(1) which allows us to
372 edit, re-order and delete patches. Run
380 to start an interactive rebase. You can edit, re-order and delete
381 commits just as you would during B<git rebase -i>.
383 =head2 Editing patches: finishing a debrebase
385 After completing the git rebase, your branch will not be a
386 fast-forward of the git HEAD you had before the rebase. This means
387 that we cannot push the branch anywhere. If you are ready to upload,
388 B<dgit push> or B<dgit push-source> will take care of fixing this up
391 If you are not yet ready to upload, and want to push your branch to a
392 git remote such as B<salsa.debian.org>,
396 % git debrebase conclude
400 Note that each time you conclude a debrebase you introduce a
401 pseudomerge into your git history, which may make it harder to read.
402 Try to do all of the editing of the delta queue that you think will be
403 needed for this editing session in a single debrebase, so that there
404 is a single debrebase stitch.
406 =head1 BUILDING AND UPLOADING
408 You can use dpkg-buildpackage(1) for test builds. When you are ready
409 to build for an upload, use B<dgit sbuild>, B<dgit pbuilder> or B<dgit
412 Upload with B<dgit push> or B<dgit push-source>. Remember to pass
413 I<--new> if the package is new in the target suite.
415 Right before uploading, if you did not just already do so, you might
416 want to have git-debrebase(1) shuffle your branch such that the Debian
417 delta queue appears right at the tip of the branch you will push:
426 Note that this will introduce a new pseudomerge.
428 After dgit pushing, be sure to git push to B<salsa.debian.org>, if
431 =head1 HANDLING DFSG-NON-FREE MATERIAL
433 =head2 Illegal material
435 Here we explain how to handle material that is merely DFSG-non-free.
436 Material which is legally dangerous (for example, files which are
437 actually illegal) cannot be handled this way.
439 If you encounter possibly-legally-dangerous material in the upstream
440 source code you should seek advice. It is often best not to make a
441 fuss on a public mailing list (at least, not at first). Instead,
442 email your archive administrators. For Debian that is
443 To: dgit-owner@debian.org, ftpmaster@ftp-master.debian.org
445 =head2 DFSG-non-free: When upstream tags releases in git
447 Our approach is to maintain a DFSG-clean upstream branch, and create
448 tags on this branch for each release that we want to import. We then
449 import those tags per "Importing the release", above.
451 For the first upstream release that requires DFSG filtering:
455 % git checkout -b upstream-dfsg 1.2.3
457 % git commit -m "upstream version 1.2.3 DFSG-cleaned"
458 % git tag -s 1.2.3+dfsg
459 % git checkout master
460 % # proceed with "Importing the release" on 1.2.3+dfsg tag
464 And for subsequent releases (whether or not they require filtering):
468 % git checkout upstream-dfsg
470 % git rm further-evil.bin # if needed
471 % git commit -m "upstream version 1.2.4 DFSG-cleaned" # if needed
472 % git tag -s 1.2.4+dfsg
473 % git checkout master
474 % # proceed with "Importing the release" on 1.2.4+dfsg tag
478 Our upstream-dfsg branch cannot be pushed to B<dgit-repos>, but since
479 we will need it whenever we import a new upstream version, we must
480 push it somewhere. Assuming that you have already set up an origin
481 remote per the above,
485 % git push --follow-tags -u origin master upstream-dfsg
489 =head2 DFSG-non-free: When upstream releases only tarballs
491 The easiest way to handle this is to add a B<Files-Excluded> field to
492 I<debian/copyright>, and a B<uversionmangle> setting in
493 I<debian/watch>. See uscan(1). Alternatively, see the I<--filter>
494 option detailed in gbp-import-orig(1).
496 =head1 INCORPORATING NMUS
498 In the simplest case,
503 % git merge --ff-only dgit/dgit/sid
507 If that fails, because your branch and the NMUers work represent
508 divergent branches of development, you have a number of options. Here
509 we describe the two simplest.
511 Note that you should not try to resolve the divergent branches by
512 editing files in I<debian/patches>. Changes there would either cause
513 trouble, or be overwritten by git-debrebase(1).
515 =head2 Rebasing your work onto the NMU
519 % git rebase dgit/dgit/sid
523 If the NMUer added new commits modifying the upstream source, you will
524 probably want to debrebase before your next upload to tidy those up.
526 For example, the NMUer might have used git-revert(1) to unapply one of
527 your patches. A debrebase can be used to strip both the patch and the
528 reversion from the delta queue.
530 =head2 Manually applying the debdiff
532 If you cannot rebase because you have already pushed to
533 B<salsa.debian.org>, say, you can manually apply the NMU debdiff,
534 commit and debrebase. The next B<dgit push> will require
537 =head1 HINTS AND TIPS
539 =head2 Minimising pseudomerges
541 Above we noted that each time you conclude a debrebase, you introduce
542 a pseudomerge into your git history, which may make it harder to read.
544 A simple convention you can use to minimise the number of pseudomerges
545 is to B<git debrebase conclude> only right before you upload or push
546 to B<salsa.debian.org>.
548 It is possible, though much less convenient, to reduce the number of
549 pseudomerges yet further. We debrebase only (i) when importing a new
550 release, and (ii) right before uploading. Instead of editing the
551 existing delta queue, you append fixup commits (and reversions of
552 commits) that alter the upstream source to the required state. You
553 can push and pull to and from B<salsa.debian.org> during this. Just
554 before uploading, you debrebase, once, to tidy everything up.
556 =head2 The debian/patches directory
558 In this workflow, I<debian/patches> is purely an output of
559 git-debrebase(1). You should not make changes there. They will
560 either cause trouble, or be ignored and overwritten by
563 I<debian/patches> will often be out-of-date because git-debrebase(1)
564 will only regenerate it when it needs to. So you should not rely on
565 the information in that directory. When preparing patches to forward
566 upstream, you should use git-format-patch(1) on git commits, rather
567 than sending files from I<debian/patches>.
569 =head2 Upstream branches
571 In this workflow, we specify upstream tags rather than any branches.
573 Except when (i) upstream releases only tarballs, (ii) we require DFSG
574 filtering, or (iii) you also happen to be involved in upstream
575 development, we do not maintain any local branch corresponding to
576 upstream, except temporary branches used to prepare patches for
577 forwarding, and the like.
579 The idea here is that from Debian's point of view, upstream releases
580 are immutable points in history. We want to make sure that we are
581 basing our Debian package on a properly identified upstream version,
582 rather than some arbitrary commit on some branch. Tags are more
585 Upstream's branches remain available as the git remote tracking
586 branches for your upstream remote, e.g. I<remotes/upstream/master>.
588 =head2 The first ever dgit push
590 If this is the first ever dgit push of the package, consider passing
591 I<--deliberately-not-fast-forward> instead of I<--overwrite>. This
592 avoids introducing a new origin commit into your git history. (This
593 origin commit would represent the most recent non-dgit upload of the
594 package, but this should already be represented in your git history.)
596 =head2 Alternative ways to start a debrebase
598 Above we started an interactive debrebase by invoking git-debrebase(1)
607 It is also possible to perform a non-interactive rebase, like this:
611 % git debrebase -- [git-rebase options...]
616 A third alternative is to have git-debrebase(1) shuffle all the Debian
617 changes to the end of your branch, and then manipulate them yourself
618 using git-rebase(1) directly. For example,
623 % git rebase -i HEAD~5 # there are 4 Debian patches
627 If you take this approach, you should be very careful not to start the
629 including before the most recent pseudomerge.
630 git-rebase without a base argument will often
631 start the rebase too early,
632 and should be avoided.
633 Run git-debrebase instead.
637 dgit(1), dgit(7), git-debrebase(1), git-debrebase(5)
641 This tutorial was written and is maintained by Sean Whitton
642 <spwhitton@spwhitton.name>. It contains contributions from other dgit
643 contributors too - see the dgit copyright file.