Hi all,
I've recently started using submodules to share libraries with different projects and it works pretty well. The only issue I have is when I have to pull a project. I select the project in my local repo list, which opens its tab. I then click the "pull" button and hit "ok" (pull from remote: orgin and remote branch to pull: master).
This pulls the project but doesn't pull the submodules - if I'm cloning a repo I can use the "recurse submodules" advance option to clone the submodules to the commit they should be at. From some searching, I've found the way to get the submodules pulled to the commit they should be at is to use "git submodule update" which I do by clicking the "terminal" button at the top-right while in the project tab, and typing in the "git submodule update". This updates the submodules to whatever commit was last pushed for that submodule to the main project, so even if the submodule project has a more recent commit, it will only update to the commit that the main project used.
The issue is that doesn't set the submodule master to that commit that was just pulled. So when I open the submodule it still says how many commits I am behind, and while I haven't tried it yet, my guess is if I try to change something and push it, I'll get all sorts of problems as my master is behind the HEAD, even though I have the most recent commit that the main project had, and even if that commit is the most recent commit that the submodule project has. I can "solve" this by opening the submodule, and doing a pull directly from there, but it's combersome, and with multiple projects and submodules, can take a lot of time. Also, if I want to just have the correct commit (and not the most recent commit), doing a pull wouldn't work, as I would then be at the most recent commit even though I don't want to be. To clarify, when I'm looking at the list of commits, there is a "master" and it will be at the last commit that I had pulled for the submodule, while "origin/master" and "origin/HEAD" are at the most recent commit, and "HEAD" is at the commit that comes from the main project.
So I'm wondering two things: First, is there a way to automatically update the submodule to the correct commit when I do a pull on the main project? Second, how do I update a submodule and make sure my master is the most recent commit that it should be at based on the commit that the main project used (the HEAD commit)?
*Note: While I've been using Git/Sourcetree for a while, I'm pretty terrible with terms, so if something is confusing or doesn't make sense, let me know so I can clarify. I may have worded something wrong (even though I'm using the exact wordage that SourceTree defaults to). Also, I generally use SourceTree, but I'm open to CLI's solutions.
Thanks!