https://go.dev/ref/mod#workspaces describes the current implementation of Go workspaces, as proposed by https://golang.org/issue/45713, which culminated in the proposal doc at https://go.googlesource.com/proposal/+/master/design/45713-workspace.md.
The proposal doc says:
go.work files should not be checked into version control repos containing modules so that the go.work file in a module does not end up overriding the configuration a user created themselves outside of the module. The go.work documentation should contain clear warnings about this.
However, the canonical documentation about go.work at https://go.dev/ref/mod#workspaces makes no mention of this, as far as I can see. In practice, it seems like the common knowledge among Go developers is that the file should never be checked in, because:
First, we should decide whether we actually want to recommend users to never check in go.work files, like the original proposal doc said. If that's the case, then we simply need to add that recommendation to the /ref/mod page.
However, if we don't want to make that general recommendation, then we need to figure out under what circumstances it is recommended or not to check in go.work into VCS. For example, here are some personal guesses of mine:
- For a VCS repository holding a Go library module intended for external use, checking in
go.work is likely a bad idea, as it prevents downstream users from easily setting up their own go.work in a parent directory.
- For large monorepos with multiple modules, it likely makes sense to check in
go.work, as it makes the setup easier and often has no downsides.
- In some cases,
go.work files will naturally live in the parent directory to the VCS clones, so they have no VCS repository to naturally be checked into at all.
cc @bcmills @marwan-at-work @matloob
https://go.dev/ref/mod#workspaces describes the current implementation of Go workspaces, as proposed by https://golang.org/issue/45713, which culminated in the proposal doc at https://go.googlesource.com/proposal/+/master/design/45713-workspace.md.
The proposal doc says:
However, the canonical documentation about
go.workat https://go.dev/ref/mod#workspaces makes no mention of this, as far as I can see. In practice, it seems like the common knowledge among Go developers is that the file should never be checked in, because:gitignoreincludes the file since Go: Ignore Go workspace file go.work github/gitignore#3884x/toolsdoes not include one, even though it has two modules connected by a directory replace directiveFirst, we should decide whether we actually want to recommend users to never check in
go.workfiles, like the original proposal doc said. If that's the case, then we simply need to add that recommendation to the/ref/modpage.However, if we don't want to make that general recommendation, then we need to figure out under what circumstances it is recommended or not to check in
go.workinto VCS. For example, here are some personal guesses of mine:go.workis likely a bad idea, as it prevents downstream users from easily setting up their owngo.workin a parent directory.go.work, as it makes the setup easier and often has no downsides.go.workfiles will naturally live in the parent directory to the VCS clones, so they have no VCS repository to naturally be checked into at all.cc @bcmills @marwan-at-work @matloob