0

I have a major problem with git pull when dealing with submodules. I thought I started understanding their principle but apparently not...

I created a simple git repo Super and created a submodule module in it. My first issue is when make a commit in module (I add a text file) and push the code, I can see that on github that the text file does not go into the submodule module but in fact goes into the superproject Super (the submodule does not even show in github). So when I do a git pull in Super I end up with the text file in the local copy of my repo that I already pushed in my submodule... I am not sure what I am doing wrong. here is the code basically:

   cd module (a text file "Test" was added to be commited)
   ~/Super/module [master]: git add -A
   ~/Super/module [master]: git commit -m 'comment'
   ~/Super/module [master]: git push
   cd Super
   ~/Super [master] : git pull
   and now the text file "Test" shows up in my Super next to the submodule "module".

So this is already problematic but I can live with that. I now go into my Super and delete this text file and add the changes made to the submodule module in order to repoint the latest submodule commit.

(after deleting the text file )
~/Super [master] : git add -A
~/Super [master] : git commit -m 'comment 2'
~/Super [master] : git submodule update
~/Super [master] : git pull
~/Super [master] : git push

I now go in my submodule and do a git pull

~/Super/module [master]: git pull

and this create a copy of everything that is in the super and put it in the submodule module. So if I do a ls in module I find a nested submodule module, which is a big problem.

~/Super/module/module [master]: 

So I basically have 2 problems :

  • When I push my submodule a copy goes to the superproject

  • when pulling in my submodule after updating my superproject, it creates a nested submodule.

Can anybody out there tell me what I am doing wrong? I am very sorry if this might seem obvious to you guys, but I have been stuck on this problem for while and it is very frustrating.

I have added the .gitmodules files and .git/config from the Super:

.gitmodules:

[submodule "module"]
path = module
url = git@github.com:titocazou/Super.git

.git/config:

[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = git@github.com:titocazou/Super.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[submodule "module"]
url = git@github.com:titocazou/Super.git
titocazou
  • 3
  • 1
  • 6
  • It would help if you could add the contents of both the `.gitmodules` file in the Super repo, and the contents of `.git/config` in both the Super and the module repos. – Amber May 11 '13 at 01:55

1 Answers1

0

It sounds to me like you may have set the wrong remote path for your submodule, and so your submodule is actually pointing to a remote that is shared with your parent repository. (Basically, you've duplicated your repository inside itself.)

Check the contents of .gitmodules to see what remote path your submodule is actually pointing at for pushes and pulls, and make sure it's not the same as the path your parent repository is pushing to and pulling from.

Amber
  • 507,862
  • 82
  • 626
  • 550
  • Thanks a lot Amber about your quick answer ! I thought at some point that it might come from the .gitmodules urls (since the super and module urls match) but what I should change them into ? (I have added the .gitmodules and .git/config file to my question) – titocazou May 11 '13 at 03:10
  • A submodule is designed to be a completely separate repository (simply embedded in the directory tree of a different repository). You'd want to create a second repository for the submodule and point the submodule at that. However, the other question is... what are you wanting to use a submodule for in the first place? – Amber May 11 '13 at 03:43