Created
August 22, 2014 16:17
-
-
Save mattrudder/01b03c1a39cb0b5d407f to your computer and use it in GitHub Desktop.
Update git repositories in named subdirectories, preserving working copy changes.
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 | |
| # git-sync.sh: Update git repositories in named subdirectories, preserving working copy changes. | |
| for f in $@ | |
| do | |
| pushd $f > /dev/null | |
| echo "Updating $f..." | |
| git update-index -q --refresh | |
| git diff-index --quiet HEAD -- | |
| hasChanges=$? | |
| if [ $hasChanges = 1 ]; then | |
| git stash -q | |
| fi | |
| git pull --rebase | |
| if [ $hasChanges = 1 ]; then | |
| git stash pop -q | |
| fi | |
| popd > /dev/null | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment