简体   繁体   中英

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

I have 2 repositories. Let say them repo_a and repo_b. I imported repo_a in repo_b

When I ran go get, it will get repo_a master branch. Is there any way to get develop branch using go get or another command from repo_b?

I do not want to git pull on each specific package (in this case repo_a)

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.

you can use gopkg.in , it will redirect to github.

There are two URL patterns supported:

gopkg.in/pkg.v3      → github.com/go-pkg/pkg (branch/tag v3, v3.N, or v3.N.M)
gopkg.in/user/pkg.v3 → github.com/user/pkg   (branch/tag v3, v3.N, or v3.N.M)

go get gopkg.in/pkg.v3 means go get github.com/go-pkg/pkg , but is branch or tag v3.* .

for more details, see here

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM