go install of forked repo

1,154 views
Skip to first unread message

Duncan Harris

unread,
Dec 3, 2022, 6:55:08 AM12/3/22
to golang-nuts
This seems a noddy question but can't easily find an answer with Google apparently. I may have lost the plot :-)

There is a repo which contains source for a go executable that I want to use.
Normally I install this with: go install original.domain/path@latest
I want to fork that repo and make some experimental changes.
So then I want to: go install my.forked.domain/path@commit
But if I don't also change the go.mod file in my fork I get something like:

go: downloading my.forked.domain/path v0.0.0-20221203102529-commit
go: my.forked.domain/path@commit: my.forked.domain/pa...@v0.0.0-20221203102529-commit: parsing go.mod:
    module declares its path as: 
original.domain/path
            but was required as: my.forked.domain/path

Obviously I could change the go.mod in my fork, but that seems wrong if I later want to submit a PR on the original repo.

Steven Hartland

unread,
Dec 3, 2022, 7:14:14 AM12/3/22
to Duncan Harris, golang-nuts
Check out go work I achieve it’s exactly what you are looking for, allowing for projects to use temporary local versions of packages 

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/9a9542bd-1718-4ea7-a0ed-42b343bb9699n%40googlegroups.com.

Sean Liao

unread,
Dec 3, 2022, 2:30:46 PM12/3/22
to golang-nuts
`go install pkg@version` doesn't support installing from a fork.

The argument is best understood as a module identity rather than source code location.

- sean

Volker Dobler

unread,
Dec 4, 2022, 7:17:20 AM12/4/22
to golang-nuts
You cannot use a "fork". The Github concept of a "fork" doesn't
work together with the concept of a Go module.
You are free to fork a repo and you can modify the source
after git cloning your "fork" you even can build the "fork" and
go install it's binaries by simply running go install inside
of the "fork". But your "fork" just remains a Github-fork,
it's not a software fork of the original module. For that you
have to rename it. Forks in Go cannot (for reasonable definition
of cannot) have the the same name as the original.

V.

Robert Engels

unread,
Dec 4, 2022, 9:13:46 AM12/4/22
to Volker Dobler, golang-nuts
Can’t you use a replace directive to use the fork ?

On Dec 4, 2022, at 6:17 AM, Volker Dobler <dr.volke...@gmail.com> wrote:

You cannot use a "fork". The Github concept of a "fork" doesn't
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.

Volker Dobler

unread,
Dec 5, 2022, 2:39:55 AM12/5/22
to golang-nuts
On Sunday, 4 December 2022 at 15:13:46 UTC+1 ren...@ix.netcom.com wrote:
Can’t you use a replace directive to use the fork ?

No, not in the general case.

V.

Christian Stewart

unread,
Dec 5, 2022, 2:48:20 AM12/5/22
to Volker Dobler, golang-nuts
I definitely fork things and use "replace" quite frequently.

When forking something you have to tell Go where to find it, that's
what "replace" is for.

There's a issue about using replaces in `go install` without a go.mod:

https://github.com/golang/go/issues/44840
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/2d404195-2a47-47e9-98f8-273e8159426fn%40googlegroups.com.

Dan Kortschak

unread,
Dec 5, 2022, 3:52:17 AM12/5/22
to golan...@googlegroups.com
On Sun, 2022-12-04 at 23:47 -0800, 'Christian Stewart' via golang-nuts
wrote:
> I definitely fork things and use "replace" quite frequently.

It *can* be used, but it is not the solution in the general case as
Volker said. A replace in a library's go.mod file has no effect on
consumers of that library.

https://go.dev/ref/mod#go-mod-file-replace:

> replace directives only apply in the main module’s go.mod file and
are ignored in other modules. See Minimal version selection for
details.

Stéphane Jeandeaux

unread,
Dec 5, 2022, 4:16:24 AM12/5/22
to golang-nuts
Hi, 

If you don't want to commit go.mod, you can use go.work https://go.dev/ref/mod#go-work-file

Brian Candler

unread,
Dec 5, 2022, 6:32:35 AM12/5/22
to golang-nuts
Or there is vendoring.

Robert Engels

unread,
Dec 5, 2022, 7:09:13 AM12/5/22
to Brian Candler, golang-nuts
As I mentioned in the other thread - isn’t that made more complicated because the module author (the module that is imported) doesnt use relative packages references? If they did wouldn’t this be simpler?

On Dec 5, 2022, at 5:32 AM, Brian Candler <b.ca...@pobox.com> wrote:

Or there is vendoring.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.

ged...@gmail.com

unread,
May 3, 2023, 8:55:57 AM5/3/23
to golang-nuts
the original question was to do it from anywhere. that's also what i would like to do..

go install from anywhere... Not when you in a project with a go.work or go.mod etc etc

It's a pain that this is not supported.

Reply all
Reply to author
Forward
0 new messages