How to do "go get" on a specific tag of a github repository
It is not possible using the go get
tool. Instead you need to use a third party go package management tool or create your own forks for the packages that you wish to manage more fine grained.
Spoke to a guy that works at Google and he acknowledged this problem/requirement, he said that vendoring which his team used was bulky and they will probably solve it with the official tools soon.
Read more:
- Reference of third party package management tools
- Blog post by golang team discussing the approach for implementing vendoring
Vendoring in Go 1.6
Vendoring has been released from experimental in go 1.6 (after this post was initially written) that makes the process of using specific tags / versions of packages using third party tools easier. go get
does still not have the functionality to fetch specific tags or versions.
More about how vendoring works: Understanding and using the vendor folder
Modules in Go 1.11
Go 1.11 has released an experimental features called modules to improve dependency management, they hope to release it as stable in Go 1.12: Information about modules in Go 1.11
go mod
is available now.
For those who need to build a binary of a specific tag, here is my way:
mkdir temp
cd temp
go mod init local/build # or `go mod init .` before go 1.13
go get -d -v github.com/nsqio/[email protected]
mkdir bin
go build -o bin/nsqd.exe github.com/nsqio/nsq/apps/nsqd
Explanation:
- The above code pulls NSQ v1.1.0 and build
nsqd
. go mod init .
creates ago.mod
file in the current directory, which enables usinggo get
with revision/tags. (see this link)-d
means "download only", if you want a direct installation, omit this flag and the build commands below this line.-v
means "be verbose".- The above code is for Windows. If you use Linux, replace
bin/nsqd.exe
withbin/nsqd
.
The module downloaded is stored in %GOPATH%\pkg\mod
. If you don't want to pollute your GOPATH
directory, make a new one and set your GOPATH
to it.