How to archive a Git branch

Kenny DuMez
Kenny DuMez
Graphite software engineer

Creating an archive of a Git branch can be very useful, especially when you need to preserve the state of a branch at a specific point in time for compliance, backup, or historical reference. This guide will provide a detailed explanation of how to archive a Git branch, using commands and examples that you can follow directly from your terminal.

The git archive command is used to create an archive (like a .zip or .tar file) from a tree or a set of files in a Git repository.

Before archiving, you might want to ensure that your local branch is up-to-date with its remote counterpart. Here's how you can update your local branch:

Terminal
git checkout your-branch-name
git pull origin your-branch-name

Replace your-branch-name with the name of the branch you wish to archive.

To create an archive of your branch, use the following command:

Terminal
git archive --format=zip --output=/path/to/your-archive.zip your-branch-name
  • --format=zip: specifies the format of the archive. Other formats you can use include tar or tar.gz.
  • --output=/path/to/your-archive.zip: specifies the path and filename of the output archive.
  • your-branch-name: is the name of the branch you are archiving.

This command will create a .zip file containing the current snapshot of the branch.

If you want to archive branches that are no longer actively used but you want to keep a historical record of, you can use the same command. First, ensure you have a list of all branches, including those not checked out locally:

Terminal
git fetch --all
git branch -a

Then, you can archive each branch using the same git archive command:

Terminal
git archive --format=zip --output=/path/to/old-branch-archive.zip old-branch-name

Replace old-branch-name with the name of the branch you want to archive.

For further reading on the Git archive command, see the official Git documentation.

Stay unblocked. Ship faster.
Experience the new developer workflow - create, review, and merge code continuously. Get started with one command.
Get started

Give your PR workflow
an upgrade today

Stack easier | Ship smaller | Review quicker

Or install our CLI.
Product Screenshot 1
Product Screenshot 2