Created
June 7, 2026 15:04
-
-
Save ravshansbox/e76ddfd1f79d55bf5156be424e37d4ae to your computer and use it in GitHub Desktop.
After cloning a GitHub fork, set 'upstream' remote to the original parent repo. Tiny, no gh repo set-default needed.
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
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| slug=$(git remote get-url origin | sed -E 's#^.*[/:]([^/]+/[^/.]+)(\.git)?$#\1#') | |
| url=$(gh api "repos/$slug" --template '{{if .fork}}{{.parent.ssh_url}}{{end}}' 2>/dev/null || true) | |
| [[ -z $url ]] && { echo "not a fork"; exit 0; } | |
| git remote add upstream "$url" 2>/dev/null || git remote set-url upstream "$url" | |
| git fetch upstream --prune | |
| echo "upstream → $url" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment