Last active
November 24, 2021 17:06
-
-
Save clockworksoul/1029ce118194d8662d4e8b7d21652f00 to your computer and use it in GitHub Desktop.
Syncs a fork with its parent repo (so you don't have to)
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 | |
# For best results, drop this into your path as "git-sync" and "chmod +x" it. | |
# | |
# From that point forward, you'll be able to use "git sync" as a command to | |
# synchronize any repository with a registered upstream. | |
set -eo pipefail | |
CURRENT_BRANCH=$(git status | grep '^On branch ' | sed 's/On branch //') | |
if [[ -n "$1" ]]; then | |
TARGET_BRANCH="$1" | |
else | |
TARGET_BRANCH=$CURRENT_BRANCH | |
echo "No branch specified. Using current ($CURRENT_BRANCH)" | |
fi | |
if [[ ! $(git remote -v | grep 'upstream') ]]; then | |
echo "No configured upstream repository. Use: git remote add upstream [email protected]:ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git" | |
exit 1 | |
fi | |
if [[ "$CURRENT_BRANCH" != "$TARGET_BRANCH" ]]; then | |
git checkout "$TARGET_BRANCH" | |
fi | |
git fetch upstream | |
git merge "upstream/$TARGET_BRANCH" | |
git push |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment