user user - 9 months ago 86
Git Question

How to send a git submodule folder `.git` to the parent repository `.git/modules/` folder?

When you locally create git submodules as on this script:

# Create the directory structure
mkdir main_repo
mkdir main_repo/unrelated_repo
mkdir main_repo/unrelated_repo/main_repo_submodule

cd main_repo

# Setup the unrelated_repo
cd unrelated_repo
printf "# UnRelated Repository\n\n" >
git init
git add -f
git commit -m "Added the unrelated repository first commit."
git remote add origin

# Setup the main_repo_submodule
cd main_repo_submodule
printf "# Main Repository Submodule\n\nThis is a submodule from the \`main_repo\`, and not from the \`unrelated_repo\`\n" >
git init
git add -f
git commit -m "Added the main repository submodule first commit."
git remote add origin

# Setup the main_repo
cd ../..
printf "# Main Repo\n\nThis is the main repository which contains submodules\n" >
printf "\nThis is a main_repo_file on the unrelated repository\n\n" > unrelated_repo/main_repo_file.txt
printf "\n*\n**\n\n" > unrelated_repo/.gitignore
git init
git add -f unrelated_repo/main_repo_file.txt unrelated_repo/.gitignore
git submodule add -f -- "unrelated_repo/main_repo_submodule"

git commit -m "Added the first main repository first commit."
git remote add origin

The submodule
folder will be located on the folder:

  1. main_repo/unrelated_repo/main_repo_submodule/.git/

However, if I push this submodule to a remote server do to perform a:

  1. git clone --recursive

The submodule git folder
will be located on:

  1. main_repo/.git/modules/main_repo_submodule/

And on its place will be a synlink to its git folder on the parent repository. So how to put a submodule just create on this parent folder
folder, wihtout cloning it recursively?

It is necessary because I want to keep my submodules folder on the parent modules folder, keeping the workspace clean, without having to recursively re-clone everything every time a new submodule is added.


I tried doing:

# Move the submodule to the parent repository
mkdir -p .git/modules
# shopt -s dotglob
mv unrelated_repo/main_repo_submodule/.git/ .git/modules
printf "gitdir: ../../.git/modules/main_repo_submodule\n" > unrelated_repo/main_repo_submodule/.git

But git says the submodule is not found.

phd phd
Answer Source


mv unrelated_repo/main_repo_submodule/.git/ .git/modules

you also need

mv .git/modules/.git .git/modules/main_repo_submodule
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download