3 dgit - tutorial for package maintainers, using a workflow centered around git-merge(1)
7 This document describes elements of a workflow for maintaining a
8 non-native Debian package using B<dgit>. The workflow makes the
9 following opinionated assumptions:
15 Git histories should be the non-linear histories produced by
16 git-merge(1), preserving all information about divergent development
17 that was later brought together.
21 Maintaining convenient and powerful git workflows takes priority over
22 the usefulness of the raw Debian source package. The Debian archive
23 is thought of as an output format.
25 For example, we don't spend time curating a series of quilt patches.
27 in straightforward cases,
28 the information such a series would contain is readily
29 available from B<dgit-repos>.
33 It is more important to have the Debian package's git history be a
34 descendent of upstream's git history than to use exactly the orig.tar
35 that upstream makes available for download.
39 This workflow is less suitable for some packages.
40 When the Debian delta contains multiple pieces which interact,
41 or which you aren't going to be able to upstream soon,
42 it might be preferable to
43 maintain the delta as a rebasing patch series.
44 For such a workflow see for example
47 =head1 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
53 =head2 When upstream tags releases in git
55 Suppose that the latest stable upstream release is 1.2.2, and this has
56 been tagged '1.2.2' by upstream.
60 % git clone -oupstream https://some.upstream/foo.git
62 % git verify-tag 1.2.2
63 % git reset --hard 1.2.2
64 % git branch --unset-upstream
68 The final command detaches your master branch from the upstream remote,
69 so that git doesn't try to push anything there, or merge unreleased
70 upstream commits. If you want to maintain a copy of your packaging
71 branch on B<alioth.debian.org> in addition to B<dgit-repos>, you can
72 do something like this:
76 % git remote add -f origin git.debian.org:/git/collab-maint/foo.git
77 % git push --follow-tags -u origin master
81 Now go ahead and Debianise your package. Just make commits on the
82 master branch, adding things in the I<debian/> directory. If you need
83 to patch the upstream source, just make commits that change files
84 outside of the I<debian/> directory. It is best to separate commits
85 that touch I<debian/> from commits that touch upstream source, so that
86 the latter can be cherry-picked by upstream.
88 Note that there is no need to maintain a separate 'upstream' branch,
89 unless you also happen to be involved in upstream development. We
90 work with upstream tags rather than any branches, except when
91 forwarding patches (see FORWARDING PATCHES UPSTREAM, below).
93 Finally, you need an orig tarball:
101 See git-deborig(1) if this fails.
103 This tarball is ephemeral and easily regenerated, so we don't commit
104 it anywhere (e.g. with tools like pristine-tar(1)).
106 =head3 Verifying upstream's tarball releases
110 It can be a good idea to compare upstream's released tarballs with the
111 release tags, at least for the first upload of the package. If they
112 are different, you might need to add some additional steps to your
113 I<debian/rules>, such as running autotools.
115 A convenient way to perform this check is to import the tarball as
116 described in the following section, using a different value for
117 'upstream-tag', and then use git-diff(1) to compare the imported
118 tarball to the release tag. If they are the same, you can use
119 upstream's tarball instead of running git-deborig(1).
123 =head2 When upstream releases only tarballs
125 We need a virtual upstream branch with virtual release tags.
126 gbp-import-orig(1) can manage this for us. To begin
136 Now create I<debian/gbp.conf>:
141 upstream-branch = upstream
142 debian-branch = master
143 upstream-tag = %(version)s
147 pristine-tar-commit = False
154 gbp-import-orig(1) requires a pre-existing upstream branch:
158 % git add debian/gbp.conf && git commit -m "create gbp.conf"
159 % git checkout --orphan upstream
161 % git commit --allow-empty -m "initial, empty branch for upstream source"
162 % git checkout -f master
166 Then we can import the upstream version:
170 % gbp import-orig --merge-mode=replace ../foo_1.2.2.orig.tar.xz
174 Our upstream branch cannot be pushed to B<dgit-repos>, but since we
175 will need it whenever we import a new upstream version, we must push
176 it somewhere. The usual choice is B<alioth.debian.org>:
180 % git remote add -f origin git.debian.org:/git/collab-maint/foo.git
181 % git push --follow-tags -u origin master upstream
185 You are now ready to proceed as above, making commits to both the
186 upstream source and the I<debian/> directory.
188 =head1 CONVERTING AN EXISTING PACKAGE
190 This section explains how to convert an existing Debian package to
191 this workflow. It should be skipped when debianising a new package.
193 =head2 No existing git history
199 % git remote add -f upstream https://some.upstream/foo.git
203 =head2 Existing git history using another workflow
205 First, if you don't already have the git history locally, clone it,
206 and obtain the corresponding orig.tar from the archive:
210 % git clone git.debian.org:collab-maint/foo
216 Now dump any existing patch queue:
220 % git rm -rf debian/patches
221 % git commit -m "drop existing quilt patch queue"
225 Then make new upstream tags available:
229 % git remote add -f upstream https://some.upstream/foo.git
233 =for dgit-test dpkg-source-ignores begin
235 Now you simply need to ensure that your git HEAD is dgit-compatible,
236 i.e., it is exactly what you would get if you ran
237 B<dpkg-buildpackage -i'(?:^|/)\.git(?:/|$)' -I.git -S>
238 and then unpacked the resultant source package.
240 =for dgit-test dpkg-source-ignores end
242 To achieve this, you might need to delete
243 I<debian/source/local-options>. One way to have dgit check your
244 progress is to run B<dgit build-source>.
246 The first dgit push will require I<--overwrite>. If this is the first
247 ever dgit push of the package, consider passing
248 I<--deliberately-not-fast-forward> instead of I<--overwrite>. This
249 avoids introducing a new origin commit into your git history. (This
250 origin commit would represent the most recent non-dgit upload of the
251 package, but this should already be represented in your git history.)
253 =head1 SOURCE PACKAGE CONFIGURATION
255 =head2 debian/source/options
257 We set some source package options such that dgit can transparently
258 handle the "dropping" and "refreshing" of changes to the upstream
268 You don't need to create this file if you are using the version 1.0
269 source package format.
271 =head2 Sample text for debian/source/patch-header
273 It is a good idea to explain how a user can obtain a breakdown of the
274 changes to the upstream source:
278 The Debian packaging of foo is maintained in git,
279 using the merging workflow described in dgit-maint-merge(7).
280 There isn't a patch queue that can be represented as a quilt series.
282 A detailed breakdown of the changes is available from their
283 canonical representation -
284 git commits in the packaging repository.
285 For example, to see the changes made by the Debian maintainer in the
286 first upload of upstream version 1.2.3, you could use:
290 % git clone https://git.dgit.debian.org/foo
292 % git log --oneline 1.2.3..debian/1.2.3-1 -- . ':!debian'
296 (If you have dgit, use `dgit clone foo`,
297 rather than plain `git clone`.)
299 A single combined diff, containing all the changes, follows.
303 If you are using the version 1.0 source package format, this text
304 should be added to README.source instead. The version 1.0 source
305 package format ignores debian/source/patch-header.
307 If you're using the version 3.0 (quilt) source package format, you
308 could add this text to README.source instead of
309 debian/source/patch-header, but this might distract from more
310 important information present in README.source.
312 =head1 BUILDING AND UPLOADING
314 Use B<dgit build>, B<dgit sbuild>, B<dgit build-source>, and B<dgit
315 push> as detailed in dgit(1). If any command fails, dgit will provide
316 a carefully-worded error message explaining what you should do. If
317 it's not clear, file a bug against dgit. Remember to pass I<--new>
318 for the first upload.
320 As an alternative to B<dgit build> and friends, you can use a tool
321 like gitpkg(1). This works because like dgit, gitpkg(1) enforces that
322 HEAD has exactly the contents of the source package. gitpkg(1) is
323 highly configurable, and one dgit user reports using it to produce and
324 test multiple source packages, from different branches corresponding
325 to each of the current Debian suites.
327 If you want to skip dgit's checks while iterating on a problem with
328 the package build (for example, you don't want to commit your changes
329 to git), you can just run dpkg-buildpackage(1) or debuild(1) instead.
331 =head1 NEW UPSTREAM RELEASES
333 =head2 Obtaining the release
335 =head3 When upstream tags releases in git
343 =head3 When upstream releases only tarballs
345 You will need the I<debian/gbp.conf> from "When upstream releases only
346 tarballs", above. You will also need your upstream branch. Above, we
347 pushed this to B<alioth.debian.org>. You will need to clone or fetch
348 from there, instead of relying on B<dgit clone>/B<dgit fetch> alone.
354 % gbp import-orig --no-merge ../foo_1.2.3.orig.tar.xz
358 or if you have a working watch file
362 % gbp import-orig --no-merge --uscan
366 =head2 Reviewing & merging the release
368 It's a good idea to preview the merge of the new upstream release.
369 First, just check for any new or deleted files that may need
370 accounting for in your copyright file:
374 % git diff --stat master..1.2.3 -- . ':!debian'
378 You can then review the full merge diff:
382 % git merge-tree `git merge-base master 1.2.3` master 1.2.3 | $PAGER
386 Once you're satisfied with what will be merged, update your package:
391 % dch -v1.2.3-1 New upstream release.
392 % git add debian/changelog && git commit -m changelog
396 If you obtained a tarball from upstream, you are ready to try a build.
397 If you merged a git tag from upstream, you will first need to generate
406 =head1 HANDLING DFSG-NON-FREE MATERIAL
408 =head2 When upstream tags releases in git
410 We create a DFSG-clean tag to merge to master:
414 % git checkout -b pre-dfsg 1.2.3
416 % git commit -m "upstream version 1.2.3 DFSG-cleaned"
417 % git tag -s 1.2.3+dfsg
418 % git checkout master
419 % git branch -D pre-dfsg
423 Before merging the new 1.2.3+dfsg tag to master, you should first
424 determine whether it would be legally dangerous for the non-free
425 material to be publicly accessible in the git history on
428 If it would be dangerous, there is a big problem;
429 in this case please consult your archive administrators
430 (for Debian this is the dgit administrator dgit-owner@debian.org
431 and the ftpmasters ftpmaster@ftp-master.debian.org).
433 =head2 When upstream releases only tarballs
435 The easiest way to handle this is to add a B<Files-Excluded> field to
436 I<debian/copyright>, and a B<uversionmangle> setting in
437 I<debian/watch>. See uscan(1). Alternatively, see the I<--filter>
438 option detailed in gbp-import-orig(1).
440 =head1 FORWARDING PATCHES UPSTREAM
448 Create a new branch based off upstream's master branch.
452 git-cherry-pick(1) commits from your master branch onto your new
457 Push the branch somewhere and ask upstream to merge it, or use
458 git-format-patch(1) or git-request-pull(1).
462 For example (and it is only an example):
466 % # fork foo.git on GitHub
467 % git remote add -f fork git@github.com:spwhitton/foo.git
468 % git checkout -b fix-error upstream/master
469 % git config branch.fix-error.pushRemote fork
470 % git cherry-pick master^2
472 % # submit pull request on GitHub
476 Note that when you merge an upstream release containing your forwarded
477 patches, git and dgit will transparently handle "dropping" the patches
478 that have been forwarded, "retaining" the ones that haven't.
480 =head1 INCORPORATING NMUS
488 Alternatively, you can apply the NMU diff to your repository. The
489 next push will then require I<--overwrite>.
497 This tutorial was written and is maintained by Sean Whitton <spwhitton@spwhitton.name>. It contains contributions from other dgit contributors too - see the dgit copyright file.