Skip to content

Instantly share code, notes, and snippets.

@ViacheslavK
Last active June 20, 2022 23:37
Show Gist options
  • Save ViacheslavK/4613a0a4a04df8b43d3b552abb823573 to your computer and use it in GitHub Desktop.
Save ViacheslavK/4613a0a4a04df8b43d3b552abb823573 to your computer and use it in GitHub Desktop.
bash script for updating all repositories, located in folder. Save as `your_name.sh` and add execution rights (`chmod +x your_name.sh`)
#!/bin/sh
for D in *; do
if [ -d "${D}" ]; then
cd "${D}"
if [ -d ".git" ]; then
git pull -v
fi
cd ..
fi
done
@ViacheslavK
Copy link
Author

Possible improvement if use next for understanding branch state

#!/bin/sh

UPSTREAM=${1:-'@{u}'}
LOCAL=$(git rev-parse @)
REMOTE=$(git rev-parse "$UPSTREAM")
BASE=$(git merge-base @ "$UPSTREAM")

if [ $LOCAL = $REMOTE ]; then
    echo "Up-to-date"
elif [ $LOCAL = $BASE ]; then
    echo "Need to pull"
elif [ $REMOTE = $BASE ]; then
    echo "Need to push"
else
    echo "Diverged"
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment