Я бы сделал что-то вроде этого:
# fetch updates, but don't merge yet
git fetch # origin is default
# list all branches
git for-each-ref --format='%(refname:short)' refs/heads |
while read branch; do
# if the branch is not the same as the remote branch...
if [ "$(git rev-parse $branch)" != "$(git rev-parse origin/$branch)" ]; then
# only continue to the next step on successful results
git checkout $branch &&
git pull &&
(make &&
cp executable /somewhere/else;
make clean)
# except always make clean as long as we tried to make
#
# you might also consider a hard reset and clean, to guarantee things
# are safe for the next checkout
fi
done
Самое приятное при извлечении в первую очередь заключается в том, что вам не нужно без необходимости проверять ветки без изменений; если ваш репо большой, это может сэкономить время.
Очевидно, что при обработке ошибок необходимо сделать выбор; Я просто пошел с самой простой вещью, которая все еще имела смысл. Для более сложной обработки вы можете вместо этого сделать что-то вроде if make; then ...; else ...; fi
, например ::100100
# die hard on unexpected checkout/pull failures
if ! (git checkout $branch && git pull); then
exit 1
fi
if make; then
cp executable /somewhere/else
else
# report a build failure?
fi
# clean up no matter what
git clean -xdf
git reset --hard