2

For one of my project I decided to use submodules.
They are nice to keep different plugins for application in separate repos, but I have one issue.
Any time I have uncommited changes in the submodule I cannot do anything with the main repo, it keeps track of the submodule and the moment I try to do a commit or anything I have to choose between loosing all my submodule changes or commit them first.

Its a huge pain to work on the main repo because the submodules getting in the way all the time. I have lost changes in the submodule so many times due to main repo deleting them when I was stashing or changing anything in the main repo.

So my question is, is there a way to tell git to only clone a subrepository but completely ignore it afterwards?

4
  • are you using the command line git client, or some gui tool? I don't currently use submodules but have used them quite a lot in the past and don't remember this sort of issue.
    – TZHX
    Commented May 17, 2022 at 15:17
  • I am using gitkraken.
    – HubertNNN
    Commented May 17, 2022 at 16:03
  • looks like this is gitkraken "feature" and there is also feature request to be able to disable this behaviour feedback.gitkraken.com/suggestions/193513/… , but this is still not implemented.
    – Serg
    Commented May 17, 2022 at 16:33
  • Command-line Git is less destructive than it sounds like gitkraken is here, but submodules are generally a pain in the <insert anatomy part> like this. Still, you might want to learn the CLI...
    – torek
    Commented May 17, 2022 at 17:35

1 Answer 1

2

I have to choose between loosing all my submodule changes or commit them first.

You should be able to add and commit, while ignoring your submodules:

submodule.<name>.ignore

Defines under what circumstances "git status" and the diff family show a submodule as modified.
When set to "all", it will never be considered modified (but it will nonetheless show up in the output of status and commit when it has been staged).

3
  • Looks like it works for vanilla git, but not for gitkraken. Well, kinda. I can stash using git and unstash using gitkraken. I can also stash using gitkraken and unstash using git. Now it only causes issues when I both stash and unstash using gitkraken. I guess its a bug in gitkraken.
    – HubertNNN
    Commented May 18, 2022 at 12:19
  • Also for anyone having the same issue. You put the config line in your .git/config file under [submodule "<name>"] as ignore = all. Setting submodule.<name>.ignore = all under [core] will not work.
    – HubertNNN
    Commented May 18, 2022 at 12:21
  • @HubertNNN a git config submodule.<name>.ignore all should work and generate the same syntax you mention in .git/config.
    – VonC
    Commented May 18, 2022 at 16:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.