Skip to content

Instantly share code, notes, and snippets.

@cybertk
Last active August 29, 2015 14:17
Show Gist options
  • Save cybertk/8a61ed9aca71a66cd711 to your computer and use it in GitHub Desktop.
Save cybertk/8a61ed9aca71a66cd711 to your computer and use it in GitHub Desktop.
Copy a remote git repo to another remote destination
#!/bin/sh
#
# Copy a remote git repo to another remote destination
#
# Copyright (C) 2015 Quanlong <[email protected]>
# Options validation
if [ -z "$1" -o -z "$2" ];
then
echo "Usage: git copy <source_repo_url> <destionation_repo_url>"
exit 1
fi
SRC_REPO=$1
DST_REPO=$2
# Clone a bare repo
repo_name="${SRC_REPO##*/}"
[[ -d "${repo_name}" ]] || git clone --mirror ${SRC_REPO}
cd ${repo_name}
# Update local refs
git fetch --prune --progress
git fetch --prune --tags --progress
# Push to another repo for mirrors
git push --prune ${DST_REPO} +refs/heads/*:refs/heads/* +refs/tags/*:refs/tags/*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment