Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git post-commit hooks

I've got two git project repos that have two or three files in common.

Something like this:

Project A ------> helper_functions

Project B ------> helper_functions

I'm wondering if there's an accepted method to "share" these common helper files between the repos, so that I don't have to maintain separate copies in both repos.

Would something like a post commit hook that would update the helper_functions in Project B when the helper_functions from Project A are updated? Or is there a more seamless method for ensuring both projects have the latest and greatest version of the helper_functions file and that the file automatically gets included in any package of the project?

Thanks for any ideas or resources on an accepted way to deal with this.

Also, I wanted to add that both of these projects have collaborators, so it would ideally be automatic, so we're all on the same page without having to use soft links or aliases.

like image 610
julio Avatar asked Nov 26 '25 21:11

julio


1 Answers

Some people might say this is overkill for just a few files, but to me this sounds like a good case for using git's support for submodules. Basically, you would create a new repository called helper_functions, and add that to each of the existing repositories as a submodule with:

git submodule add git://foo/bar/helper_functions.git helper_functions

There are a few subtleties to do with working with submodules, however, so it would be worth doing some reading first. I like the description in the git manual as a starting point, but there are plenty of other nice explanations, e.g. that from Pro Git.

I wouldn't create hooks to commit and push the submodule, however - I think it's better to carefully consider when you want to update the version of the submodule that's committed in the main repository. What I have found quite useful, though, is to use a commit-submodule script that makes sure you push your submodule changes before committing a new submodule version in the repository.

like image 178
Mark Longair Avatar answered Nov 28 '25 10:11

Mark Longair



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!