How to Test Local Changes with Go Mod

Teiva Harsanyi
Aug 7, 2019 · 1 min read
Image for post
Image for post

We are developing on two different Go projects using modules:

  • A module
  • Another module that depends on the first one

Let’s say we made some changes to and we would like to test the impacts on before committing them.

Without Go modules, it was pretty straightforward as our changes were done in GOPATH so they were automatically reflected.

With Go modules, the trick is to replace our import by the physical location of the project:

Here, /path/to/local/bar is the actual location of the bar project containing the local changes.

We can also use the following command:

go mod edit -replace


Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store