Pages

Friday, April 28, 2023

Working with a forked repository in Golang

 Let say you have a project A that depends on an open-source library B:

A -> B

Now for your own need, you need to enhance library B in order to fit your need. So you fork it as B2:

B -> B2

 
While you're waiting for the maintainer of B to approve your PR, how do you configure your project A to make use of B2? Turns out it's pretty easy! Here's the step:

  1. Fork B as B2
  2. Clone B2 locally
  3. Open A's `go.mod` file, add the following line if you're doing local development
     
    replace github.com/Khan/genqlient => /Users/aharijanto/src/opensource/genqlient

    Or if you're doing remote development

    replace github.com/Khan/genqlient => github.com/dharijanto/genqclient@branch-name
     

Once your change made it to the original repository, simply remove the replace directive! Golang is just so sweet, isn't it? :)

Source:
https://stackoverflow.com/questions/72312460/how-to-replace-a-go-module-with-a-major-version-to-a-fork-master

No comments:

Post a Comment