Home > Backend Development > Golang > How Can I Use `go get` to Fetch Non-Default Branches in Go Modules?

How Can I Use `go get` to Fetch Non-Default Branches in Go Modules?

DDD
Release: 2024-12-14 05:19:10
Original
365 people have browsed it

How Can I Use `go get` to Fetch Non-Default Branches in Go Modules?

Acquiring Non-Default Branches in Go with go get

In a software development workflow involving multiple repositories, situations may arise where specific branches, rather than the default master branch, need to be retrieved. This question centers around accessing the develop branch of a dependency repository from within another repository.

Solution using Go Modules

With the advent of Go modules in Go 1.11, retrieving specific branches of dependencies became feasible. Go modules utilize module queries, which allow for the specification of branches or tags during dependency installation.

To retrieve the develop branch of a dependency repository named repo_a from within your own repository repo_b, simply include the branch name in the module query when executing go get:

$ go get <path-to-repo_a>@<branch-name>
Copy after login

For instance:

$ go get example.com/repo_a@develop
Copy after login

The above is the detailed content of How Can I Use `go get` to Fetch Non-Default Branches in Go Modules?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template