In JGit there is a SubmoduleWalk
that might help with your problem. To run a checkout command on all submodules, you would write something along these lines:
try (SubmoduleWalk walk = SubmoduleWalk.forIndex(repository)) {
while(walk.next()) {
try (Repository submoduleRepository = walk.getRepository()) {
Git.wrap(submoduleRepository).checkout().call();
}
}
}