Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parallelize script for git pulling multiple repositories

Tags:

git

linux

shell

npm

When I get to work each morning I run a script that pulls multiple repositories my company uses:

#!/bin/bash
cd ~/myCompany/rep1
git pull --rebase
git submodule update
cd ~/myCompany/rep2
git pull --rebase
npm install
npm run build
cd ~/myCompany/rep3
git pull --rebase
npm install
npm run build
cd ~/myCompany/rep4
git pull --rebase
npm install
npm run build
cd ~/myCompany/rep5
git pull --rebase
git submodule update
echo "done!"

As you can see, different repositories need to be built while others need a submodule update and so on.

I was wondering if theres any way to make this script run each git pull and their respective commands in parallel instead of one after the other. Does anyone know how I'd achieve such a thing?

like image 961
MarksCode Avatar asked Sep 21 '25 11:09

MarksCode


1 Answers

Make it a function, call the function in the background:

#!/bin/bash
npmBuild() {
    cd $1
    git pull --rebase
    npm install
    npm run build
}
npmBuild ~/myCompany/rep2 &
npmBuild ~/myCompany/rep3 &

Make a slightly different function for the ones where you don't npm.

like image 149
jeremysprofile Avatar answered Sep 23 '25 02:09

jeremysprofile