Skip to content

Instantly share code, notes, and snippets.

@robkooper
Last active October 14, 2020 16:34
Show Gist options
  • Save robkooper/3aa68f347b2bc2cebfbb9099aa52349e to your computer and use it in GitHub Desktop.
Save robkooper/3aa68f347b2bc2cebfbb9099aa52349e to your computer and use it in GitHub Desktop.
Simple script to synchronize a forked repository.
#!/bin/bash
# save old state
BRANCH=$(git branch | awk '/^\*/ { print $2}')
STASH=$(git stash -u)
# update all remotes
git fetch --all
# update master
git checkout master
git merge upstream/master
git push
# update develop
git checkout develop
git merge upstream/develop
git push
# restore
git checkout ${BRANCH}
if [ "${STASH}" != "No local changes to save" ]; then
git stash pop
fi
# merge develop in current branch
if [ "$BRANCH" != "master" -a "$BRANCH" != "develop" ]; then
git merge upstream/develop
fi
# cleanup
git remote prune origin
git branch --merged | egrep -v "\*|master|develop" | xargs -n 1 git branch -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment