Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto-committing git submodule hash in super-project

When you commit in a git submodule, you need to go up to the super-project to do a second commit, which is the new hash of the submodule.

This is incredibly annoying, easy to forget and can cause all manner of problems if you don't do it.

What I want to do is:

  1. Commit the changes in my submodule
  2. Have the hash committed automatically in the super-project
  3. Have both the submodule and the super-project pushed to their remote-origin ('git push')

What's the best way to figure out if you're in a submodule, where the super-project is, etc and automate this?

Maybe some kind of post-commit hook in the submodule?

like image 544
Avleen Avatar asked Jan 06 '12 18:01

Avleen


Video Answer


1 Answers

Have you tried git-slave? This is exactly what it's designed to do.

You can also script that yourself. Be aware that there are 2 options on the git command itself that can help greatily: --work-tree and --git-dir. Using these you can act on any repo without leaving the current directory.

Then there is also git submodule foreach --recursive git push.

like image 151
Adam Dymitruk Avatar answered Oct 07 '22 01:10

Adam Dymitruk