# Packaging Workflow with Git

## Table of Contents

1. Definitions
2. Preparations
3. Handling new packages
4. Handling existing package

## 1. Definitions

- changeslist: name of the commit mailinglist
- package: name of the source package of your program
- project: name of the alioth project
- revision: debian version string
- username: name of the alioth account
- version: upstream version string

^

## 2. Preparations

- Install git

      # apt-get install git

- Install pristine-tar

      # apt-get install pristine-tar

- Install git-buildpackage

      # apt-get install git-buildpackage

^

## 3. Handling new packages

### 3.1 Preparing upstream tarball

- Download upstream source tarball
- Rename it to `package_version.orig.tar.gz`

### 3.2 Preparing git repository

- Create an empty git repository

      $ mkdir program
      $ cd program
      $ git init --shared

- Unpack upstream sources into the git repository
- Import upstream into git

      $ git add .
      $ git commit -a -m "Adding upstream version version."
      $ git tag -a -m "Tagging upstream version version." upstream/version

- Create upstream branch (by renaming master)

      $ git branch -m master upstream

- Import pristine-tar delta

      $ pristine-tar commit -m "Adding pristine-tar version version." ../program_version.orig.tar.gz

- Create and switch to debian branch

      $ git checkout -b debian

- Prepare bare git repository

      $ cd ..
      $ git clone --bare program program.git
      $ cd program.git

- Add gitweb description

      $ echo "project/program" > description

- Upload git repository to alioth

      $ scp -r program.git username@alioth.debian.org:/git/project

- Remember to make sure that the files on alioth do have read-write permissions for your alioth group.

^

## 4. Handling existing package

### 4.1 Checking out

- Checkout repository

      $ git clone ssh://username@git.debian.org/git/project/package.git

- Checkout branches

      $ cd package

      $ git checkout -b upstream origin/upstream
      $ git checkout -b pristine-tar origin/pristine-tar

- Switch to debian branch

      $ git checkout debian

### 4.2 Checking in

- Make sure that you are on the debian branch

      $ cd package

      $ git checkout debian

- Do your modifications on the package here. Remember to not touch debian/changelog at all, it will be later automatically generated from the git log.
- Commit changes

      $ git commit -a -m "My commit message."

- After a bunch of commits, you push changes

      $ git push

### 4.3 Adding new Upstream version

- Make sure that you are on the upstream branch

      $ cd package

      $ git checkout upstream

- Removing current files

      $ rm -rf *

- Unpacking new upstream sources into the git repository.
- Adding files

      $ git add .
      $ git commit -a -m "Adding upstream version version."

- Tagging

      $ git tag -a -m "Tagging upstream version version." upstream/version

- Upstream tarball

      $ pristine-tar commit -m "Adding pristine-tar version version." ../package_version.orig.tar.gz

- Make sure that you are on the debian branch

      $ git checkout debian

- Merging

      $ git cherry-pick -n upstream
      $ git commit -a -m "Merging upstream version version."

- Pushing

      $ git push

      $ git push --tags

### 4.4 Releasing new Debian version

- Creating changelog

      $ git-dch --debian-branch debian --release --since HASH

- Releasing

      $ git commit -a -m "Releasing debian version version-revision."

- Tagging

      $ git tag -a -m "Tagging debian version version-revision." debian/version-revision

- Pushing

      $ git push
      $ git push --tags

- Upstream tarball

      $ pristine-tar checkout package_version.orig.tar.gz

- Build in chroot and upload to ftp-master as usual.

^