Skip to content

Instantly share code, notes, and snippets.

@lmllrjr
Last active February 9, 2023 12:46
Show Gist options
  • Save lmllrjr/a4fa3a9ec77026a9d7cb65b3a81191fb to your computer and use it in GitHub Desktop.
Save lmllrjr/a4fa3a9ec77026a9d7cb65b3a81191fb to your computer and use it in GitHub Desktop.
Import a specific branch of a forked repo into Go code
module github.com/<username>/<reponame>
go 1.19
require (
github.com/<username>/pkg v0.7.0
)
// Order will matter here
replace github.com/<username>/pkg v0.7.0 => github.com/<username>/pkg v0.7.1
  • Create a fork of the original repo
  • Create a 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 v0.7.0 then the tag v0.7.1 should be applied to the forked branch
    git tag -a v0.7.1
    git push origin v0.7.1
    
  • Change go.mod file of my package to use replace directive and my new tag like in the following go.mod example:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment