Go CLI Modules and Workspaces/Add replace directive

Point a module dependency to a local checkout.

Section: Editing and Replacements

Add replace directive

bash
bash
go mod edit -replace example.com/lib=../lib
Explanation

Point a module dependency to a local checkout. 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 Editing and Replacements
Add require directive
Add an explicit module requirement.
OpenIn sheetbashsame section
Set go line
Set the minimum Go version in go.mod.
OpenIn sheetbashsame section
Vendor dependencies
Copy dependencies into a vendor directory.
OpenIn sheetbashsame section
Inspect current module JSON
Inspect current module metadata.
OpenIn sheetbashsame section
Initialize module
Create a new go.mod for the current project.
OpenIn sheetbash2 tag match
Tidy dependencies
Add missing and remove unused module requirements.
OpenIn sheetbash2 tag match