New repo for new package

Init git repository on alioth:

/git/pkg-horde$ mkdir DEBPKGNAME.git
/git/pkg-horde$ cd DEBPKGNAME.git
/git/pkg-horde/DEBPKGNAME.git$ git --bare init

Note: please use a bare repository. We will have a clean Gitweb URL like http://git.debian.org/?p=pkg-horde/DEBPKGNAME.git and not http://git.debian.org/?p=pkg-horde/DEBPKGNAME.git/.git with a non-bare repository

Configure the repository:

/git/pkg-horde/DEBPKGNAME.git$ echo "Debian Horde Packages repository: DEBPKGNAME package" > description
/git/pkg-horde/DEBPKGNAME.git$ git config --add hooks.mailinglist "pkg-horde-hackers@lists.alioth.debian.org"
/git/pkg-horde/DEBPKGNAME.git$ echo "exec /usr/local/bin/git-commit-notice" >> hooks/post-receive
/git/pkg-horde/DEBPKGNAME.git$ chmod +x hooks/post-receive

Init your own repository:

# fetch upstream sources
/path$ wget upstream.tar.gz 
/path$ tar -xvf upstream.tar.gz
/path$ mv upstream DEBPKGNAME.git
/path$ cd DEBPKGNAME.git
# init Git repository
/path/DEBPKGNAME.git$ git init
/path/DEBPKGNAME.git$ git add .
/path/DEBPKGNAME.git$ git commit -m "Import PKGNAME VERSION" 
# create branches
/path/DEBPKGNAME.git$ git branch -m master upstream
/path/DEBPKGNAME.git$ git branch upstream+patches upstream
/path/DEBPKGNAME.git$ git branch upstream+repack upstream (if needed!)
# pristine-tar upstream sources
/path/DEBPKGNAME.git$ pristine-tar commit ../upstream.tar.gz

Push all to alioth repository:

/path/DEBPKGNAME.git$ git remote add origin ssh://LOGIN@git.debian.org/git/pkg-horde/DEBPKGNAME.git
# commands to track all branches
/path/DEBPKGNAME.git$ git config branch.upstream.remote origin
/path/DEBPKGNAME.git$ git config branch.upstream.merge refs/heads/upstream
/path/DEBPKGNAME.git$ git config branch.upstream+repack.remote origin
/path/DEBPKGNAME.git$ git config branch.upstream+repack.merge refs/heads/upstream+repack
/path/DEBPKGNAME.git$ git config branch.upstream+patches.remote origin
/path/DEBPKGNAME.git$ git config branch.upstream+patches.merge refs/heads/upstream+patches
/path/DEBPKGNAME.git$ git config branch.pristine-tar.remote origin
/path/DEBPKGNAME.git$ git config branch.pristine-tar.merge refs/heads/pristine-tar
# push all
/path/DEBPKGNAME.git$ git push --all 

Repack upstream (if needed!)

/path/DEBPKGNAME.git$ git checkout upstream+repack
# Create a shell script, and commit it in debian/
/path/DEBPKGNAME.git$ sh /tmp/cleanup-upstream.sh
/path/DEBPKGNAME.git$ git commit -a -m repack
/path/DEBPKGNAME.git$ tar --exclude .git -czf ../upstream+debian0.orig.tar.gz .
/path/DEBPKGNAME.git$ pristine-tar commit ../upstream+debian0.orig.tar.gz upstream+repack

If you don't need repack, don't forget to commit .orig.tar.gz:

/path/DEBPKGNAME.git$ mv ../upstream.tar.gz ../DEBPKGNAME_VERSION.orig.tar.gz
/path/DEBPKGNAME.git$ pristine-tar commit ../DEBPKGNAME_VERSION.orig.tar.gz

First Debianization

# create branch
/path/DEBPKGNAME.git$ git checkout -b debian-sid upstream+repack
# track branch
/path/DEBPKGNAME.git$ git config branch.debian-sid.remote origin
/path/DEBPKGNAME.git$ git config branch.debian-sid.merge refs/heads/debian-sid
# Hack and commit
/path/DEBPKGNAME.git$ mkdir debian && hack hack....
/path/DEBPKGNAME.git$ git add debian && git commit -m "First Debian packaging"

New upstream release

# Fetch new source
/path$ wget newupstream.tar.gz
/path$ tar -xvf newupstream.tar.gz
/path$ cd DEBPKGNAME.git
/path/DEBPKGNAME.git$ git checkout upstream
/path/DEBPKGNAME.git$ git_load_dirs -s 'Import new upstream sources' ../newupstream/
/path/DEBPKGNAME.git$ pristine-tar commit ../newupstream.tar.gz
# Merge new sources to upstream+patches branch
/path/DEBPKGNAME.git$ git checkout upstream+patches
/path/DEBPKGNAME.git$ git merge upstream
# Merge new sources to upstream+repack branch (if needed!)
/path/DEBPKGNAME.git$ git checkout upstream+repack
/path/DEBPKGNAME.git$ git merge upstream
hack... hack... if need of new repack
# Store .orig.tar.gz tarball
/path/DEBPKGNAME.git$ tar --exclude .git -czf ../newupstream+debian0.orig.tar.gz .
/path/DEBPKGNAME.git$ pristine-tar commit ../upstream+debian0.orig.tar.gz upstream+repack

New Debian package with new upstream

/path/DEBPKGNAME.git$ git checkout debian-sid
/path/DEBPKGNAME.git$ git merge upstream+repack
hack hack...
/path/DEBPKGNAME.git$ git commit -a -m "New changelog"
hack hack...

New Debian package

/path/rep$ git checkout debian-sid
/path/rep$ dch -v NEWVERSION
hack hack...
/path/rep$ git commit -a -m "New changelog"
hack hack...

Build Debian package

/path/rep$ git checkout debian-sid
/path/rep$ git-buildpackage -us -uc --git-pristine-tar --git-upstream-branch=upstream+repack --git-debian-branch=debian-sid

Notes about migration from GNU Arch to Git

Migration is done with git-archimport.

# Migration of all GNU Arch repo 
git-archimport -v pkg-horde-hackers@lists.alioth.debian.org--2006

It's done in /git/pkg-horde/archimport.git on alioth.

Steps are :

1. Create a new repository (bare repo on alioth with upstream branches)

2. Push GNU Arch branch to your new repository

~$ cd /git/pkg-horde/archimport.git
/git/pkg-horde/archimport.git$ git remote add DEBPKGNAME /git/pkg-horde/DEBPKGNAME.git/
/git/pkg-horde/archimport.git$ git push DEBPKGNAME pkg-horde-hackers@lists.alioth.debian.org--2006,PKGNAME--sid--VERSION:refs/heads/debian-sid

3. Merge upstream (or upstream-repack) to debian-sid branch

/path/DEBPKGNAME.git$ git pull
/path/DEBPKGNAME.git$ git branch --track debian-sid origin/debian-sid
/path/DEBPKGNAME.git$ git checkout debian-sid
/path/DEBPKGNAME.git$ cp -pr debian/ /tmp/
/path/DEBPKGNAME.git$ /usr/lib/git-core/git-merge-resolve upstream+repack (or git-merge-stupid!)
/path/DEBPKGNAME.git$ cp -pr /tmp/debian/ .
/path/DEBPKGNAME.git$ git reset HEAD debian
/path/DEBPKGNAME.git$ git commit -m "merge from upstream"

Note: I'm aware it's a dirty way. Comments welcome!

4. Check Debian changes in upstream source and put them in upstream+patches branch (if needed)

Check changes in diff.gz file (for example, zgrep +++ *diff.gz). If there are, add git patch stuff in debian/rules.

See http://git.debian.org/?p=pkg-horde/horde3.git;a=commitdiff;h=bb953be969e2944f8aa91c825a35b3ffe6a82e71;hp=d41f4d934c07c7226de1ed5d7dab5fe851f2c3cd#patch2

5. VERY VERY IMPORTANT: give ancestor to debian-sid branch for future merges

Download git-merge-unrelated-branch script from http://wingolog.org/archives/2008/10/14/merging-in-unrelated-git-branches (replace "git-update-ref" to "git update-ref" on line 24).

/path/DEBPKGNAME.git$ git checkout debian-sid
/path/DEBPKGNAME.git$ sh /tmp/git-merge-unrelated-branch . upstream+repack