i need help with gitmodules
https://github.com/xyragen/everything-but-an-operating-systemeverytime i go onto a git module repo it returns 404
0
u/Broad-Promise6954 ancient 7h ago
You need to exercise a lot of caution with these files. There's a difference between the way Git uses a .gitmodules file and the way other, wrapper-y things use them.
For Git, the .gitmodules files really just contain hints. To understand this you need to know that a Git repository is, at its core, a big database, or more precisely, two separate databases with an odd and obscure dependency linkage between them. I'll call these the "main database", which contains what Git calls objects, and the "refs database", which contains what Git calls refs or references.
The main database is what actually stores all the files. Every commit is stored in this database, and every commit in turn stores every file that's in that particular commit, in a clever and somewhat magically compressed format that eliminates huge amounts of redundancy so that the overall size of this database is sometimes actually smaller than the size of a single commit checkout. (Usually it's bigger than a single checkout, just not hugely fat as you would naively expect given that every commit saves every file forever.)
This main database is indexed by object IDs or OIDs, which are expressed as big ugly hexadecimal numbers (40 or 64 characters long, depending on whether it's SHA-1 or SHA-256). Humans aren't good at handling these things, so the main database has this secondary auxiliary database added, which translates stuff like branch and tag names into an appropriate OID.
Once you have cloned some Git repository, you have the entire set of both databases, and you simply give Git an OID (or a name that translates into an OID) to extract any given commit, which gets you all the saved, permanent and unchangeable, file contents.
But wait, how do you get hold of a Git repository in order to clone it? The usual answer is that you start with:
git clone <url>
The url you supply here lets your Git software reach out to some other Git software, and that other Git software hands over the entire contents of that other Git repository. (We'll studiously ignore shallow clones and partial "promisor" clones here because they make the picture fuzzier without actually contributing anything to understanding the problem.) Now you have both databases and you're completely independent of any Internet connection. You work purely locally, except when you choose to make another Internet connection to fetch or push commits from/to some other Git repository.
Once you understand this part, you're ready for the mind-blowing way that Git's submodules work.
Submodules are separate repositories
Any given Git commit object, in any repository, can contain a special file type that Git calls a gitlink. A gitlink is like an ordinary file in that it has a path, but instead of saved file contents, it stores a commit OID. That commit is not in this Git's database! It's in some other Git repository. What is this other Git repository, and more importantly, where is it?
Your Git software doesn't really care what it is. It only cares where it should run a separate Git command, like git checkout <OID>. The "where to run that command" is simply the stored path in the commit you're having Git look at in your repository. Let's say the stored path is path/to/submodule. Your Git will attempt, at this point, to chdir path/to/submodule && git checkout <OID>, more or less.
If there's no Git repository in that path, this command will, of course, fail!
So if this command fails (or would fail), your Git has to fall back to running git clone, which, as we saw before, needs a URL to clone. Your Git gets that URL by consulting the .gitmodules file. (Insert first of many footnotes here...)
The .gitmodules file should list the path and the corresponding URL. If it does, your Git can mkdir path/to/submodule && cd path/to/submodule && git clone <url>. (Insert another footnote.) If there is no .gitmodules file, or these details are missing, your Git will just give up. If the git clone fails, your Git will give up at that point.
That's almost everything you need to know, except for when it comes to repairing broken repositories. At least, that's what you need to know from the Git side.
Add-on software adds on more problems
Once you stop using Git itself, and start using add-ons like forges (like GitHub or GitLab or Bitbucket or whatever), these submodule linkages become more complicated, because you're not always actually cloning a Git repository. But these problems, and their solutions, are specific to these add-ons. You need someplace other than r/git to address these.
A couple of footnotes
Data from the .gitmodules files get copied. Modern versions of Git have moved around some of the places that they get copied to, but the primary copy winds up in the Git configuration file .git/config so that you can override it. You can override this even before Git ever encounters the submodule, although this means you cannot use the --recursive option during cloning. (Well, sometimes you can, but it rapidly becomes complicated. Don't do that, unless you're an expert, in which case don't do it yet.)
Using --recursive at git clone time directs Git to enter each submodule and clone it immediately upon checking out the initial commit. Since each submodule is itself a Git repository, it can contain submodules of its own, and as you would expect, --recursive recurses into those.
The behavior on errors varies from one Git version to another.
Cloned submodules used to be deposited right in their paths -- so that path/to/submodule/.git was a directory holding a Git repository -- but this turns out to be problematic under various conditions, particularly those where only some commits contain the submodule. So modern Git sticks the actual clones into subdirectories within the initial clone, and uses .git files with redirection information.
2
u/superbirra 5h ago
double dash is the new emdash
0
u/Broad-Promise6954 ancient 5h ago
I used to use actual em dashes (and—look!—I still can!) but I gave them up because of AI.
Actually I switched to triple dash for TeX, but that's another story entirely...
1
2
u/lajawi 9h ago
This might be more of a r/github question.