DEV Community

Cover image for Go: Using fork module
anasrin
anasrin

Posted on • Originally published at anasrin.vercel.app

Go: Using fork module

Why ?

When you are using a Go module and encounter a bug, you may try to fix it by forking the repository and sending a pull request. However, the merge or release tag might not be immediately available, and you still need to use the module.

Here is how you can use the forked module: After forking the repository and committing the bug fix, you can run the following command:

go mod edit -replace github.com/someuser/repo=github.com/yourusername/repo@branch
Enter fullscreen mode Exit fullscreen mode

This command will add the following code to your go.mod file:

replace github.com/someuser/repo => github.com/yourusername/repo branch
Enter fullscreen mode Exit fullscreen mode

Now, you just need to run the following command to download the module:

go mod download
Enter fullscreen mode Exit fullscreen mode

If you take a look at your go.mod file, you will see that the branch has been changed to tag-(time commit)-(hash commit).

replace github.com/someuser/repo => github.com/yourusername/repo v0.0.0-(time commit)-(hash commit)
Enter fullscreen mode Exit fullscreen mode

Whenever the pull request has been merged, you can feel free to remove the replace statement in the go.mod file and update the module.

References

Top comments (0)