Search code examples
linuxgitversion-controlgit-submodules

Pushing local repo to remote does not push submodule files using GIT


I'm new to GIT and am struggling with it. I've got a website that is stored in a repository. The website requires a theme folder that is setup as a separate repository.

I've used the git submodule add command successfully to add the theme repository to my website.

So now I have a website repro with a theme child repro. The files for the submodule are showing inside my website folder.

I'm trying to push the entire main website repro to a remote server which works but the files of the theme (submodule) are not pushed.


Solution

  • The submodule is very much like an independent respository - it knows nothing about whether it's been included as a submodule in the parent repository. The parent repository doesn't know that much about the submodule either - just where it should be in the tree, what commit the submodule should be at and what URL to initially clone it from...

    I don't think there's a command that will push all your submodules for you - the sequence of events when you update some files in the submodule should be:

     cd theme
    
     # [Change or add some files, etc.]
    
     # Now commit those changes:
     git commit -a
    
     # Push them to the origin repository, assuming you're on the master branch:
     git push origin master
    
     # Change up to the parent repository:
     cd ..
    
     # Create a commit with the new version of that submodule:
     git add theme
     git commit -m "Committing a new version of the theme submodule"
    
     # Now push the commit that includes a pointer to the new submodule
     # version in the parent repository:
     git push origin master
    

    The typical problem here is pushing a commit in the parent repository that references a submodule version that you haven't yet pushed from the submodule version. You may find it helpful to create a script so that you don't forget any of those steps.