

Note, while the modern form of updating submodule commits would be: git submodule update -recursive -remote -force I have a script running this in a Jenkins job that chains to a scheduled automated deployment afterwards, and it works like a charm. This commit will be ignored by default, if nothing was done. This list of relative submodule paths is captured in an array ( $(.)) - finally iterate this and do git add $i to update the parent repository.įinally, a commit with some message explaining that the parent repository was updated. Using 'echo $path' (must be in single-quotes), the path to the submodule gets written to output. Iterate all submodules - with -quiet, which removes the 'Entering MODULE_PATH' output.

My favourite part: for i in $(git submodule foreach -quiet 'echo $path') To make this work, everything in the iteration must be wrapped in the double-quotes and the Git commands are wrapped in parentheses (operator precedence). Again, it only happens if a pull actually brought in new stuff.įinally, the final || true is ensuring that script continues on errors. Notice a few things: First of all, I'm chaining some Git commands using & - meaning previous command must execute without error.Īfter a possible successful pull (if new stuff was found on the remote), I do a push to ensure that a possible merge-commit is not left behind on the client. Then I update/pull all submodules: git submodule foreach "(git checkout $BRANCH & git pull -ff origin $BRANCH & git push origin $BRANCH) || true" Then some submodule initializing, might be necessary, if new submodules have been added or are not initialized yet: git submodule sync git checkout $BRANCH & git pull -ff origin $BRANCH Then I pull the parent repository's latest stuff (I prefer to use -ff (fast-forwarding) whenever I'm just doing pulls. The first couple of sections is some checking that the arguments are there.
Gitkraken submodules free#
Feel free to make this even more complex. To run it, execute git-update-submodules.sh /path/to/base/repo BRANCH_NAMEįirst of all, I assume that the branch with name $BRANCH (second argument) exists in all repositories. Git commit -m "Updated $BRANCH branch of deployment repo to point to latest head of submodules" Git submodule foreach "(git checkout $BRANCH & git pull -ff origin $BRANCH & git push origin $BRANCH) || true"įor i in $(git submodule foreach -quiet 'echo $path') Git checkout $BRANCH & git pull -ff origin $BRANCH It would be cool to have an automated iteration through each submodule, updating the parent repository pointer (using git add) to point to the head of the submodule(s).Įcho "Missing 1st argument: should be path to folder of a git repo" Įcho "Missing 2nd argument (branch name)" a script to update the parent repository's commit pointers. Not very practical, since you would have to hardcode n paths to all n submodules in e.g.

This would be done by git submodule foreach git pull origin BRANCH New stuff has happened in one or more submodules, and I want to 1) pull these changes and 2) update the parent repository to point to the HEAD (latest) commit of this/these submodules. Scenario 2, which I think is what OP is aiming at This is, as pointed out, done with git submodule foreach git pull origin BRANCH Using my parent repository's pointers to submodules, I want to check out the commit in each submodule that the parent repository is pointing to, possibly after first iterating through all submodules and updating/pulling these from remote. It seems like two different scenarios are being mixed together in this discussion: Thus far I've just been rm-ing the module and re-adding it, but this is both wrong in principle and tedious in practice.

I've also tried git fetch mod, which appears to do a fetch (but can't possibly, because it's not prompting for a password!), but git log and git show deny the existence of new commits. Nothing to commit (working directory clean) Submodule 'mod' registered for path 'mod' # At this point, changes submodule needs to change too. Hello world.Ģ files changed, 4 insertions(+), 0 deletions(-) Remote: Total 131 (delta 54), reused 0 (delta 0) Initialized empty Git repository in /./foo/.git/ It doesn't do anything (no output, success exit code). Now, my understanding is that git submodule update should do this, but it doesn't. Commit B has been pushed to that URL, and I want the submodule to retrieve the commit, and change to it.
