Pull multiple git repositories when working with that not-so-usual PC

less than 1 minute read

At least, every few days I change my workplace and I work on a different computer (home-laptop-work). For this reason, I usually need to ensure that I’m using the latest version of each repository.

After writing a script to facilitate the task of clonning several Git repositories, it is logical to consider the same when I need to pull them. In this post I want to share the script I use to automatically pull all my git repositories in one step, no matter if they are stored in GitHub, GitLab or Bitbucket. Practically, its the same script proposed by douglas, but simpler and following my personal naming convention…

The multiple-git-pull.sh script is stored in a Gist and allows me to pull several repositories stored in the same working folder (e.g. /home/user/git).

Avoid some headaches and innecesary pulls just by executing this script in your git working folder (if you have one :)

bash multiple-git-pull.sh

I hope you like it ;)

#!/bin/bash
# Based on https://gist.github.com/douglas/1287372
# But with a couple of changes
# store the current dir
CUR_DIR=$(pwd)
# Let the person running the script know what's going on.
echo "Pulling in latest changes for all repositories..."
# Find all git repositories and update it to the master latest revision
for i in $(find . -name ".git" | cut -c 3-); do
echo "";
echo $i;
# We have to go to the .git parent directory to call the pull command
cd "$i";
cd ..;
# finally pull
# This is the only thing I changed
# I have repos where I don't edit in the master branch
#git pull origin master;
git pull;
# lets get back to the CUR_DIR
cd $CUR_DIR
done
echo "Complete!"