Skip to content

Instantly share code, notes, and snippets.

@cpuguy83 cpuguy83/gitsynch.sh
Created Sep 12, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.