dgit-maint-debrebase(7)
π dgit-maint-debrebase β a dgit manual page, bestie edition π
okay so. this is dgit-maint-debrebase(7), and it's the dgit page that lives in section 7 of the manual (iykyk). grab a lil snack, we're doing this together π
πΈ NAME πΈ
dgit β tutorial for package maintainers, using a workflow centered around git-debrebase(1)
β¨ INTRODUCTION β¨
bestie this document is gonna walk you through elements of a workflow for maintaining a non-native Debian package using git-debrebase and git-debpush, plus a lil bit of dgit. the whole vibe: we keep the Debian delta as a series of git commits on our master branch. then we use git-debrebase(1) to shuffle our branch so that series of git commits ends up sitting at the end of the branch. and the public git history? all fast-forwarding. no cap. we do not rewrite and force-push. periodt. π
so why would you even want this? some advantages of this workflow:
- you manipulate the delta queue using the full power of
git-rebase(1), instead of relying onquilt(1), and without having to switch back and forth between patches-applied and patches-unapplied branches every time you commit changes and try to build, like you would withgbp-pq(1). iconic, honestly. - if you're using
3.0 (quilt), you get to provide your delta queue as a properly separated series of quilt patches in the source package you upload to the archive (unlike withdgit-maint-merge(7)). queen behaviour. - the git tree never gets dirtied by the application or unapplication of patches, because they're always applied. the way thatβ¦ π
- you benefit from dgit & tag2upload's safety catches. in particular, you ensure that your upload always matches exactly your git HEAD. no rogue drift, we don't know her.
- you provide your full git history in a standard format on dgit-repos, where it can benefit downstream dgit users β like people using dgit to do an NMU (see
dgit-nmu-simple(7)anddgit-user(7)). community service fr fr π«Ά - you minimise the amount you need to know about
3.0 (quilt)in order to maintain Debian source packages which use that format. less lore to memorise, more slay.
when is this workflow for you? it's appropriate for packages where the Debian delta contains multiple pieces which interact, or which you don't expect to be able to upstream soon. for packages with simple and/or short-lived Debian deltas, using git-debrebase(1) introduces unneeded complexity. for those, consider the workflow described in dgit-maint-merge(7). π
π INITIAL DEBIANISATION π
this section explains how to start using this workflow with a new package. skip it entirely when you're converting an existing package to this workflow, okay?
π¦ When upstream tags releases in git
suppose the latest stable upstream release is 1.2.2, and it's been tagged '1.2.2' by upstream. cool. then:
% git clone -oupstream https://some.upstream/foo.git
% cd foo
% git verify-tag 1.2.2
% git reset --hard 1.2.2
% git remote add -f origin git@salsa.debian.org:debian/foo.git
% git push --follow-tags -u origin master
that final command also has the effect of detaching your master branch from the upstream remote, so that git doesn't try to push anything there, or merge unreleased upstream commits. bye bestie π
now go ahead and Debianise your package. make commits on the master branch, adding things in the debian/ directory, or patching the upstream source.
technical reasons alert!! it is essential that your first commit introduces thedebian/directory containing at least one file, and does nothing else. in other words: make a commit introducingdebian/before patching the upstream source. do not skip this, do not get cute with it.
finally, you need an orig tarball:
% git deborig
see git-deborig(1) if this fails.
this tarball is ephemeral and easily regenerated, so we don't commit it anywhere (e.g. with tools like pristine-tar(1)). it's giving disposable π
π Comparing upstream's tarball releases
the above assumes that you know how to build the package from git and that doing so is straightforward.
if, as a user of the upstream source, you usually build from upstream tarball releases, rather than upstream git tags, you will sometimes find that the git tree doesn't contain everything that is in the tarball. π
additional build steps may be needed. for example, you may need your debian/rules to run autotools.
you can compare the upstream tarball release, and upstream git tag, within git, by importing the tarball into git as described in the next section, using a different value for 'upstream-tag', and then using git-diff(1) to compare the imported tarball to the release tag.
πΈ Using untagged upstream commits
sometimes upstream does not tag their releases, or you want to package an unreleased git snapshot. in such a case you can create your own upstream release tag, of the form upstream/ver, where ver is the upstream version you plan to put in debian/changelog. the upstream/ prefix ensures that your tag will not clash with any tags upstream later creates. so considerate β¨
for example, suppose the latest upstream release is 1.2.2 and you want to package git commit ab34c21 which was made on 2013-12-11. a common convention is to use the upstream version number 1.2.2+git20131211.ab34c21 and so you could use
% git tag -s upstream/1.2.2+git20131211.ab34c21 ab34c21
to obtain a release tag, and then proceed as above.
one can generate such a versioned tag using git show's --pretty option. e.g.:
% git tag -s upstream/$(git show --date=format:%Y%m%d --pretty=format:"1.2.2+git%cd.%h" --quiet upstream/main) upstream/main
π§ When upstream releases only tarballs
because we want to work in git, we need a virtual upstream branch with virtual release tags. gbp-import-orig(1) can manage this for us. to begin:
% mkdir foo
% cd foo
% git init
% git checkout -b upstream
% gbp import-orig \
--upstream-branch=upstream --debian-branch=master \
--upstream-tag='upstream/%(version)s' \
--sign-tags --no-pristine-tar \
../foo_1.2.2.orig.tar.xz
% git branch -f upstream
this should leave you on the master branch. next: our upstream branch cannot be pushed to dgit-repos, but since we will need it whenever we import a new upstream version, we must push it somewhere. the usual choice is salsa.debian.org:
% git remote add -f origin salsa.debian.org:debian/foo.git
% git push --follow-tags -u origin master upstream
you are now ready to proceed as above, making commits to the debian/ directory and to the upstream source. as above, for technical reasons, it is essential that your first commit introduces the debian/ directory containing at least one file, and does nothing else. in other words: make a commit introducing debian/ before patching the upstream source. (yes i'm repeating it. it matters. π
)
a convenient way to ensure this requirement is satisfied is to start by creating debian/gbp.conf:
[DEFAULT]
upstream-branch = upstream
debian-branch = master
upstream-tag = upstream/%(version)s
sign-tags = True
pristine-tar = False
pristine-tar-commit = False
[import-orig]
merge = False
and commit that:
% git add debian/gbp.conf && git commit -m "create gbp.conf"
note that we couldn't create debian/gbp.conf before now for the same technical reasons which require our first commit to introduce debian/ without patching the upstream source. that's why we had to pass a lot of options to our first call to gbp-import-orig(1). it's giving chicken-and-egg π£
π CONVERTING AN EXISTING PACKAGE π
this section explains how to convert an existing Debian package to this workflow. skip it when you're debianising a new package.
if you have an existing git history that you have pushed to an ordinary git server like salsa.debian.org, we start with that. if you don't already have it locally, you'll need to clone it, and obtain the corresponding orig.tar from the archive:
% git clone salsa.debian.org:debian/foo
% cd foo
% dgit setup-new-tree
% origtargz
if you don't have any existing git history, or you have history only on the special dgit-repos server, we start with dgit clone:
% dgit clone foo
% cd foo
then we make new upstream tags available:
% git remote add -f upstream https://some.upstream/foo.git
we now use a git debrebase convert-from-* command to convert your existing history to the git-debrebase(5) data model. which command you should use depends on some facts about your repository. let's vibe-check your repo π
- (A) There is no delta queue. if there do not exist any Debian patches, use
% git debrebase convert-from-gbp
- (B) There is a delta queue, and patches are unapplied. this is the standard
git-buildpackage(1)workflow: there are Debian patches, but the upstream source is committed to git without those patches applied. use
% git debrebase convert-from-gbp
if you were not previously using dgit to upload your package (i.e. you were not using the workflow described in dgit-maint-gbp(7)), and you happen to have run dgit fetch sid in this clone of the repository, you will need to pass --fdiverged to this command.
- (C) There is a delta queue, and patches are applied. use
% git debrebase convert-from-dgit-view
finally, you need to ensure that your git HEAD is dgit-compatible, i.e., it is exactly what you would get if you deleted .git, invoked dpkg-buildpackage -S, and then unpacked the resultant source package. π―
to achieve this, you might need to delete debian/source/local-options. one way to have dgit check your progress is to run dgit build-source.
π GIT CONFIGURATION π
git-debrebase(1) does not yet support using git merge to merge divergent branches of development (see "OTHER MERGES" in git-debrebase(5)). so you should configure git such that git pull does not try to merge:
% git config --local pull.rebase true
now when you pull work from other Debian contributors, git will rebase your work on top of theirs.
if you use this clone for upstream development in addition to Debian packaging work, you may not want to set this global setting. instead, see the branch.autoSetupRebase and branch.<name>.rebase settings in git-config(5).
(not done yet bestie β more parts incoming π)
π¦ IMPORTING NEW UPSTREAM RELEASES π¦
okay so this is a two-step sitch, bestie:
- grab the
gitrefs that match the new release - actually import that release using
git-debrebase(1)
π Obtaining the release
πΈ When upstream tags releases in git
% git fetch --tags upstream
If you wanna package an untagged upstream commit (because upstream literally refuses to tag, or because you wanna package a dev snapshot), go peek at "Using untagged upstream commits" up above. π
π When upstream releases only tarballs
You're gonna need the debian/gbp.conf from "When upstream releases only tarballs", above. You'll also need your upstream branch β remember, up there we pushed it to salsa.debian.org. So you'll have to clone or fetch from there, you can't just vibe off dgit clone/dgit fetch alone. π
Then, pick your fighter:
% gbp import-orig ../foo_1.2.3.orig.tar.xz
or, if you've got a working watch file:
% gbp import-orig --uscan
π Importing the release
% git debrebase new-upstream 1.2.3
heads up bestie, this git-debrebase(1) invocation runs a git rebase. So if your Debian delta queue doesn't apply cleanly on top of the new upstream source, you're resolving conflicts. no cap. π
If all went well, you can now review the merge of the new upstream release:
git diff debian/1.2.2-1..HEAD -- . ':!debian'
Also β diff with --name-status and --diff-filter=ADR to see just the list of added or removed files. That's lowkey so useful for figuring out whether there are any new or deleted files that need accounting for in your copyright file. β¨
If you got a tarball from upstream, you're ready to try a build. If you merged a git tag from upstream, you'll first need to generate a tarball:
% git deborig
βοΈ EDITING THE DEBIAN PACKAGING βοΈ
Genuinely simple: just make commits on master that change the contents of debian/. that's it. that's the section. π
π οΈ EDITING THE DELTA QUEUE π οΈ
β Adding new patches
Adding new patches is straightforward β just make commits touching only files outside of the debian/ directory. You can also use tools like git-revert(1), git-am(1) and git-cherry-pick(1). slay. π
π Editing patches: starting a debrebase
git-debrebase(1) is a wrapper around git-rebase(1) which lets us edit, re-order and delete patches. Run
% git debrebase -i
to start an interactive rebase. You can edit, re-order and delete commits just as you would during git rebase -i. iconic behaviour honestly. β¨
π«Ά Editing patches: finishing a debrebase
After completing the git rebase, your branch will not be a fast-forward of the git HEAD you had before the rebase. Which means... we cannot push the branch anywhere. π If you're ready to upload, dgit push-source (or dgit push-built) will take care of fixing this up for you. π
If you're not ready to upload yet, and you wanna push your branch to a git remote such as salsa.debian.org:
% git debrebase conclude
β οΈ Note that each time you conclude a debrebase you introduce a pseudomerge into your git history, which may make it harder to read. Try to do all of the editing of the delta queue that you think will be needed for this editing session in a single debrebase, so that there's a single debrebase stitch. π§΅
π BUILDING AND UPLOADING π
You can use dpkg-buildpackage(1) for test builds. When you're ready to build just prior to an upload, use dgit sbuild, dgit pbuilder or dgit cowbuilder. Routine source-only uploads can be made by just typing
% git debpush
The first time, pass --quilt=linear. This is especially important if you have converted the package from another workflow. See git-debpush(1). π₯
If you need to upload to NEW, you'll need to use dgit push-built. Remember to pass --new if the package is new in the target suite, and to git push to salsa.debian.org afterwards. π
In some cases where you used git debrebase convert-from-gbp since the last upload, and you're uploading with dgit, it is not possible for dgit to make your history fast-forwarding from the history on dgit-repos. In such cases you'll have to pass --trust-changelog to dgit. git-debrebase will normally tell you if this will be needed. (git-debpush handles this transparently.) πͺ
Right before uploading, if you didn't just already do so, you might wanna have git-debrebase(1) shuffle your branch such that the Debian delta queue appears right at the tip of the branch you'll push:
% git debrebase quick
% git debpush
Note that this will introduce a new pseudomerge. π
π« HANDLING DFSG-NON-FREE MATERIAL π«
π Illegal material
okay so here we explain how to handle material that is merely DFSG-non-free. Material which is legally dangerous (for example, files which are actually illegal) cannot be handled this way. periodt.
If you encounter possibly-legally-dangerous material in the upstream source code you should seek advice. It is often best not to make a fuss on a public mailing list (at least, not at first). Instead, email your archive administrators. For Debian that is
To: dgit-owner@debian.org, ftpmaster@ftp-master.debian.org
πΏ DFSG-non-free: When upstream tags releases in git
Our approach is to maintain a DFSG-clean upstream branch, and create tags on this branch for each release that we wanna import. We then import those tags per "Importing the release", above. In the case of a new package, we base our initial Debianisation on our first DFSG-clean tag. π
For the first upstream release that requires DFSG filtering:
% git checkout -b upstream-dfsg 1.2.3
% git rm evil.bin
% git commit -m "upstream version 1.2.3 DFSG-cleaned"
% git tag -s 1.2.3+dfsg
% git checkout master
Now either proceed with "Importing the release" on the 1.2.3+dfsg tag, or in the case of a new package:
% git branch --unset-upstream
% git reset --hard 1.2.3+dfsg
and proceed with "INITIAL DEBIANISATION". β¨
For subsequent releases (whether or not they require additional filtering):
% git checkout upstream-dfsg
% git merge 1.2.4
% git rm further-evil.bin # if needed
% git commit -m "upstream version 1.2.4 DFSG-cleaned" # if needed
% git tag -s 1.2.4+dfsg
% git checkout master
% # proceed with "Importing the release" on 1.2.4+dfsg tag
Our upstream-dfsg branch cannot be pushed to dgit-repos, but since we'll need it whenever we import a new upstream version, we must push it somewhere. Assuming that you have already set up an origin remote per the above:
% git push --follow-tags -u origin master upstream-dfsg
π° DFSG-non-free: When upstream releases only tarballs
The easiest way to handle this is to add a Files-Excluded field to debian/copyright, and a uversionmangle setting in debian/watch. See uscan(1). Alternatively, see the --filter option detailed in gbp-import-orig(1). π
π€ INCORPORATING NMUS π€
In the simplest case:
% dgit fetch
% git merge --ff-only dgit/dgit/sid
If that fails, because your branch and the NMUers' work represent divergent branches of development, you've got a bunch of options. Here we describe the two simplest. π
β οΈ Note that you should not try to resolve the divergent branches by editing files indebian/patches. Changes there would either cause trouble, or be overwritten bygit-debrebase(1). π
π Rebasing your work onto the NMU
% git rebase dgit/dgit/sid
If the NMUer added new commits modifying the upstream source, you'll probably wanna debrebase before your next upload to tidy those up. π§Ή
For example, the NMUer might have used git-revert(1) to unapply one of your patches. A debrebase can be used to strip both the patch and the reversion from the delta queue. slay. π
π Manually applying the debdiff
If you cannot rebase because you have already pushed to salsa.debian.org, say, you can manually apply the NMU debdiff, commit and debrebase. The next dgit push will require --trust-changelog. π
π HINTS AND TIPS π
Okay bestie, here's the stuff that makes the whole workflow click. Little things, big glow-up energy. β¨
π Minimising pseudomerges
So remember how we said earlier that every single time you conclude a debrebase, you lowkey drop a pseudomerge into your git history? And that it can make stuff harder to read? Yeah. That.
A simple convention you can use to keep the number of pseudomerges down: only run git debrebase conclude right before you upload or push to salsa.debian.org. That's it. That's the whole trick. π«Ά
And it is possible, though much less convenient, to reduce the pseudomerge count even further. Here's how: we debrebase only (i) when importing a new release, and (ii) right before uploading. Instead of editing the existing delta queue, you append fixup commits (and reversions of commits) that alter the upstream source to the required state. You can push and pull to and from salsa.debian.org while you're doing this. Then just before uploading, you debrebase β once β to tidy everything up. Iconic, honestly.
π The debian/patches directory
In this workflow, debian/patches is purely an output of git-debrebase(1). Do not make changes in there. They will either cause trouble, or be ignored and overwritten by git-debrebase(1). Pick your poison, but like, don't. π
Also: debian/patches will often be out-of-date, because git-debrebase(1) only regenerates it when it needs to. So don't rely on the information in that directory, fr fr. When you're preparing patches to forward upstream, use git-format-patch(1) on git commits β not files you grabbed out of debian/patches. K thx.
πΏ Upstream branches
In this workflow, we specify upstream tags, not any branches. Tags are the moment. π
Exception time β the only cases where we don't do the tag thing: (i) upstream releases only tarballs, (ii) we require DFSG filtering, or (iii) you also happen to be involved in upstream development. Outside of those, we do not maintain any local branch corresponding to upstream, except temporary branches used to prepare patches for forwarding, and the like.
The idea here? From Debian's point of view, upstream releases are immutable points in history. We want to make sure we're basing our Debian package on a properly identified upstream version, rather than some arbitrary commit on some branch. Tags are simply more useful for this. Periodt.
Upstream's branches do remain available as the git remote tracking branches for your upstream remote, e.g. remotes/upstream/master. So they're not gone, they're just not the main character. π¦
π The first ever dgit push
If this is the first ever dgit push of the package to this suite, consider passing --deliberately-not-fast-forward instead of --trust-changelog. This avoids introducing a new origin commit into your git history. (That origin commit would represent the most recent non-dgit upload of the package β but this should already be represented in your git history.) No cap. π
π Inspecting the history
The git history made by git-debrebase can seem complicated. It's giving labyrinth. But here are some suggestions for helpful invocations of gitk and git. They can be adapted for other tools like tig(1), git-log(1), magit, etc. β¨
History of package in Debian, disregarding history from upstream:
% gitk --first-parent
In a laundered branch, the delta queue is at the top.
History of the packaging, excluding the delta queue:
% gitk :/debian :!/debian/patches
Just the delta queue (i.e. Debian's changes to upstream):
% gitk --first-parent -- :/ :!/debian
Full history including old versions of the delta queue:
% gitk --date-order
The "Declare fast forward" commits you see have an older history (usually, an older delta queue) as one parent, and a newer history as the other. --date-order makes gitk show the delta queues in the right order.
Complete diff since the last upload:
% git diff dgit/dgit/sid..HEAD -- :/ :!/debian/patches
This includes changes to upstream files.
Interdiff of delta queue since last upload, if you really want it:
% git debrebase make-patches
% git diff dgit/dgit/sid..HEAD -- debian/patches
And of course there is:
% git debrebase status
π§ Alternative ways to start a debrebase
Earlier we started an interactive debrebase by invoking git-debrebase(1) like this:
% git debrebase -i
It is also possible to perform a non-interactive rebase, like this:
% git debrebase -- [git-rebase options...]
A third alternative is to have git-debrebase(1) shuffle all the Debian changes to the end of your branch, and then manipulate them yourself using git-rebase(1) directly. For example:
% git debrebase
% git rebase -i HEAD~5 # there are 4 Debian patches
Careful, bestie. π¨ If you take this approach, you should be very careful not to start the rebase too early, including before the most recent pseudomerge.git-rebasewithout a base argument will often start the rebase too early, and should be avoided. Rungit-debrebaseinstead. See also "ILLEGAL OPERATIONS" ingit-debrebase(5).
π SEE ALSO π
dgit(1), dgit(7), git-debrebase(1), git-debrebase(5), gitrevisions(7)
π AUTHOR π
The original developer and author of this manpage is Sean Whitton <spwhitton@spwhitton.name>. It contains contributions from other dgit contributors too β see the dgit copyright file.
That's the whole page, bestie. You absolutely ate this. π β¨
This one came from the Debian Project / the dgit+tag2upload team, and it's dgit-maint-debrebase(7) β go forth and debrebase responsibly, ily π«ΆπΈ
π¦ where this page comes from
- ubuntu stonking: dgit 17.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms