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: tar --exclude-vcs leaves .git folders out of an archive

Archive
~/tips/tip-tar-exclude-vcs

tar --exclude-vcs -czf project.tar.gz project/

Leaves .git and other version control folders out of a tar archive.

Zipping up a project folder to send to someone usually drags the whole .git directory along. I’d rather not hand that over by accident.

GNU tar has an option for it:

tar --exclude-vcs -czf project.tar.gz project/

--exclude-vcs skips the metadata of common version control systems: .git, .svn, .hg, .bzr and a few older ones, plus files like .gitignore. You don’t have to remember a list of --exclude patterns for each of them.

Check the result before you send it:

tar -tzf project.tar.gz | head

The archive gets smaller as well, sometimes by a lot, since a long history can be bigger than the code itself.

A caveat: the option is a GNU tar feature. The tar that ships with macOS is a different implementation with its own options, so check man tar there before you rely on it. And it removes .gitignore too, so the receiver loses that file. If you want only the files git tracks, git archive is the better tool.

Further reading: GNU tar manual: Excluding some files

More Archive tips tar -tf backup.tar.gz | head All Archive tips (2) All topics

Link