Here\'s part of the contents of my .gitmodules
file:
[submodule \"src/static_management\"]
path = src/static_management
url = gi
For the record:
I created the same issue by adding an empty repository as submodule. In this case, there was no reference hash available for the submodule, leading to the error described by the original poster.
Force-adding the repository after having committed to it solved the issue (as in Arvids post)
git submodule add --force git@my-repo.git destination
When I saw this today, a developer had moved part of the tree into a new sub-directory and it looks as though his git client did not record the updated Subproject rules in the tree, instead they were just nuked, leaving .gitmodules
referring both to stale locations and to subprojects which no longer existed in the current tree.
Adding the submodules back in, and comparing the commit shas of the submodule to those found in git show $breaking_commit_sha
(search for lines matching regexp ^-Subproject
) to adjust as needed fixed things.
Same as you I found that git submodule sync does not do what you expect it to do.
Only after doing an explicit git submodule add
again does a submodule url change.
So, I put this script in ~/bin/git-submodule-sync.rb
:
https://gist.github.com/frimik/5125436
And I also use the same logic on a few post-receive git deploy scripts.
All I need to do now is edit .gitmodules
, then run this script and it finally works like I thought git submodule sync
was supposed to.
Thinking that manually setting up .gitmodules
is enough is WRONG
My local git version 2.22.0
as of this writing.
So I came to this thread wondering why wasn't git submodule init
working; I setup the .gitmodules
file and proceeded to do git submodule init
...
IMPORTANT
git submodule add company/project.git includes/project
is required (when adding the module for the first time), this will:
.git/config
.gitmodules
fileincludes/project
in this example).you must then git commit
after you have added the submodule, this will commit .gitmodules
and the tracked submodule location.
When the project is cloned again, it will have the .gitmodules
and the empty submodules directory (e.g. includes/project
in this example). At this point .git/config
does not have submodule config yet, until git submodule init
is run, and remember this only works because .gitmodules
AND includes/project
are tracked in the main git repo.
Also for reference see:
I had a similar problem with a submodule. It just didn't want to be cloned/pulled/updated/whatever.
When trying to re-add the 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 enforce the add command:
git submodule add --force git@my-repo.git destination
That worked in my case.
Below sync command resolved the issue :
git submodule sync