Skip to content

Instantly share code, notes, and snippets.

@mattrudder
Created August 22, 2014 16:17
Show Gist options
  • Select an option

  • Save mattrudder/01b03c1a39cb0b5d407f to your computer and use it in GitHub Desktop.

Select an option

Save mattrudder/01b03c1a39cb0b5d407f to your computer and use it in GitHub Desktop.
Update git repositories in named subdirectories, preserving working copy changes.
#!/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