Last active
September 11, 2015 09:25
-
-
Save danielmitd/8e301d42f3c1504e8a27 to your computer and use it in GitHub Desktop.
script to update all local git repositories 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/zsh | |
| # place this in $PATH and then run: | |
| # git up-all | |
| # make it beautiful | |
| autoload colors ; colors | |
| GIT=`which git` | |
| folders=(/srv/modules /srv/httpd) # entry points for git folder search | |
| git_dirs=() # git directories | |
| maxdepth=3 # folder depth for entry points | |
| # check for git up command | |
| git up --version > /dev/null 2>&1 || \ | |
| (echo "$fg[red]error$reset_color: git-up is required (https://github.com/aanand/git-up)\n" && exit 1) | |
| update() | |
| { | |
| output=`$GIT --git-dir=$1/.git --work-tree=$1 up 2>&1` | |
| echo "update $fg[yellow]$1$reset_color:" | |
| echo "$output\n" | |
| } | |
| # find git folders in project directories | |
| for folder in $folders; do | |
| for dir in $(find "$folder" -maxdepth $maxdepth -mindepth 2 -type d -name .git); do | |
| git_dirs+=(${dir/\/.git/}) | |
| done | |
| done | |
| echo "found $fg[yellow]${#git_dirs}$reset_color directories.\n" | |
| # update all directories | |
| for directory in $git_dirs; do | |
| update $directory & # "&" fork of to be faster | |
| done | |
| # wait for all forked jobs | |
| wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment