Home > Backend Development > Golang > How Can I Use `go get` with Local Private Git Repositories?

How Can I Use `go get` with Local Private Git Repositories?

Patricia Arquette
Release: 2024-12-04 09:54:11
Original
460 people have browsed it

How Can I Use `go get` with Local Private Git Repositories?

Using Go Get for Local Server Repositories

Getting packages from a local server using go get can be challenging due to its expectation of HTTP-based repositories.

To resolve this issue:

For Packages (GOPATH Convention)

  1. Add the following to .gitconfig: git config --global url."user@host:".insteadOf "https://github.com/"
  2. Create git repositories on your private git server and use SSH public key access.
  3. Use go get with the suffix .git to retrieve packages: go get user@host:gitrepo/package/

For Modules

  1. Follow the steps above for packages.
  2. Set GOPRIVATE to specify the private repositories: go env -w GOPRIVATE=user@host/gitrepo/*
  3. Use go get with the suffix .git to retrieve modules: go get user@host/gitrepo/module/

Differences from Public Repositories

  • Modifying .gitconfig to use SSH for private repositories.
  • Adding .git suffix in go get for non-public repositories.
  • Ensuring the hostname has a dot (.) or using its IP address.

Notes

  • Go gets modules from the $GOPATH/pkg/mod directory.
  • Semantic versioning is done with tags, which are independent of branches.
  • To get the latest commit on a branch, use @branchname in go get, e.g. go get user@host/gitrepo/module/branchname

The above is the detailed content of How Can I Use `go get` with Local Private Git Repositories?. 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