Last active
April 26, 2020 02:05
-
-
Save alwinw/73c3e46348cb75fb18df64d24cf7b2df to your computer and use it in GitHub Desktop.
Git pull all branches from another remote and push them as their own group
This file contains hidden or 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/sh | |
| MIRROR_REPO=${MIRROR_REPO:-"origin"} | |
| UPSTREAM_REMOTE=${UPSTREAM_REMOTE:-"upstream_remote"} | |
| UPSTREAM_REMOTE_NAME=${UPSTREAM_REMOTE_NAME:-"upstream"} | |
| UPSTREAM_REMOTE_URL=${UPSTREAM_REMOTE_URL:-"<alternate-remote.git>"} | |
| echo "Pulling $UPSTREAM_REMOTE_URL" | |
| git remote add "$UPSTREAM_REMOTE" "$UPSTREAM_REMOTE_URL" | |
| git fetch "$UPSTREAM_REMOTE" | |
| for branch in $(git ls-remote $UPSTREAM_REMOTE | grep -oP '(?<=refs/heads/).*'); do | |
| echo "Fetching branch '$branch' and setting upstream to '$MIRROR_REPO/$UPSTREAM_REMOTE_NAME/$branch'" | |
| git fetch "$UPSTREAM_REMOTE" "$branch:$UPSTREAM_REMOTE_NAME/$branch" | |
| git push --set-upstream "$MIRROR_REPO" "$UPSTREAM_REMOTE_NAME/$branch:$UPSTREAM_REMOTE_NAME/$branch" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment