Skip to content

Instantly share code, notes, and snippets.

@ismet55555
Last active January 27, 2023 14:17
Show Gist options
  • Save ismet55555/2838d2f53c99a5af29043c9ec8716910 to your computer and use it in GitHub Desktop.
Save ismet55555/2838d2f53c99a5af29043c9ec8716910 to your computer and use it in GitHub Desktop.
Sync with upstream
#!/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