Go CLI Modules and Workspaces/Initialize workspace

Create a go.work file for multiple local modules.

Section: Workspaces

Initialize workspace

bash
bash
go work init
Explanation

Create a go.work file for multiple local modules. Useful in Go CLI workflows.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Workspaces
Add module to workspace
Add one or more modules to go.work.
OpenIn sheetbashsame section
Recursively add modules
Add modules under a tree recursively.
OpenIn sheetbashsame section
Print go.work JSON
Inspect go.work configuration as JSON.
OpenIn sheetbashsame section
Sync workspace build list
Sync workspace dependencies back to module go.mod files.
OpenIn sheetbashsame section
Initialize module
Create a new go.mod for the current project.
OpenIn sheetbash1 tag match
Add replace directive
Point a module dependency to a local checkout.
OpenIn sheetbash1 tag match