0

I would like to execute following command to do git fetch in git repos if the have a remote (= git remote is non-empty):

find -name .git -execdir test $(git remote) \; -execdir git fetch
                              ^^^^^^^^^^^^^
                              How to quote/escape/mask this?

Tried much variations which don't work like: "$(git remote)", '$(git remote)', \$\(git remote\), '"$(git remote)'", ...

  • Not a direct answer to the question you asked, but you can also use a glob: shopt -s globstar; for d in **/*.git; do pushd "$d"; test ...; popd; done – slhck Jan 29 '16 at 14:54
  • @slhck Also a nice idea :) – criztovyl Jan 30 '16 at 17:29
2

Try this:

find -name .git -execdir sh -c 'test $(git remote)' \; -execdir git fetch \;

and because that starts a shell anyway, you can even do:

find -name .git -execdir sh -c 'test $(git remote) && git fetch' \;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.