Using forked package import in Go


Suppose you have a repository at and you fork it to You want to use your fork instead of the main repo, so you do a

go get

Now all the import paths in this repo will be “broken”, meaning, if there are multiple packages in the repository that reference each other via absolute URLs, they will reference the source, not the fork.

Is there a better way as cloning it manually into the right path?

git clone $GOPATH/src/


If you are using go modules. You could use replace directive

The replace directive allows you to supply another import path that might
be another module located in VCS (GitHub or elsewhere), or on your
local filesystem with a relative or absolute file path. The new import
path from the replace directive is used without needing to update the
import paths in the actual source code.

So you could do below in your go.mod file

module some-project

go 1.12

require ( v1.20.0

replace => v3.2.1

where v3.2.1 is tag on your repo. Also can be done through CLI

go mod edit -replace=""

Answered By – Yogesh

Answer Checked By – Terry (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.