Yusuke Hatanaka

September 4, 2024

TIL: using forked repository in my Go package

I wanted to use my forked repository not to change original package name.
In my case is that I wanted to debug authentication process for Google Cloud from AWS environment by using Workload Identity Pool.
I forked https://github.com/googleapis/google-cloud-go into https://github.com/hatajoe/google-cloud-go, but I wasn't sure how I import hatajoe/google-cloud-go without changing original package name.

Here is the answer.
  1. fork repository
  2. make some changes
  3. create and push tag
  4. go mod edit
  5. go mod tidy

At the first, fork repository.
Make some changes you need. This time I put some logging code on some files.
Push the branch, and create and push tag.

% git push -u origin debug
% git tag auth/v0.0.1
% git push --tag

This is the point. This time I wanted to make changes in cloud.google.com/go/auth package only.
So I needed to create tag in form of auth/v0.0.1 instead of v0.0.1.
Next, edit go.mod file.

% go mod edit -replace cloud.google.com/go/auth@v0.9.1=github.com/hatajoe/cloud.google.com/go/auth@v0.0.1

Or edit go.mod yourself like following:

+replace cloud.google.com/go/auth v0.9.1 => github.com/hatajoe/google-cloud-go/auth v0.0.1 

And execute go mod tidy then finished.

About Yusuke Hatanaka

I'm working as a software engineer in Japan. I like reading, watching basketball game, and fishing. 
Not only the fact oriented but also intuition.