Skip to content

Instantly share code, notes, and snippets.

@icyveins7
Last active November 21, 2023 05:16
Show Gist options
  • Save icyveins7/e657cfa50291850404fa88c8b04c663f to your computer and use it in GitHub Desktop.
Save icyveins7/e657cfa50291850404fa88c8b04c663f to your computer and use it in GitHub Desktop.
Git Pull on Multiple Folders

Who This Is For

If you're like me, you have some (or most) of your github repositories stored in some parent folder like ~/gitrepos. Sometimes you want to just update multiple repositories together without having to git pull each one individually. Hopefully this will help you.

Setting It Up

First off, SSH access is required for private repos, so we'll assume you have this set up already. Github has enough documentation to cover this.

If your keys are password locked (as they should be), you should run

Linux

ssh-add

Windows (Git Bash)

eval ($ssh-agent)
ssh-add

and then type your password to unlock the ssh for some time without having to keep prompting you.

The Script

Then you can just create a script like this while inside the ~/gitrepos folder and run it.

declare -a dirs=(
            "repo1"
            "repo2"
            "repo3")
            
for i in "${dirs[@]}"
do
  echo "$i"
  cd $i
  git pull
  git submodule update --remote
  cd ..
done

I have added the submodule update line in case your repos have submodules which need to be updated.

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