Stefan Saasen avatar Stefan Saasen committed f2ee636

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

Comments (0)

Files changed (2)

+#!/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
+.\" 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>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.