Last active
July 3, 2017 21:00
-
-
Save brennie/11891b02cb3e43dc1190a7fc3a17335b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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