Skip to content

Instantly share code, notes, and snippets.

@cpuguy83
Created September 12, 2018 20:46
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 cpuguy83/125404c4d61a9b8c9d5a76cb1832a6b2 to your computer and use it in GitHub Desktop.
Save cpuguy83/125404c4d61a9b8c9d5a76cb1832a6b2 to your computer and use it in GitHub Desktop.
Synchronize a git fork with origin
#!/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