Skip to content

Instantly share code, notes, and snippets.

@lmmx
Created April 25, 2025 12:54
Show Gist options
  • Save lmmx/f2ebfa58ba05cfa832c70ecab4833f08 to your computer and use it in GitHub Desktop.
Save lmmx/f2ebfa58ba05cfa832c70ecab4833f08 to your computer and use it in GitHub Desktop.
Sync your remote git repo with its upstream (default branch), so you can then pull the changes to your local repo
function sync-fork() {
local origin_url=$(git config --get remote.origin.url)
local fork_repo=""
if [[ $origin_url =~ github\.com[:/]([^/]+/[^/.]+) ]]; then
fork_repo="${BASH_REMATCH[1]}"
else
echo "Error: Could not parse origin remote URL"
return 1
fi
local upstream_url=$(git config --get remote.upstream.url)
local upstream_repo=""
if [[ $upstream_url =~ github\.com[:/]([^/]+/[^/.]+) ]]; then
upstream_repo="${BASH_REMATCH[1]}"
else
echo "Error: Could not parse upstream remote URL or upstream not configured"
return 1
fi
echo "Syncing $fork_repo with $upstream_repo..."
gh repo sync $fork_repo --source $upstream_repo
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment