Last active
May 21, 2018 13:02
-
-
Save krohne/c422e080bbacf11672eab4b90b83bc34 to your computer and use it in GitHub Desktop.
Update collection of git repositories quickly in parallel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# $1 - a folder containing multiple git repos; i.e. ~/work | |
# The Mac way to get number of logical cores | |
# You can run more parallel processes than the number of cores, | |
# but at some point the process will slow to a crawl | |
cores=$( sysctl -n hw.ncpu ) | |
# list all paths below $1 in single column, and pipe to xargs: | |
# ls -d1 $1/*/ | | |
# Run a bash command on each path, using $cores number of processes: | |
# xargs -I % -n 1 -P $cores bash --login -c | |
# cd to the path | |
# cd % ; | |
# discard changes to package.json (if any) | |
# git checkout -- package.json | |
# pull updates | |
# git pull ; | |
# if '.nvmrc' exists, then use that version of npm, else use npm version 4 | |
# [ -f .nvmrc ] && nvm use || nvm use 4 ; | |
# update node dependencies | |
# npm install ; | |
ls -d1 $1/*/ | xargs -I % -n 1 -P $cores bash --login -c 'cd % ; git checkout -- package.json ; git pull ; [ -f .nvmrc ] && nvm use || nvm use 4 ; npm install ;' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment