1

I want to transfer all my git repos to another computer. How can I loop over my ~/Sites directory and get their clone urls/origins?

evolutionxbox
  • 3,932
  • 6
  • 34
  • 51
Toli
  • 5,547
  • 8
  • 36
  • 56
  • This is a very specific problem... – evolutionxbox Aug 09 '20 at 23:38
  • 2
    So is this a duplicate of "how to write a loop in bash" or "how to get a list of remote URLs from a Git repository"? Or "how to change directory without having to change back"? – mkrieger1 Aug 09 '20 at 23:43
  • how to get a list of remote URLs from a Git repository, I haven't seen any answers on SO – Toli Aug 10 '20 at 02:56
  • 2
    Does this answer your question? [How can I determine the URL that a local Git repository was originally cloned from?](https://stackoverflow.com/questions/4089430/how-can-i-determine-the-url-that-a-local-git-repository-was-originally-cloned-fr) – jonrsharpe Aug 10 '20 at 06:51
  • @jonrsharpe no. please read my question. I want all the clone urls in my Sites dir. not just a single one – Toli Aug 10 '20 at 17:30
  • 1
    So what? You said above that was the specific part you were asking. As mentioned there are multiple parts to the problem, all with existing dupes. We don't need a Q&A for every possible combination of looping over directories and doing a thing, it's up to each of us to decompose the problem, research each part and integrate the answers. – jonrsharpe Aug 10 '20 at 17:32

1 Answers1

1
for dir in *; do
  ( cd "${dir%/*}" && echo "git clone $(git config --get remote.origin.url)" )
done
Toli
  • 5,547
  • 8
  • 36
  • 56
  • 1
    I think he just wants the URLs for now, so you don't need the clone - `for d in *; do ( cd $d && git config --get remote.origin.url ); done` – Paul Hodges Aug 10 '20 at 15:20