Commits

Stefan Saasen  committed f2ee636

Add 'git-mirror' command to easily mirror a repository.

  • Participants
  • Parent commits 8b2e415

Comments (0)

Files changed (2)

File bin/git-mirror

+#!/bin/bash
+
+if [ "$#" -ne 2 ]; then
+  echo "Usage:"
+  echo ""
+  echo "  git mirror SOURCE TARGET"
+  echo ""
+  exit -1
+fi
+
+set -e
+set -u
+
+SOURCE=$1
+TARGET=$2
+
+git fetch "${SOURCE}"
+for name in $(git for-each-ref "refs/remotes/${SOURCE}" --format="%(refname:short)" | grep -v HEAD); do
+    echo "Pushing branch '${name}' to ${TARGET}"
+    git push -q --tags "${TARGET}" ${name}:refs/heads/${name#${SOURCE}/}
+done

File man/git-mirror.1

+.\" Manpage for git-mirror
+.TH man 1 "May 2012" "1.0" "git mirror man page"
+.SH NAME
+git mirror  \- Push tags and branches from one repository to another
+.SH SYNOPSIS
+git mirror SOURCE TARGET
+.SH DESCRIPTION
+Push all the branches and tags from repository SOURCE into repository TARGET.
+
+.SH OPTIONS
+.TP
+.I SOURCE
+The name of the remote that is the source repository (e.g. origin).
+.TP
+.I TARGET
+The name of the remote that is the target repository.
+
+E.g.
+.nf
+    git mirror origin bitbucket
+.fi
+
+will push all the branches and tags that are available in origin to the
+repository named bitbucket.
+
+.SH SEE ALSO
+git(1)
+.SH BUGS
+No known bugs.
+.SH AUTHOR
+Stefan Saasen <stefan@saasen.me>