albusdemens
albusdemens

Reputation: 6634

First push for folder with submodules on GitLab

I need to push to GitLab a folder (this will be my repo) that contains several modified gihub repos. What is the best way to do it? As far as I understood, what I should do it

  1. Make a GitLab repo for the main folder
  2. Push the submodules
  3. Push the main module

The content of the .gitmodules file is as follows:

[submodule "restyle"]
   path = restyle
   url = ./restyle

Once I push the main folder, the submodules are visible on GitLab, but I cannot open them. How can I fix this? I would like to see the actual folder and to be able to open them.

Upvotes: 0

Views: 670

Answers (1)

Chris Burghart
Chris Burghart

Reputation: 76

The .gitmodules file you presented contains a circular definition; it says that Git should create a submodule for your repository at path restyle, and should populate that path with a clone of the Git repository at URL ./restyle, which is exactly the same directory. The URL needs to point to a Git repository located outside of the current repository. That is why you are unable to open your submodule.

I recommend the Git Tools - Submodules documentation for a more complete description.

If you want a single monolithic repository instead of a main repository which uses submodules, then your "submodules to simple folders" solution should be fine.

However, if you want to retain the submodule aspect of your existing repository, you will need a .gitmodules file that has appropriate URLs for the source of each of the submodules. If you make changes to a submodule, you have a couple of options:

  1. If your changes would help others, make a pull request at the submodule's origin and get your changes moved upstream.

    Once done, pull the updates back into your submodule directory and check out the new commit.

    In your main repository top directory, commit the new revision pointer for the updated submodule.

  2. If your changes cannot or should not be incorporated in the original upstream location, then it would be best to clone that upstream repository into your GitLab account/instance and change your submodule to point to your GitLab copy.

    Push your changes to GitLab.

    In your main repository top directory, commit the new revision pointer for the updated submodule.

Upvotes: 1

Related Questions