Skip to content

Instantly share code, notes, and snippets.

@cpuguy83 cpuguy83/
Created Sep 12, 2018

What would you like to do?
Synchronize a git fork with origin
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 }'))
for b in ${BRANCHES[@]}; do
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
You can’t perform that action at this time.