Skip to content

Instantly share code, notes, and snippets.

@ianhinder
Created March 20, 2014 15:25
Show Gist options
  • Save ianhinder/9666299 to your computer and use it in GitHub Desktop.
Save ianhinder/9666299 to your computer and use it in GitHub Desktop.
Parallel submodule fetch
#!/bin/bash
set -e
set -u
if [ $# -eq 0 ]; then
git submodule -q foreach 'echo $name' | xargs -n 1 -P 10 git-submodule-fetch
else
while [ $# -gt 0 ]; do
(cd $1; git fetch -q || echo "Failed to fetch $1">&2)
/bin/echo -n .
shift
done
fi
@ncjones
Copy link

ncjones commented Jan 4, 2018

Generic version using recursive foreach:

# git-submodule-foreach-parallel.sh:

#!/bin/bash
git submodule foreach --recursive --quiet pwd | xargs -P10 -I{} bash -c "cd {}; $*"

@advance512
Copy link

Nice idea, @ncjones. Thanks!

@RoToRx88
Copy link

RoToRx88 commented Nov 4, 2019

To complete @ncjones code, and to introduce a tiny bit error management, you could change the cd {}; $* by a cd {} && $* therefore the command $* won't be executed outside of the desired path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment