# submodules

2 messages from 2014-01-23 to 2014-01-23. Participants: shawn wilson, W. Trevor King.
Thread: https://gitlist.dev/t/35722

## shawn wilson, 2014-01-23 08:38

Subject: submodules
Message-ID: <CAH_OBicG4bLWu_C=uF6bTzzdJP5SSZ=odQF-qsP4n+VvAN4nrQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAH_OBicG4bLWu_C%3DuF6bTzzdJP5SSZ%3DodQF-qsP4n%2BVvAN4nrQ%40mail.gmail.com

```
I've got a git repo that just contains a bunch of small projects
(scripts, configs, etc). The idea was (is) to make it so that each
project is tracked seperately (different branches, not needing to
filter out logs for unrelated commits). And it works great for that.
The problem is that I guess I don't know how to manage it and keep
stumbling and tripping over myself here.

My issue is in trying to update the submodules, I'm getting:
 % git submodule update --init
                                                gits/kt (master ⚡)
swlap1
fatal: reference is not a tree: 98f1e9f99fca32ab3de901219eb2f600d38ab3a5
Unable to checkout '98f1e9f99fca32ab3de901219eb2f600d38ab3a5' in
submodule path 'repo_a'

Ok, so a bit of googling and I found this:
http://stackoverflow.com/questions/13425298/git-submodule-update-fatal-error-reference-is-not-a-tree
Ok, so update the repo that contains the submodules every time you
push from a sub repo? How / where do I create a hook to do this?

And then:
http://stackoverflow.com/questions/2155887/git-submodule-head-reference-is-not-a-tree-error
So, the first example didn't really work:
 % cd repo_a
                                            gits/kt (master ⚡) swlap1
 % git checkout 98f1e9
                                              kt/repo_a (master)
swlap1
error: pathspec '98f1e9' did not match any file(s) known to git.

So, at this point I realized I have pushed from two repos (maybe
others have as well) and not updated the repo of submodules. So, as
long as the issue is just with this one repo, I'm ok with loosing a
little data (not much has changed in a while and maybe I'll go and
find the blobs and merge them back in later). So I try the other
method:
 % git log --oneline -p -- repo_a
                                            gits/kt (master ⚡) swlap1
7911a1e Bump.
diff --git a/repo_a b/repo_a
index 206635e..98f1e9f 160000
--- a/repo_a
+++ b/repo_a
@@ -1 +1 @@
-Subproject commit 206635eed8b94e4133a7689b34a570e2fb0b6069
.......
 % git checkout d92f592- -- repo_a
                                            gits/kt (master ⚡) swlap1
fatal: invalid reference: d92f592-



So, (after this is solved) is there a post hook (not even sure where
such a thing would go) after pushing from a submodule repo (maybe a
concatination of commit messages or something) so that this stays in
sync and I never have to think about this again (though I think I'll
remember after winning this fight).

```

## W. Trevor King, 2014-01-23 17:20

Subject: Re: submodules
Message-ID: <20140123172014.GS29063@odin.tremily.us>
URL: https://gitlist.dev/e/20140123172014.GS29063%40odin.tremily.us
In-Reply-To: <CAH_OBicG4bLWu_C=uF6bTzzdJP5SSZ=odQF-qsP4n+VvAN4nrQ@mail.gmail.com>

```
On Thu, Jan 23, 2014 at 03:38:49AM -0500, shawn wilson wrote:
> My issue is in trying to update the submodules, I'm getting:
>  % git submodule update --init
>                                                 gits/kt (master ⚡)
> swlap1
> fatal: reference is not a tree: 98f1e9f99fca32ab3de901219eb2f600d38ab3a5
> Unable to checkout '98f1e9f99fca32ab3de901219eb2f600d38ab3a5' in
> submodule path 'repo_a'
> 
> Ok, so a bit of googling and I found this:
> http://stackoverflow.com/questions/13425298/git-submodule-update-fatal-error-reference-is-not-a-tree
> Ok, so update the repo that contains the submodules every time you
> push from a sub repo? How / where do I create a hook to do this?

You've got it switched.  You *did* push the superproject, but forgot
to push the new submodule commits that it references.  An easy way to
avoid this problem is to always push the superproject using:

  $ git push --recurse-submodules=on-demand …

If you no longer have access to the submodule repositories that
weren't pushed, you'll have to roll back the superproject so it
references submodule commits that were pushed.  The easiest way to do
this is probably to just cd into the submodule directory and checkout
an appropriate commit (e.g. origin/master):

  $ cd repo_a
  $ git fetch origin
  $ git checkout origin/master

That will put you on a detached HEAD, so you might want to replace the
checkout with:

  $ git checkout -B master origin/master

or some such to get a local branch.

Then cd back into the superproject and commit the submodule
(referencing the current submodule commit):

  $ cd ..
  $ git commit -m 'repo_a: Roll back to last public commit' repo_a

When you push that commit, don't forget to push everything ;)

  $ git push --recurse-submodules=on-demand

Cheers,
Trevor

-- 
This email may be signed or encrypted with GnuPG (http://www.gnupg.org).
For more information, see http://en.wikipedia.org/wiki/Pretty_Good_Privacy

```
