Created
April 25, 2025 12:54
-
-
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
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
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