Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: option to initialize go mod from git submodules #47824

mcandre opened this issue Aug 19, 2021 · 2 comments

cmd/go: option to initialize go mod from git submodules #47824

mcandre opened this issue Aug 19, 2021 · 2 comments
FeatureRequest GoCommand NeedsInvestigation


Copy link

@mcandre mcandre commented Aug 19, 2021


I have historically used git submodules as the most reliable way to manage library dependencies in my Go projects. I would very much like to migrate to modern Go modules. However, the go mod init system does not appear to support generating go.mod configurations from git submodules.

When I try to do this, I either get NO modules in the resulting go.mod file, or else I get the latest versions of everything, which of course breaks my application. Please include automation for migrating vendor/ directories from git submodules to go.mod.

Furthermore, when I try to explicitly copy the exact same git refs for the dependency versions, then go mod operations corrupt these. go mod checks out a completely different version of the dependency tree than I have in the original vendor/ with git submodules.

If someone can help me to reliably migrate the exact same dependency tree to go mod, then I would be grateful.


@mknyszek mknyszek changed the title Option to initialize go mod from git submodules cmd/go: option to initialize go mod from git submodules Aug 19, 2021
@mknyszek mknyszek added FeatureRequest GoCommand NeedsInvestigation labels Aug 19, 2021
@mknyszek mknyszek added this to the Backlog milestone Aug 19, 2021
Copy link

@mknyszek mknyszek commented Aug 19, 2021

CC @bcmills @matloob @jayconrod

Copy link

@jayconrod jayconrod commented Aug 20, 2021

Could you say more about how you're using submodules? Concepts in Go modules and Git submodules don't map directly to each other, so it's not clear to me how this would work or whether it would be feasible.

It sounds like you have submodules checked out into the vendor directory, presumably at locations that correspond to repository root paths. If that's the case, then git submodule status would show something like this for each repo:

012345abcdef vendor/

It's probably feasible for go mod init to list directories inside vendor containing .go files, find what submodule they belong to, then build a go.mod based on that. Does that sound about right?

We're probably not going to be able to get to this soon; I don't think many people are in this situation. In the mean time, you can simulate the result by using go get to pull in each dependency.

go get -d

@jayconrod jayconrod removed this from the Backlog milestone Aug 20, 2021
@jayconrod jayconrod added this to the Unplanned milestone Aug 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
FeatureRequest GoCommand NeedsInvestigation
None yet

No branches or pull requests

3 participants