Point to local repo using
8 Sep 2021
What if you want to point a Go project at a Go module that you have cloned locally?
In this case, let's pretend I'm working on a project that import pgx. My go.mod looks like this:
module github.com/manniwood/iidy go 1.16 require github.com/jackc/pgx/v4 v4.11.0
Let's say I have git cloned pgx to my local dir
/home/mwood/PROJECTS/pgx and I'd rather include
that clone in my current project. I would change my project's
go.mod like so:
module github.com/manniwood/iidy go 1.16 replace github.com/jackc/pgx/v4 => /home/mwood/PROJECTS/pgx require github.com/jackc/pgx/v4 v4.11.0
Apparently this edit does not have to be done by hand!
$ go mod edit -replace github.com/jackc/pgx/v4=/home/mwood/PROJECTS/pgx