0

I faced with the following problem:

  • I forked a repo, and made some modifications to it under new branch
  • I create PR to upstream repo and it is not yet merged
  • I want to adjust my Go codebase to import the specific branch of my forked repo

The problem:

  • if the original repo is github.com/user/pkg/v3 then the forked repo appears as github.com/myusername/pkg
  • moreover, I made a new branch, e.g. mybranch where I made my fixes
  • in the code where I used original repo I have an entry in my go.mod file as github.com/user/pkg/v3 which I want to replace with specific branch of my forked repo

How should I correctly solve this issue?

What I see when I tried to change go.mod of my forked repo to be github.com/myusername/pkg/v3 and then call go get github.com/myusername/pkg@mybranch is the following

go: github.com/myusername/pkg/v3@vxx-xx-xx: parsing go.mod:
    module declares its path as: github.com/user/pkg/v3
            but was required as: github.com/myusername/pkg/v3
Valentin
  • 1,492
  • 3
  • 18
  • 27
  • 3
    Does this answer your question? [Using forked package import in Go](https://stackoverflow.com/questions/14323872/using-forked-package-import-in-go) – medasx Mar 28 '22 at 12:21
  • Not really, since version and tags are involved. I tried to use replace and I got the following error: ``` replace ... v1.0.1-xxxx invalid: go.mod has post-v1 module path .. at revision xyz ``` So, the replace will require proper tagging and handling the versions. So far I didn't find correct way to do that and seeking for information. – Valentin Mar 28 '22 at 12:45

1 Answers1

1

I found required solution. The trick was to perform the following series of steps:

  • fork original repo
  • create new branch
  • add modifications to the code
  • push branch into forked repo
  • tag this branch with version higher then original repo, e.g. if original repo had v3.1.1 then the tag I applied to my forked branch was v3.1.2
  • go to code which depends on this package
  • change go.mod file of my package to use replace directive and my new tag like this
replace github.com/user/pkg/v3 => github.com/myusername/pkg/v3 v3.1.2

Therefore, in order to use forked repo with new branch we must tag this branch in forked repo with version higher of the tag in upstream repo.

Valentin
  • 1,492
  • 3
  • 18
  • 27