Home >Backend Development >Golang >How to Use 'go get' to Fetch a Specific Git Branch?

How to Use 'go get' to Fetch a Specific Git Branch?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2025-01-05 06:52:40271browse

How to Use

How to Fetch a Specific Repository Branch with "Go Get"

In Go modules, you might encounter situations where you prefer fetching a specific branch, such as a development branch, from a dependency repository. The default behavior of "go get" is to obtain the master branch. However, you can override this default by utilizing the module query feature introduced in Go 1.11.

To retrieve a non-default branch from a dependency repository, follow this syntax:

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

For instance, if you wish to acquire the develop branch of repository repo_a within your repository repo_b, execute the following command:

$ go get github.com/repo_a@develop

This will fetch the develop branch of repo_a and allow you to utilize it within the current module of repo_b.

Remember, this approach is specific to Go modules and can only be employed if both repositories utilize the module system. Otherwise, alternative methods, such as direct repository cloning or vendor management, may be necessary.

The above is the detailed content of How to Use 'go get' to Fetch a Specific Git Branch?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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