
If the Git server disappeared, could you recover the last approved commit of main using only the files in your backup bucket? A full Git bundle can seed a new clone. An incremental bundle can bring it up to date, provided the clone already has the commit where that increment begins.
We tested that dependency with a two-commit repository. We uploaded a base bundle and an update to an S3-compatible bucket, removed the source repository, and restored the branch from the downloaded copies. Git named the missing commit when we tried the update on its own. With the base in place, the restore recovered the exact branch tip and the approved file contents.
Start inside the source repository, with at least one commit on main and an unused sibling directory named backup. These commands use Bash and sha256sum. We ran them with Git Bash and Git 2.51.0 on Windows. The bundle carries the history reachable from refs/heads/main.
set -eu
mkdir -p ../backup
git bundle create ../backup/base.bundle refs/heads/main
git bundle list-heads ../backup/base.bundle refs/heads/main > ../backup/base.ref
Keep base.ref. It records the commit ID and ref name that the finished bundle advertises. If someone pushes another commit while you prepare the backup, the saved ID still describes the artifact you have. Git’s bundle reference explains how the refs you select determine the contents.
After at least one new commit lands on main, run the following from the same source repository. The ancestry check stops the script if the branch has been rewritten past the saved base. In that case, take a new standalone base in a fresh directory. If the branch has not advanced, there is no increment to create.
set -eu
read -r base branch < ../backup/base.ref
test "$branch" = refs/heads/main
git merge-base --is-ancestor "$base" refs/heads/main
git bundle create ../backup/update.bundle "$base..refs/heads/main"
git bundle list-heads ../backup/update.bundle refs/heads/main > ../backup/update.ref
(cd ../backup && sha256sum base.bundle base.ref update.bundle update.ref > SHA256SUMS)
The range excludes the history already reachable from the saved base and advertises the newer main tip. Keep both bundle files for this recovery point. The two .ref files identify the commits to expect, and SHA256SUMS lets the receiver check the four downloaded files before asking Git to open them. Keep a trusted copy of the manifest or its digest if you also need to detect replacement of the entire set.
Save the helper below as copy_set.py and install Boto3 in your Python environment. Set S3_ENDPOINT to the endpoint URL, BUCKET to a test bucket you control, and PREFIX to a new name for this recovery point. Configure Boto3 credentials and the region for that endpoint. A unique prefix keeps a later update from being mixed with an earlier base.
import argparse
from pathlib import Path
import boto3
FILES = ("base.bundle", "base.ref", "update.bundle", "update.ref", "SHA256SUMS")
def copy_set(direction, endpoint, bucket, prefix, folder):
client = boto3.client("s3", endpoint_url=endpoint)
try:
for name in FILES:
path = str(folder / name)
key = f"{prefix.strip('/')}/{name}"
if direction == "upload":
client.upload_file(path, bucket, key)
else:
client.download_file(bucket, key, path)
finally:
client.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("direction", choices=["upload", "download"])
parser.add_argument("endpoint")
parser.add_argument("bucket")
parser.add_argument("prefix")
parser.add_argument("folder", type=Path)
args = parser.parse_args()
if args.direction == "download":
args.folder.mkdir(parents=True, exist_ok=True)
copy_set(args.direction, args.endpoint, args.bucket, args.prefix, args.folder)
Run the upload from the directory containing backup. On the recovery machine, run the download with the same endpoint, bucket and prefix from a clean directory. It creates a folder named received. The uploader sends the manifest last. Wait for a successful upload before treating the set as ready.
python copy_set.py upload "$S3_ENDPOINT" "$BUCKET" "$PREFIX" backup
python copy_set.py download "$S3_ENDPOINT" "$BUCKET" "$PREFIX" received
Our test used Boto3 1.43.117 and a local Moto S3 emulator. Five objects made the round trip. SHA-256 digests calculated independently before upload and after download matched for all five. If your team transfers objects from the command line, the guide to copying files with the AWS CLI covers that workflow.
Run this block inside received, with the sibling name recovered available for a new clone. Checking the base commit before the fetch catches a mismatched recovery set. A fast-forward merge moves the branch to the saved tip without creating a new merge commit.
set -eu
sha256sum -c SHA256SUMS
git clone --branch main --single-branch ./base.bundle ../recovered
read -r base branch < base.ref
test "$(git -C ../recovered rev-parse HEAD)" = "$base"
git -C ../recovered bundle verify ../received/update.bundle
git -C ../recovered fetch ../received/update.bundle refs/heads/main
git -C ../recovered merge --ff-only FETCH_HEAD
read -r target branch < update.ref
test "$(git -C ../recovered rev-parse HEAD)" = "$target"
git -C ../recovered fsck --full
In our empty-repository check, git bundle verify rejected update.bundle and identified 37dbb02 as a missing prerequisite. Cloning the base supplied that commit. The same downloaded update then verified, and the recovered branch ended at 8928251, exactly matching the full ID in update.ref. Both commits were present, git fsck --full passed, and the restored report.txt matched its committed bytes. The clone’s origin points to the local base bundle. Set the remote URL to your intended Git host before resuming normal pushes.
We deliberately left a working-tree edit, an untracked file and a second branch name in the source repository. All three were absent from the recovery. If you need more branches or tags, include their refs and check that each expected ref survives a clean restore. With Git LFS, a commit can contain a pointer to a file stored elsewhere. Include those external files in your recovery plan. Issues, CI settings and other hosting-service data require separate exports. For files outside Git, see the restic backup guide.
To evaluate Object Storage with Hivenet for repository backups, repeat the drill with a disposable prefix on your endpoint. Record the expected branch tip before the test, give the recovery machine access to the stored set, and verify that it can check out that exact commit without contacting the original Git server.
Pick one AI, compute, or storage workload and see the difference for yourself. Spin it up in minutes, or let our team map your fastest path to production.