DEV Community

Alex Rios
Alex Rios

Posted on

How to use your private Go lib in Github Actions

In this tutorial I'll use the fictional private repository called at the version v1.1.0

Backing story

During the Continuous integration pipeline executing go mod tidy I was getting this error:

go: reading at revision v1.1.0: unknown revision v1.1.0
Enter fullscreen mode Exit fullscreen mode


In order to understand how Go uses a VCS to handle dependencies I recommend this Go team blog post:


Generate a token with read permission on org or user repositories and setup a substitution in git global configurations.

That way the authenticated form will always be used.

I highly recommend you to use the repository secrets to avoid exposing sensible data, in this case, the token.

- name: Granting private modules access
        run: |
          git config --global url."https://${{ secrets.GO_MODULES_TOKEN }}".insteadOf ""     
Enter fullscreen mode Exit fullscreen mode

more on declaring and using secrets:

Top comments (4)

renanbastos93 profile image

Hey dude, thanks a lot you safe my life, nice article.

stardustman profile image


br3nda profile image
Shiny • Edited

what kind of token is GO_MODULES_TOKEN

alextrending profile image
Alex Rios

It could be any token that grants you the access. Eg.: