Go Workspace

Developing two separate repos together using go.work.

Scenario: You have a bookmarks API and a shared library (gokit) in separate repos. You need to edit both at the same time.

projects/
├── go.work              ← NOT committed to version control
├── bookmarks/
│   ├── go.mod           ← module: github.com/yourname/bookmarks
│   └── main.go
└── gokit/
    ├── go.mod           ← module: github.com/yourname/gokit
    ├── errx/
    │   └── errx.go
    └── slogr/
        └── slogr.go

go.work file:

go 1.24

use (
    ./bookmarks
    ./gokit
)

Setup:

cd projects
go work init
go work use ./bookmarks ./gokit

bookmarks/go.mod stays clean — normal require, no replace:

module github.com/yourname/bookmarks

go 1.24

require github.com/yourname/gokit v0.2.0

The workspace silently redirects github.com/yourname/gokit to the local ./gokit directory. When done developing:

# Tag and push gokit
cd gokit && git tag v0.3.0 && git push --tags

# Update bookmarks to use the published version
cd ../bookmarks && go get github.com/yourname/[email protected]

# CI uses GOWORK=off to test against published versions
GOWORK=off go test ./...

💻 Run locally

Copy the code above and run it on your machine

© 2026 ByteLearn.dev. Free courses for developers. · Privacy