DevTip: How to pull changes from all your git repositories

So every once in a while you would like to sync all the git repositories you work/worked on in the past. It cumbersome to always just go trough one by one.

I use this nifty little script:

#!/bin/bash

#Define the color yellow for later use
YELLOW='\033[0;33m'

#Define text reset
NC='\033[0m'

pathToRepos=~/work/repos

for i in `ls $pathToRepos`;do
    repo=$pathToRepos"/"$i
    #Get curreny branch name
    branch=`git -C $repo symbolic-ref --short -q HEAD`
    if [ -d $repo/.git ]; then
        echo -e "\n${YELLOW}#"$i"#${NC} - ${branch}\n"
        git -C $repo stash
        git -C $repo pull --rebase
        git -C $repo stash pop
    fi
done

Hope it’s useful, let me know what you think ! 🙃

comments powered by Disqus