Created
September 5, 2024 14:52
-
-
Save mmguero/788bb455a83ab9d2f472abf1f854dfe5 to your computer and use it in GitHub Desktop.
loop through directories and add remotes for parents when they exist
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
for DIR in *; do pushd "$DIR" >/dev/null 2>&1; export URL="https://api.github.com/repos/$(git remote -v| grep -P "origin.*push" | head -n 1 | cols 2 | sed "s/.*github\.com\///" | sed "s/\.git$//")"; export PARENT="$(curl -fsSL -H "Authorization: token $GITHUB_TOKEN" "$URL" | jq -r '.parent.html_url')"; [[ "$PARENT" != "null" ]] && export FORKNAME="$(echo "$PARENT" | cut -d'/' -f4)" && echo "$FORKNAME" && git remote add "$FORKNAME" "$PARENT"; popd >/dev/null 2>&1; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment