Home > Backend Development > Golang > How Can I Use `go get` to Retrieve a Specific Branch of a Go Module Dependency?

How Can I Use `go get` to Retrieve a Specific Branch of a Go Module Dependency?

Mary-Kate Olsen
Release: 2024-12-09 08:02:07
Original
711 people have browsed it

How Can I Use `go get` to Retrieve a Specific Branch of a Go Module Dependency?

Retrieving a Specific Branch Using Go Get

When using Go modules, you can retrieve a specific branch of a dependency rather than the default master branch.

To achieve this, you can utilize the go get command with a module query that includes the branch name. For instance:

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

In your scenario, you have two repositories, repo_a and repo_b, with repo_a imported into repo_b. To obtain the develop branch of repo_a instead of the master branch, you can execute the following command in repo_b:

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

This will install the develop branch of repo_a into your Go module.

Please note that this approach requires Go 1.11 or later, as support for specifying branches in module queries was introduced in that version.

The above is the detailed content of How Can I Use `go get` to Retrieve a Specific Branch of a Go Module Dependency?. 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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template