git archive provides an easy way of producing a tarball directly from a project's git branch.

For example, this is what we use to build the Mahara tarballs:

git archive --format=tar --prefix=mahara-${VERSION}/ ${RELEASETAG} | bzip2 -9 > ${CURRENTDIR}/mahara-${RELEASE}.tar.bz2

If you do this however, you end up with the entire contents of the git branch, including potentially undesirable files like .gitignore.

There is an easy, though not very well-documented, way of specifying files to exclude from such exports: gitattributes.

This is what the Mahara .gitattributes file looks like:

/test export-ignore  
.gitattributes export-ignore  
.gitignore export-ignore

With this file in the root directory of our repository, tarballs we generate using git archive no longer contain the selenium tests or the git config files.

If you start playing with this feature however, make sure you commit the .gitattributes file to your repository before running git archive. Otherwise the settings will not be picked up by git archive.

I understand why you'd exclude the .git* files, but why exclude the test suite?
Comment by Anonymous

Currently the Mahara test directory includes a bunch of stuff which drives our Hudson-based continuous integration server and would take the tarball from about 4 megs to 10 megs.

Once we separate these things out, we can start shipping the tests with the source code.

Comment by Fran├žois