Last active
October 14, 2020 16:34
-
-
Save robkooper/3aa68f347b2bc2cebfbb9099aa52349e to your computer and use it in GitHub Desktop.
Simple script to synchronize a forked repository.
This file contains 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 | |
# 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