Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git submodule mess: how to use git submodules with developers not familiar with git?

I am really frustrated about using git's submodule feature. Either I still don't get it right or it just don't work as I am expecting this. Following project situation is given:

Project
  | .git
  | projsrc
  | source (submodule)
  | proj.sln

In this scenario source is pointing to another repository containing the common source data across all our projects. There is a lot of development happening under source as also under projsrc. Unfortunately Project points to some commit of the source submodule and not to the actual HEAD of it. This is the usual git behaviour, as far as I got it know.

I already found out that

git submodule update

just get the version of submodule which was commited together with the main Project. However, I would really like to be always up-to date with the submodules development, but do not have any real clue how to do this right. Hence my question is:

Is it possible to attach the Project to the HEAD of the submodule, reagardless of the fact if this will break the compilation of Project or not. I just don't want to go always into the submodule directory and do git pull there. Since I think I could loose my changes done in the submodule directory, because this is simple attached to a commit and not really to any branch or so.

Please consider following constraints:

  • Developers in our group are not that familiar with all VCS around. We are used to use really huge svn repository before, without any external repo features at all.
  • We are working on Windows
  • A click'n'forget solution would be best, since most of project members are rather scared by using a command line interface :)
like image 393
cgart Avatar asked Oct 28 '11 10:10

cgart


People also ask

Is using git submodules a good idea?

Git submodules may look powerful or cool upfront, but for all the reasons above it is a bad idea to share code using submodules, especially when the code changes frequently. It will be much worse when you have more and more developers working on the same repos.

Do I need git submodules?

In most cases, Git submodules are used when your project becomes more complex, and while your project depends on the main Git repository, you might want to keep their change history separate. Using the above as an example, the Room repository depends on the House repository, but they operate separately.

How do I manage git submodules?

Use the git submodule update command to set the submodules to the commit specified by the main repository. This means that if you pull in new changes into the submodules, you need to create a new commit in your main repository in order to track the updates of the nested submodules.

What is the point of git submodules?

Git submodules allow you to keep a git repository as a subdirectory of another git repository. Git submodules are simply a reference to another repository at a particular snapshot in time. Git submodules enable a Git repository to incorporate and track version history of external code.


2 Answers

The reason why a submodule points to a particular revision is important. If you point to a HEAD, builds will be unreproducible. I.e. if you checkout yesterday's a version of the Project, you would never know which exact version of source@HEAD was yesterday.

That's why it always stores particular revision sha.

To pull all submodules you could use Easy way pull latest of all submodules

like image 197
kan Avatar answered Nov 16 '22 02:11

kan


I am not good at Git and submodule. But I think some simple rules would be very helpful.

  1. Commit and push from sub-directory.
  2. Go back to root of your project, check the status if you need to commit and push again.

when Pull. can try to use script to bundle the "pull/submodule update" together. And only do it at the root of your project.

like image 20
Enze Chi Avatar answered Nov 16 '22 02:11

Enze Chi