1

I have a project in Git which uses mySQL as a submodule. What I'd like to do is update my local tree on all my computers with the changes I made on one of them inside my local copy of mysql tree. Is there a nice clean way to do that?

Trying to google I only saw posts asking about populating changes in submodules in the upstrem. I don't want to do that - I don't have right to do that and I don't need to.

When I'm working on my code all I do is:

git add . && git commit -m "Message" && git push

Will this be enough when going to the submodule directory and performing this command?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Igor
  • 5,620
  • 11
  • 51
  • 103
  • https://stackoverflow.com/a/57485804/7976758 Found in https://stackoverflow.com/search?q=%5Bgit-submodules%5D+local+changes – phd Dec 19 '22 at 07:57
  • @phd, that is NOT the question I'm asking. He wants to update repo B - I want to update repo A and pull those changes everywhere on my machines. – Igor Dec 19 '22 at 13:25
  • First let me remind — submodules are separate repositories; you cannot integrate changes in submodules into superproject. The solution is to fork the submodule. You fork mysql; make changes; add, commit, push the changes to your forked repo. Switch the superproject to the forked submodule; add, commit, push the submodule. Now any clone or pull in any copy of the superproject will fetch your changes in the mysql submodule. Isn't it what you want? – phd Dec 19 '22 at 13:38
  • When you will need to update from the original repository — add another remote (usually called `upstream`) to your fork. `git pull upstream && git push origin && cd ../superprject && git add mysql && git commit && git push` – phd Dec 19 '22 at 13:40
  • Let me ask a question taking into account [your comment](https://stackoverflow.com/questions/74847464/how-to-push-submodule-changes-to-the-local-repo?noredirect=1#comment132096267_74847654). You don't want to change mysql sources, you just want to compile from the pristine sources and commit the binaries to the superproject to distribute to all repositories? In that case you don't submodules at all. Submodules required when you need something during development. In your case you just clone 1 commit from mysql sources, compile, commit, push and remove the sources,. – phd Dec 19 '22 at 13:58
  • @phd, `you cannot integrate changes in submodules into superproject` - I'm not trying to. The flow is this. I have a git repo. Then in this repo I added the mySQL as a submodule. I updated it on all my machine. So far so good. Now, because I made some changes and build mySQL client (not server!), I want that library (mysqlclient) and the changes I made in order to build it on that machine, be populated on all other of my local machine. – Igor Dec 19 '22 at 17:05
  • First - I will not need to make that changes by hand and second - my own repository will not be out of date. It will maintain the mySQL library and the sources the way I did on that machine. – Igor Dec 19 '22 at 17:07
  • And I am not looking for pushing to the original mySQL repo. First - I don't have access and second - I will need a PR and my changes will need to be reviewed and approved. But I do want to keep that compiled mySQL client binaries in my own repository on all my machines. Because I built it on OSX and I also have Windows and Linux ones and want to keep that binary readily available. And of course the changes I made needs to be there as well. I hope I made myself clear. Let me know if you don't understand anything. – Igor Dec 19 '22 at 17:10
  • Then my [first comments](https://stackoverflow.com/questions/74847464/how-to-push-submodule-changes-to-the-local-repo?noredirect=1#comment132096620_74847464) must be extended but the idea stays — you need to fork mysql and use the fork as the `origin` remote for the submodule. On any change in mysql source doe you do `git pull upstream && make && git add . && git commit && git push origin && cd ../superprject && git add mysql && git commit && git push` – phd Dec 19 '22 at 17:23
  • @phd, ok, understood. Thx. Is it possible to switch it on the fly or I will have to redo that? – Igor Dec 19 '22 at 19:25
  • Can be switched anytime. A submodule is a separate repository even when inside a superproject so `cd mysql && git remote set-url origin URL-fork && git remote add upstream URL-mysql # or set-url if the remote was already added` and later you can do this again with any URLs. – phd Dec 19 '22 at 20:25

1 Answers1

0

update my local tree on all my computers with the changes

That means settings up a local webhook listener, which would listen to a push even on your MySQL repository (assuming you are the owner of that repository, or fork).

That local listener can then trigger a git pull from within the submodule folder of each of your local repositories, assuming said submodule was set up to follow a branch.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I am the owner if I understand correctly what you are talking about. I did add mySQL as submidule in my repo. But now, I compiled it on one machine and want to push the compiled folder to my repo. And then I expect to use `git pull` to update all my other machines. So all MY local repositories and MY remote one will be updated but not the actual mySQL repo. – Igor Dec 19 '22 at 13:21
  • "want to push the compiled folder to my repo": you do not push compiled item into a source control system like Git. "And then I expect to use git pull": no, the webhook listener is supposed to go into each of your local repo and do the git pull within their respective mysql submodule folder. – VonC Dec 19 '22 at 14:15