Files
git-mirror-zip/git-mirror-zip.sh
T
2026-08-05 21:28:37 +03:00

28 lines
585 B
Bash

#!/bin/bash
# Clone a git repo as a full mirror and pack it into a zip archive.
# Works on Linux and macOS.
set -euo pipefail
if [ $# -lt 1 ]; then
echo "Usage: $0 <git-repo-url> [output.zip]"
exit 1
fi
URL="$1"
OUT="${2:-repo.zip}"
WORK_DIR=".tmp_git_mirror"
# Cleanup on exit
cleanup() { rm -rf "$WORK_DIR"; }
trap cleanup EXIT
echo "[1/3] Cloning mirror of $URL ..."
git clone --mirror "$URL" "$WORK_DIR"
echo "[2/3] Creating $OUT with maximum compression ..."
(cd "$WORK_DIR" && zip -9 -r "../$OUT" .)
SIZE=$(du -m "$OUT" | cut -f1)
echo "[3/3] Done: $OUT (${SIZE} MB)"