How to get another branch instead of default branch with go get

Stable HEAD philosophy

It is not possible with pure go get.

Go takes the most minimal and pragmatic approach of any package manager. There is no such thing as multiple versions of a Go package.

But this is not as bad as it seems at the first view because there exists a philosophy behind this behavior.

As a package author, you must adhere to the stable HEAD philosophy. Your default branch must always be the stable, released version of your package. You must do work in feature branches and only merge when ready to release.

This approach is forced by go get limitations and it should be treated like Python indentations - it is kind of philosophy forced by language design.

Development approaches

If you want to fork something or try new features you can clone repo then switch to a desired branch and do go build. This way shouldn't go to production.

git clone <repo name>
cd <repo name>
git checkout <branch name>
go build

Also you can use third party package management tools. But most of them support tags and revisions, not branches (since it is implied that you don't need to install feature branch).

gpm:

You can specify packages with the format, where version can be a revision number (a git/bazaar/mercurial/svn revision hash) or a tag.


Starting with Go 1.11, this is possible when using Go modules. When installing a dependency for a Go module, you can specify a module query which may contain a branch or tag name:

$ go get <path-to-repo>@<branch>

Tags:

Git

Github

Go