Created
July 6, 2022 15:27
-
-
Save Skinner927/26be545572eea5be0bfae589d9787be2 to your computer and use it in GitHub Desktop.
Mirror/clone repo for offline mirror
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Derived from: | |
# https://www.edwardthomson.com/blog/mirroring_git_repositories.html | |
# Mirrors repo and zips it up for easy transport to offline network | |
set -eufo pipefail | |
if [ "$#" -ne 1 ]; then | |
echo "usage: $0 source_repo_url" >&2 | |
exit 1 | |
fi | |
SOURCE_URL="$1" | |
REPONAME="$(basename "$SOURCE_URL")-mirror" | |
WORKDIR="$(mktemp -d)/${REPONAME}" | |
mkdir -p "$WORKDIR" | |
echo "Cloning from ${SOURCE_URL} into ${WORKDIR}..." | |
git init --bare "${WORKDIR}" | |
cd "${WORKDIR}" | |
git config remote.origin.url "${SOURCE_URL}" | |
git config --add remote.origin.fetch '+refs/heads/*:refs/heads/*' | |
git config --add remote.origin.fetch '+refs/tags/*:refs/tags/*' | |
git config --add remote.origin.fetch '+refs/notes/*:refs/notes/*' | |
git config remote.origin.mirror true | |
git fetch --all | |
echo "" | |
echo "Cloned to ${WORKDIR}" | |
ZIP_FILE="${REPONAME}.zip" | |
cd .. | |
zip -r "$ZIP_FILE" "$REPONAME" | |
echo '' | |
echo "Mirrored repo zipped into ${PWD}/${ZIP_FILE}" | |
echo 'Upload with: git push --mirror TARGET_URL' | |
rm -rf "${WORKDIR}" | |
echo "Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment