Skip to content

Instantly share code, notes, and snippets.

@cybertk
Last active August 29, 2015 14:17

Revisions

  1. cybertk revised this gist Mar 26, 2015. 1 changed file with 14 additions and 6 deletions.
    20 changes: 14 additions & 6 deletions git-copy
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,12 @@
    #!/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
    @@ -14,14 +17,19 @@ 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}
    # 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 another repo for mirrors
    git push --prune ${DST_REPO} +refs/heads/*:refs/heads/* +refs/tags/*:refs/tags/*
    # 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}
  2. cybertk created this gist Mar 26, 2015.
    27 changes: 27 additions & 0 deletions git-copy
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    #!/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/*