Skip to content

Instantly share code, notes, and snippets.

@cybertk
Last active August 29, 2015 14:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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
# https://gist.github.com/cybertk/8a61ed9aca71a66cd711
#
# Copyright (C) 2015 Quanlong <kyan.ql.he@gmail.com>
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