Created
September 12, 2018 20:46
-
-
Save cpuguy83/125404c4d61a9b8c9d5a76cb1832a6b2 to your computer and use it in GitHub Desktop.
Synchronize a git fork with origin
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 | |
set -e -u -o pipefail | |
export ORIGIN="${1}" | |
export FORK="${2}" | |
dir=$(mktemp -d) | |
( | |
cd "${dir}" | |
git init --bare . | |
git remote add origin "${ORIGIN}" | |
git remote add fork "${FORK}" | |
BRANCHES=($(git ls-remote --heads origin | awk '{ print $2 }' | awk -F'/' '{ print $3 }')) | |
BRANCHES_LOCAL=() | |
for b in ${BRANCHES[@]}; do | |
BRANCHES_LOCAL+=("${b}:${b}") | |
done | |
git fetch --update-head-ok origin ${BRANCHES_LOCAL[@]} | |
git push fork ${BRANCHES[@]} | |
git fetch --tags origin | |
git push --tags fork | |
) | |
rm -rf "${dir}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment