Bash Script: Update all local Git Repositories

Update: This has now been “rubified”. Check out the new article here.

Here’s a little script I put together. I use it when I am about to start working on my projects – so I always know what was recently touched and I always stay current.

#!/bin/bash

# This is where I want my script to start.
cd ~/Projects/

# Let the person running the script know what's going on.
echo -e "\n\033[1mPulling in latest changes for all repositories...\033[0m\n"

# Find all directories here - that are at least 1 level down, but don't go any further than 1 directory.
# Go into those directories and pull the repository.
for i in $(find . -maxdepth 1 -mindepth 1 -type d); do
  echo -e "\033[1m"+$i+"\033[0m"; cd $i; git remote -v; git pull;
  cd ~/Projects/DealerTrend
done

echo -e "\n\033[1mComplete! Do work son!\033[0m\n"


Once you've made your shell script executable and run it - you should see output similar to this:

[myuser@mycomputer:~/Projects/] $ ./updateRepositories.sh 

Pulling in latest changes for all repositories...

+./sandbox+
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
+./myawesomerepo+
origin    remoteuser@gitserver:myrepo.git (fetch)
origin    remoteuser@gitserver:myrepo.git (push)
Already up-to-date.
+./myapplication+
origin    remoteuser@gitserver:myrepo.git (fetch)
origin    remoteuser@gitserver:myrepo.git (push)
Already up-to-date.
+./wordpress-plugin-open-source+
origin    remoteuser@gitserver:myrepo.git (fetch)
origin    remoteuser@gitserver:myrepo.git (push)
public    remoteuser@gitserver:myrepo.git (fetch)
public    remoteuser@gitserver:myrepo.git (push)
Already up-to-date.

Complete! Do work son!

I hope this is of some use to the public and if anyone has any improvements to be made on it – feel free to let me know!

Leave a Reply