debian git packaging with git upstream

Update

There is an easier method to do all this using gbp-clone as described here. Ah !

Then to build the package, you just need to suggest git-buildpackage where to find the pristin-tar :

git-buildpackage --git-upstream-branch=upstream/master

or you could simply describe (as suggested) the layout in debian/gbp.conf.

Easy !!!


I've found a lot of different recipes and howtos about git debian packaging, but I failed to find one simple recipe to create a debian package from scratch when upstream is using git. Of course the following is a big patchwork from many different sources.

First we need to do a bit of administrative work to setup the repository :

mkdir yourpackage
cd yourpackage
git init --shared

Then, since I'm interested in tracking upstream development branch I'm going to add a remote branch to my repo:

git remote add upstream git://the.url/here.git

at this point I need to fetch upstream and create a branch for it.

git fetch upstream
git checkout -b upstream upstream/master

Now in my repo I have a master branch and an upstream branch. So far, so good. Let's add the debian branch based on master:

git checkout master
git checkout -b debian master

It's in the debian branch where I'm going to keep the debian related files. I'm finally read for hacking git add / git commit / git remove ...

When I'm done, I can switch to master, merge the debian branch into it and use git-buildpackage to build the package.

git checkout master
git branch
  debian
* master
  upstream

git merge debian
git-buildpackage

Suppose I want to put everything on gitourious for example. I'll create an acocunt, set up my ssh pub key and then I've to add an origin ref in my .git/config . Something like :

[remote "origin"]
       url = git@gitorious.org:debian-stuff/yourpackage.git
       fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
       remote = origin
       merge = refs/heads/master

The only thing left to do is to push everything on gitourious. the --all is important.

git push --all

People willing to pull your work from girourious have to follow the following script :

$git clone git@gitorious.org:debian-stuff/yourpackage.git
$cd yourpackage
$git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/debian
  remotes/origin/master
  remotes/origin/upstream
$git checkout -t origin/debian
$git checkout -t origin/upstream
$git branch -a
  debian
  master
* upstream
  remotes/origin/HEAD -> origin/master
  remotes/origin/debian
  remotes/origin/master
  remotes/origin/upstream
$git checkout master
$git-buildpackage

Maybe there is an easier way to pull all remote branches at once, but I'm not aware of it. Any better way ?

Average: 1.1 (55 votes)

Comments

Actually, at the time you

Actually, at the time you first ran "git checkout master", you didn't have a branch head called "master" yet. Recent git versions (>= 1.7.0 IIRC) create the branch head on the fly when you do the checkout, because there's only one remote-tracking branch whose name ends in "master" and that is upstream/master. So git ran "git branch master upstream/master" for you when you did the checkout.

Also, is there any special reason why you add the "origin" remote by editing your config instead of using "git remote add" like you did for the "upstream" remote?

Recent git versions can also create the "branch" section to setup the upstream even if the branch head already exists:

  git branch --set-upstream master origin/master
And finally, the clone command already fetched all remote branches and created remote-tracking branches for you (the origin/* ones). Those are your local mirrors of the remote branches. There's no need to create local branch heads from them, unless you actually want to work on these branches.

Reg your first point about

Reg your first point about "git checkout master" I didn't even noticed because git did it form me, but thanks for pointing out.

The second point is just because I did a cut and past from another .git/config , but yes, no special reason...

About the last point, I've noticed that if I don't create a local branch, git-buildpackage will refuse to run ... but maybe I've missed something ...

thanks for your comments !

Two

Two remarks:

  1. git-buildpackage is no use here. debuild (or dpkg-buildpackage) would do exactly the same job, ignoring the Git-related files.
  2. I do not see the point of having two debian and master branches: it looks like they are the same in your example. I personally use my master branch for the Debian package development, as this is what I do, in fact.

To avoid confusion I usually

To avoid confusion I usually name the remote "upstream-repo" to avoid it having the same name as the "upstream" branch. I understand git is a very low level tool and that there's no technical reason why remotes, tags, branches can't have the same name but from an end user perspective I think it's good if everything has unique names.