Search code examples
gitgit-submodulessymlink

How to convert automatically all symlink to git submodules in repo


How to convert automatically all symlink to git submodules in some repo.

I want to do something like, I have on client side:

folder1(repo1) 
| 
+--folderA--file.a 

folder2(repo2) 
| 
+--symlink to folderA 

And I want convert it to git submodule, on server side:

repo1 
| 
+--FolderA--file.a 

repo2 
| 
+-- git submodule to folderA in repo1.. 

Repo 1 and repo 2 are mine.

(I need something like:

I have on client side folder1 inicializated as repo1, I have folder2 inicializated as repo2, I have symlink from one folder in folder 2 to one folder in folder1. And I need it on server side (git server) all symlinks convert to git submodules -> folder in repo2 to be submodule to folder in repo1.)

(sry for my English), I'm using google translator, and it sometimes translate very bad.


Solution

  • You cannot automate that, unless you know the remote repo URL those symlink are supposed to point to.

    If you do, delete the symlink, and type:

    git submodule add ../path/to/other/repo/.git otherRepo
    

    But in your case, that would clone repo1, not folderA

    repo2
    |
    + repo1
      |
      + folderA
    

    If you intent to make commits from repo2/repo1/folderA and push back, it is best to reference a bare repo version of repo1 (a repo1.git)