DEV Community

Cover image for Archive Your Git Repo
Michael D. Callaghan
Michael D. Callaghan

Posted on • Originally published at walkingriver.com

3

Archive Your Git Repo

Cross-posted from https://walkingriver.com/archive-your-git-repo/

Did you know there is a very simple and straightforward command to archive a complete Git repository, while including no historical information? In this brief article I explain both how and why I do it.

Why Archive Your Git Repo?

Every few weeks or so, I find myself needing to archive my Git repo. Often I do this to send code to someone who has no reason to access the repo directly. They just need a snapshot of the code, with no history information, because they won't be contributing to it.

I also provide a snapshot of my code for every module in my Pluralsight courses. Being able to archive my Git repo into a zip file is very handy.

For some reason, I can never remember how to do this, and find myself looking it up repeatedly. I decided to write about it here so that I could always find it when I need it. And just maybe it will help someone other than just me.

How to Do It

If you want to backup a Git repo, completely detaching it from Git, use one of the following variations of the git archive command:

Zip File

git archive --format zip --output /full/path/to/zipfile.zip master
Enter fullscreen mode Exit fullscreen mode

Tar File:

git archive master > /some/other/path/my-repo.tar
Enter fullscreen mode Exit fullscreen mode

Tar / Bzip:

git archive master | bzip2 > my-repo.tar.bz2
Enter fullscreen mode Exit fullscreen mode

In each of these cases, the word master is the branch I am archiving. You can archive any branch you want, simply by replacing master with the name of your desired branch.

Though not strictly necessary, I like to create my archive from the root of my repo, and have my archive created outside of it.

Note: The archive will not contain the .git directory, but will contain other hidden git-specific files like .gitignore, .gitattributes, etc.

Reference

https://stackoverflow.com/questions/160608/do-a-git-export-like-svn-export


Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (1)

Collapse
 
stephencweiss profile image
Stephen Charles Weiss

For some reason, I can never remember how to do this, and find myself looking it up repeatedly. I decided to write about it here so that I could always find it when I need it. And just maybe it will help someone other than just me.

Inspiration for 90% of what I write.

Thanks for sharing!

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more