Fix git related issues

Replace the command using 'foreach' with 'for' loop.
'foreach' will stop the loop when error occured in one of the loop,
In our usecase, we want continue the loop.