I have sup
aliased to submodule foreach 'git co master; git up'
(co
& up
are aliases for checkout
& pull --rebase
, respectively.).
How do add a condition so that if the submodule name is Libraries/JSONKit
, it checks out the branch named experimental
, instead of master
?
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With