Confused by Git Submodule

I created two repos on GitHub

I added submodule_actions_sub to submodule_actions via git submodule add like following


I thought when I update submodule_actions_sub in its repo, submodule_actions will be changed too, at least the tree point (the red line in the above image) will be updated, but it doesn’t, why?

BTW, if I am not wrong, it worked as I think about three years ago.

Thank you.

A submodule is recorded with a specific commit, it will always point to that commit until you update it. If you pull in the submodule directory you’ll get updates like for any other repository. The changed commit of the submodule will be shown as a change in the surrounding repository, and you can commit that like any other change.

@airtower-luna I see, thank you so much.

BTW, is there a way to automatically update the main repo when the submodule is updated in git?

1 Like

Not in Git, no. The point is to prevent unexpected changes. Of course you can automate it if you need that, whether locally (e.g. a script that pulls all submodules and shows you the diff, so you can commit if you want) or fully automated e.g. using an Actions workflow.

Thank you. I think I will use GitHub Actions.

1 Like