Bash: Git Submodule Foreach?
Answer : The script passwd to git submodule is run with it's working directory set to the top of the given submodule...so you can simply look at pwd to see if you're in you're in the particular submodule. However, if you take some time to read the git submodule documentation, it turns out to be even easier: foreach Evaluates an arbitrary shell command in each checked out submodule. The command has access to the variables $name, $path, $sha1 and $toplevel: $name is the name of the relevant submodule section in .gitmodules, $path is the name of the submodule directory relative to the superproject, $sha1 is the commit as recorded in the superproject, and $toplevel is the absolute path to the top-level of the superproject. So you can do something like this: git submodule foreach '[ "$path" = "Libraries/JSONKit" ] \ && branch=experimental \ || branch=master; git co $branch'