created on | October 25, 2023 |
There are three ways for creating an archive from a git repo: , , and plain tarballs. Spoiler: as long as you want to archive the local repo in its current state –that is with uncommitted changes– making a tarball from a git repo is not only the most simple way to create an archive from a git repo, but also the best one.
This is great if you just want to keep the source code of a certain branch without any version control information.
creates a tarball (or zip file) without the directory. Thus, the archive will not contain any version control information like the repo’s history. The archive can include only one branch of the repo.
Archive the contents of a certain revision in the currently checked out branch:
Archive the contents of the latest commit of the currently checked out branch.
Archive the contents of a specific branch (the branch can differ from the currently checked out branch)
This is good for making a backup of a repo including all version control information. But it has some drawbacks compared to a plain tarball of an archive.
You can back up a single branch or a whole repo.
To restore a repo from a git bundle, you don’t extract it. You a do a from the bundle.
There are some notable things about git bundles:
That said, a bundle has some disadvantages compared to a backup that’s simply a tarball of the repo:
To create a bundle that includes all branches, from the root of the git repo run:
To create a bundle from a single branch, i.e. branch main, run:
Create a bundle that contains all revisions up to (and including) a specific revision:
Restoring a repo from a git bundle is done with :
, i.e.
This is my favourite way of backing up a git repo.
Archiving a repo by creating a tarball (or zip file) including the directory will create a ‘snapshot’ of the repo that will include:
The remote origin remains intact. No git foo is necessary to get started, just unpack the tarball. You might have to remove IDE-specific files and directories like the dir. After that, you are ready to go.