Last active
August 29, 2015 14:17
-
-
Save cybertk/8a61ed9aca71a66cd711 to your computer and use it in GitHub Desktop.
Copy a remote git repo to another remote destination
This file contains hidden or 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 | |
# | |
# Copy a remote git repo to another remote destination | |
# https://gist.github.com/cybertk/8a61ed9aca71a66cd711 | |
# | |
# Copyright (C) 2015 Quanlong <[email protected]> | |
set -e | |
# 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 source into temp working dir | |
repo_name=`mktemp -d -t ck-git-copy` | |
git clone --mirror ${SRC_REPO} ${repo_name} | |
pushd ${repo_name} > /dev/null | |
# Update local refs | |
git fetch --prune --progress | |
git fetch --prune --tags --progress | |
# Push to destination | |
echo "Pushing to ${DST_REPO}" | |
git push -f --prune ${DST_REPO} +refs/heads/*:refs/heads/* +refs/tags/*:refs/tags/* | |
# Recovery | |
popd > /dev/null | |
rm -rf ${repo_name} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment