Last active
January 27, 2023 14:17
-
-
Save ismet55555/2838d2f53c99a5af29043c9ec8716910 to your computer and use it in GitHub Desktop.
Sync with upstream
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
#!/bin/bash | |
UPSTREAM_SOURCE="https://github.com/XXXXXXXXX/XXXXXXXXXX.git" | |
KEEP_THIS="path/to/file/or/dir" | |
# Check if upstream remote is defined | |
if ! git remote -v | grep -q upstream; then | |
git remote add upstream ${UPSTREAM_SOURCE} | |
echo "Successfully added 'upstream' to remotes: ${UPSTREAM_SOURCE}" | |
fi | |
echo "Staging and committing any local changes ..." | |
git add . | |
git commit "Current changes and updates" | |
echo "Pulling any origin remote changes while keeping incoming remote changes ..." | |
git config pull.rebase false | |
git pull | |
git checkout --their . | |
echo "Merging upstream remote changes ..." | |
git fetch | |
git merge upstream/master | |
echo "If conflict, accepting my current changes for ${KEEP_THIS} ..." | |
git checkout --ours ${KEEP_THIS} | |
git commit -am "Merged upstream" | |
echo "Pushing all local to origin remote ..." | |
git push | |
echo "DONE!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment