brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: git archive makes a clean tarball of your project without the .git folder

Git
~/tips/tip-git-archive-release-tarball

git archive --format=tar.gz --prefix=project/ -o project.tar.gz HEAD

Packs one commit or tag of a repository into a tar.gz or zip file, without history.

Zipping a project folder by hand drags along .git, build output and whatever else is lying around. git archive packs exactly what is committed, at the version you pick.

git archive --format=tar.gz --prefix=project/ -o project.tar.gz HEAD

--prefix=project/ puts everything inside a project/ folder in the archive, so unpacking it does not spill files into the current directory. Swap HEAD for a tag such as v1.4.0 to package that release.

You can leave out --format: the docs say the format is taken from the file name when you use -o, so git archive -o latest.zip HEAD gives you a zip. The built-in formats are tar, zip, tar.gz and tgz.

Want to keep some files out of the archive, like test fixtures or CI config? Mark them in .gitattributes:

.github/ export-ignore
tests/ export-ignore

Caveat: those attributes are read from the commit you archive, not from your working tree. Add the export-ignore lines, commit them, and only then archive. The docs mention --worktree-attributes if you want the working-tree version instead. And untracked files are never included, which is usually exactly what I want.

Further reading: git-archive documentation

Going deeper: Moving on from hdtv: how to export your TV show list to Trakt.tv

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link