Skip to content

Instantly share code, notes, and snippets.

@mmguero
Created September 5, 2024 14:52
Show Gist options
  • Save mmguero/788bb455a83ab9d2f472abf1f854dfe5 to your computer and use it in GitHub Desktop.
Save mmguero/788bb455a83ab9d2f472abf1f854dfe5 to your computer and use it in GitHub Desktop.
loop through directories and add remotes for parents when they exist
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