DEV Community

Rouan Wilsenach
Rouan Wilsenach

Posted on • Edited on • Originally published at rouanw.com

2

TIL: Add your git repo to a tarball

Today I learned that you can neatly pack all of the files in your git repository into a tarball:

git archive --format=tar -o my_repo.tar -v HEAD
Enter fullscreen mode Exit fullscreen mode

The best thing about this is it will automatically honour your .gitignore file, so won't include any files you don't care about.

Other formats

It also works with zip files:

git archive --format=zip -o my_repo.zip -v HEAD
Enter fullscreen mode Exit fullscreen mode

Excluding files

In order to exclude files from the archive, you can specify them in a .gitattributes file. Here's an example that excludes the README.md file from the export:

README.md export-ignore
Enter fullscreen mode Exit fullscreen mode

Including the git repo itself

It doesn't include the git repository itself (the .git directory). If you'd like to include it, you can run:

git archive --format=tar -o my_repo.tar -v HEAD
tar -rf my_repo.tar .git
Enter fullscreen mode Exit fullscreen mode

Sources

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay