Skip to main content
2 of 3
Changed title and provided an explanation that the "duplicate question" did not actually resolve the issue. The should not have been automatically marked as a duplicate.

find with execdir, pipe redirection evaluated too early (quote issue?)

I have changed the name and edited the content to get the re-submitted as it is not a duplicate of the suggested alternative. The two comments collectively were able to point me in the right direction, while the alternative question was off-point. I would love to give credit to @kamil-maciorowski and @ilkkachu; failing that, I will shortly provide the solution that they pointed me to in my own answer.

I use multiple GitHub accounts at work, so I need to modify the remote url to add my work account. I have figured out the recursive find -execdir, and how to get/sed/set the remote url, but I cannot combine them.

I tested the find command using git st, and it works correctly:

find . -type d -name ".git" -execdir zsh -c "git st" \;

I tested the git set process, and that works correctly:

git remote set-url origin $(git remote get-url origin | sed 's|https://github|https://my_work_username@github|g')" \

When I combine them, it isn't working so well:

find . -type d -name ".git" -execdir zsh -c "git remote set-url origin $(git remote get-url origin | sed 's|https://github|https://my_work_username@github|g')" \;

I first get an error that there is no .git folder and than a bunch of git syntax errors:

fatal: not a git repository (or any of the parent directories): .git usage: git remote set-url [--push] [] or: git remote set-url --add or: git remote set-url --delete

If I add an echo, I find that the git command I am issuing is:

git remote set-url origin

with no parameter

I've run out of ideas for trouble-shooting or term for searching to figure this one out.

Much appreciated.