Exporting a Git repo as an archive

Featured image for sharing metadata for article

I almost always work on projects with a Git repo backing it, even if it's not pushed anywhere and is more for a safer undo/redo functionality.

I've recently been doing some work that's required sending a ZIP of my work, rather than sharing a Git repo.

Although I would usually turn to the GitLab/GitHub UI to export to an archive for me, I remember reading that git-archive command exists, and is in fact used under the hood.

In your Git repo, we can run git archive to do this for us:

$ git archive origin/main -o archive.zip
# or we can be explicit about the file format
$ git archive origin/main --format=tgz -o archive.tar.gz
# defaults to stdout, beware!
$ git archive origin/main > archive.tar

Written by Jamie Tanna's profile image Jamie Tanna on , and last updated on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

#blogumentation #git.

Also on:

This post was filed under articles.

Interactions with this post

Interactions with this post

Below you can find the interactions that this page has had using WebMention.

Have you written a response to this post? Let me know the URL:

Do you not have a website set up with WebMention capabilities? You can use Comment Parade.