Skip to content

Instantly share code, notes, and snippets.

@brennie
Last active July 3, 2017 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brennie/11891b02cb3e43dc1190a7fc3a17335b to your computer and use it in GitHub Desktop.
Save brennie/11891b02cb3e43dc1190a7fc3a17335b to your computer and use it in GitHub Desktop.
#!/bin/bash
# git-setup-mirror
#
# Set up a repository to sync to and from a mirror.
#
# This is useful for working on a project from several machines.
set -euo pipefail
if [[ $# -ne 1 ]]; then
echo >&2 <<END
Usage:
git setup-mirror URL
Set up a repository to sync to and from a mirror.
END
exit 1
fi
URL="${1}"
set +e
git config --get remote.mirror.url >/dev/null 2>&1
MIRROR_EXISTS=$?
set -e
if [[ ${MIRROR_EXISTS} -eq 0 ]]; then
echo 'git setup-mirror: remote "mirror" already exists'
exit 1
fi
git remote add mirror "${URL}"
git config --unset-all remote.mirror.fetch
git config --add remote.mirror.fetch "+refs/heads/dev/*:refs/heads/dev/*"
git config --add remote.mirror.push "+refs/remotes/origin/*:refs/heads/*"
git config --add remote.mirror.push "+refs/remotes/dev/*:refs/heads/dev/*"
git config --add remote.mirror.push "+refs/tags/*:refs/tags/*"
git config --add remote.mirror.push "+refs/notes/*:refs/notes/*"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment