Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore git submodule without read permission

The situation:

I have a repository that has a submodule.

Normal people (like me) don't have read permissions for this submodule which isn't really a problem as it isn't required to run the project.

My problem is that every time I check something out I get errors telling me that the submodule update failed because the submodule remote couldn't be read:

fatal: Needed a single revision
Unable to find current revision in submodule path 

no surprise ...

I tried to remove it manually from .gitmodules and then use

git update-index --assume-unchanged .gitmodules

but this only works until the next checkout as submodules seem to get special treatment.

I tried putting .gitmodules into .gitignore or .git/info/exclude but git ignored that, reported .gitmodules as changed and gave me the original one again at checkout.

My question:

How do I suppress these errors and completely ignore the existence of this submodule locally... including all further remote changes that try to reintroduce it?


Note: Please assume that the solution has to stay on my end and requires no changes on the remote side... as they will not happen (already tried talking to the repo admin)

like image 396
Fabian N. Avatar asked Oct 20 '25 14:10

Fabian N.


2 Answers

It's a bit difficult to replicate this situation, but as per discussion in comments

git submodule deinit -f .

helped. If someone stumbles here, from documentation one might find out that during init, actual git pull is done on submodule. So If You had no permissions to access remote submodule repository, locally git had no master branch, no commits to checkout, and that was the meaning behind error message.


Update: if you are using a gui like SourceTree or SmartGit, check the repository settings and disable the auto-update of submodules.
Depending on your setup only disabling "Initialize new submodules" may already fix the problem:

enter image description here

like image 139
JustMe Avatar answered Oct 22 '25 02:10

JustMe


Another option is to use

git config --global submodule.<module>.update none

Where is the name of the submodule you want to update.

Setting the value to none means that the submodule will not be checked out or updated. Since this is global it will apply across all repos.

From here

like image 26
dcsan Avatar answered Oct 22 '25 02:10

dcsan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!