Git will not initiate / synchronize / update new submodules

Here is part of the contents of my .gitmodules file:

 [submodule "src/static_management"] path = src/static_management url = git://github.com/eykd/django-static-management.git [submodule "external/pyfacebook"] path = external/pyfacebook url = http://github.com/sciyoshi/pyfacebook.git 

However .git/config contains only the first:

 [submodule "src/static_management"] url = git://github.com/eykd/django-static-management.git 

The second submodule ( external/pyfacebook ) was added by another developer to the feature branches. I have inherited development now and checked the function branch. However, Git will not pull the submodule for me. I tried:

  • git submodule init
  • git submodule update
  • git submodule update --init
  • git submodule sync
  • Removing all submodule definitions from .git/config and running git submodule init . It copies only the pre-existing submodule and ignores the new one.
  • Manually entering new submodule definitions in .git/config and running git submodule update . Only updated submodules do not want to be updated.

in different combinations, but Git simply will not update .git/config based on the new contents of .gitmodules , and it will not create an external/pyfacebook and will not pull out the contents of the submodule.

What am I missing? Is manual intervention required (adding submodule input manually in .git/config ) and why?

Edit: Manual intervention does not work. Manually adding a new submodule entry to .git/config means nothing. The new submodule is ignored.

+89
git git-submodules
Jul 26 '10 at 16:47
source share
17 answers

Have you recently upgraded to git version 1.7.0.4? I did and now have similar problems ...

Edit: I fixed my problem, but have no idea where the problem is. I manually deleted the submodule entries from both .git / config and .gitmodules and re-added my submodules with uninstall steps (git subodule add etc ...) ... Worksforme, but does not add any value to this stream.

+32
Aug 26 '10 at 16:10
source share

I had the same problem - it turned out that the .gitmodules file was committed, but the actual commit of the submodule (i.e. the record of the fix identifier of the submodule) was not.

Adding it manually seemed to do the trick - for example:

 git submodule add http://github.com/sciyoshi/pyfacebook.git external/pyfacebook 

(Even without removing anything from .git / config or .gitmodules.)

Then commit it to write the identifier correctly.

Adding additional comments to this working answer: if updating the submodule git initodule or git does not work, then as described above git subodule add url should do the trick. You can check it out on

  git config --list 

and you need to get the submodule entry that you want to extract from the git config -list command. If, as a result of the setup, there is a record of your submodule, now the usual update of the git --init submodule should pull out your submodule. To test this step, you can manually rename the submodule and then update the submodule.

  mv yourmodulename yourmodulename-temp git submodule update --init 

To find out if you have local changes in a submodule, you can see it through git status -u (if you want to see changes in a submodule) or git status --ignore-subodules (if you don't want to see changes in a submodule).

+75
Jan 28 2018-12-12T00:
source share

git version 2.7.4. This command updates the local git submodule update --init --force --remote code git submodule update --init --force --remote

+48
Nov 21 '16 at 11:15
source share

Had the same problem when git ignored the init and update commands and did nothing.

HOW TO SEARCH

  • Your submodule folder must be converted to git repo
  • It should not be in .gitignore

If these requirements are met, it will work. Otherwise, all commands will be executed without messages and results.

If you did all this and it still doesn't work:

  • Add a submodule manually, for example. git submodule add git@... path/to
  • git submodule init
  • git submodule update
  • commit and click all the files - .gitmodules and the folder of your module (note that the contents of the folder will not be executed)
  • cancel the local git repository
  • clone new
  • make sure .git/config does not yet have submodules
  • Now git submodule init - and you will see a message in which the module is registered
  • git submodule update - extract module
  • Now look at .git/config and you will find the registered submodule
+14
Oct 27 '15 at 13:45
source share

Sort by magic, but today I ran git submodule init and then git submodule sync , followed by git submodule update , and it started by pulling my submodules ... Magic? May be! This is truly one of the most annoying experiences with git ...

Scratch it. I actually worked by doing git submodule update --init --recursive . Hope this helps.

PS: Make sure you are in the git root directory, not the submodule.

+4
May 19 '14 at 1:10
source share

There is a lot of confusion in the answers (as well).

git submodule init is not intended to magically create files in .git / config (from .gitmodules). It is designed to create something in a completely empty subdirectory after cloning the parent project or pulling a commit, which adds a previously non-existent submodule.

In other words, you follow the git clone project that has submodules (which you recognize by the fact that the clone checked the .gitmodules file) with git submodule update --init --recursive .

You do not follow git submodule add ... with git submodule init (or git submodule update --init ), which should not work. In fact, the addition will already update the corresponding .git / config if everything works.

EDIT

If a previously nonexistent git submodule was added by someone else and you execute the git pull this commit, then the directory of this submodule will be completely empty (when you execute git submodule status new hash submodule should be visible, but before it will be.) In this case you need to follow git pull also with git submodule update --init (plus --recursive when it is a submodule inside a submodule) to get a new, previously non-existent, submodule; exactly the same as after the initial clone of the project with submodules (where, obviously, you did not have these submodules before one or the other).

+4
Dec 27 '16 at 17:52
source share

I had the same problem.

.gitmodules had a submodule, but after the git submodule init it was not in .git/config .

Provides the developer who added that the submodule also added the submodule directory to the .gitignore file. This does not work.

+3
Jan 28 '13 at 3:44
source share

According to a response from Dave James Miller, I can confirm that this worked for me. It was important here to fix the commit identifier of the subprojects. It’s just that writing to .gitmodules is not enough.

Here is the corresponding commit:

https://github.com/dirkaholic/vagrant-php-dev-box/commit/d5f4c40bdbd80eefbb5ac6029823733f591435ae

+2
Jul 15 2018-12-15T00:
source share

Same as I, found that git synchronization of a submodule does not do what you expect from it. Only after an explicit git submodule add expression does the URL submodule change again.

So, I put this script in ~/bin/git-submodule-sync.rb :

https://gist.github.com/frimik/5125436

And I also use the same logic for several post-receive git deployment scenarios.

Now I need to edit .gitmodules , then run this script, and it finally works, as I thought git submodule sync should.

+2
Mar 09 '13 at 19:36
source share

When I saw this today, the developer moved part of the tree to a new subdirectory, and it seems that his git client did not write updated Subproject rules in the tree, instead they were just nuclear, leaving .gitmodules for both obsolete locations and for subprojects that no longer exist in the current tree.

Adding the submodules back and comparing the step of fixing the submodule with the elements found in git show $breaking_commit_sha (finding lines matching the ^-Subproject regular expression) to configure the necessary fixed things.

+1
Apr 30 '14 at 21:00
source share

I had the same problem today and found out that since I typed git submodule init , then I had this line in my .git/config :

 [submodule] active = . 

I deleted this and typed:

 git submodule update --init --remote 

And everything returned to normal, my submodule is updated in its subdirectory, as usual.

+1
May 11 '17 at 16:54
source share

I had a similar problem with a submodule. He simply did not want to be cloned / dragged / updated / independently.

When trying to re-add a submodule using git submodule add git@my-repo.git destination I got the following output:

 A git directory for 'destination' is found locally with remote(s): origin git@my-repo.git If you want to reuse this local git directory instead of cloning again from git@my-repo.git use the '--force' option. If the local git directory is not the correct repo or you are unsure what this means choose another name with the '--name' option. 

So, I tried to execute the add command :
git submodule add --force git@my-repo.git destination

This worked in my case.

+1
May 31 '17 at 12:18
source share

Removing the dir submodule and its contents (the "external / pyfacebook" folder), if it exists before git submodule add ... , can fix the problems.

0
May 18 '17 at 15:18
source share

For the record:
I created the same problem by adding an empty repository as a submodule. In this case, there was no reference hash for the submodule, which led to the error described by the original poster.

Forcing the addition of storage after it was committed solved the problem (as in the Arvids post)
git submodule add --force git@my-repo.git destination

0
Jul 19 '18 at 15:36
source share
  • Remove the submodule from your .git/config
  • Run the git submodule init
  • Go to the submodule directory and run git pull origin master

Should work now

0
Dec 27 '18 at 8:38
source share

Thinking that manually configuring .gitmodules enough, WRONG

My local git version 2.22.0 at the time of this writing.

So I came to this topic, wondering why git submodule init does not work; I installed the .gitmodules file and proceeded to git submodule init ...

IMPORTANT

  1. git submodule add company/project.git includes/project requires git submodule add company/project.git includes/project (the first time the module is added), this will be:

    • add config to .git/config
    • update the .gitmodules file
    • Track the location of the submodule (in this example, includes/project ).
  2. Then you must git commit after adding the submodule, with the .gitmodules and the tracked location of the submodule being fixed.

When the project is cloned again, it will have .gitmodules and an empty .gitmodules directory (for example, includes/project in this example). At the moment, .git/config does not yet have a submodule configuration until git submodule init is started, and remember that this only works because .gitmodules AND includes/project tracked mainly by git repos.

See also for reference:

  • How to remove a submodule?
  • How do I move an existing submodule?
0
Jun 12 '19 at 5:33
source share

I had the same problem, but none of the solutions above helped. The entries in .gitmodules and in .git / config were correct, but the git submodules update --init --recursive commands of the git submodules update --init --recursive did nothing. I also deleted the submodule directory and ran git submodules update --init --recursive and returned the submodule directory, but with exactly the same commit as before.

I found the answer on this page . Command: git submodule update --remote

0
Jun 21 '19 at 13:44 on
source share



All Articles