Home > Backend Development > Golang > How to Make `go get` Work with a Local Server Repository?

How to Make `go get` Work with a Local Server Repository?

DDD
Release: 2024-12-16 12:39:17
Original
899 people have browsed it

How to Make `go get` Work with a Local Server Repository?

How can I make go get work with a repo on a local server?

Go get doesn't work with repos on a local server by default. To make it work, you need to add the following line to your ~/.gitconfig file:

[url "<User>@<hostname>:<ssh-port>/<path-to-repo>.git"]
    insteadOf = https://<user>@<hostname>:<ssh-port>/<path-to-repo>.git
Copy after login

Replace with your username, with thehostname of your server, with the SSH port number, and with the path to the repo on your server.

For example, if your username is John Doe, your server's hostname is example.com, your SSH port number is 22, and your repo is located at /home/John Doe/my-repo, you would add the following line to your ~/.gitconfig file:

[url "John Doe@example.com:22/home/John Doe/my-repo.git"]
    insteadOf = https://John Doe@example.com:22/home/John Doe/my-repo.git
Copy after login

Once you have added this line to your ~/.gitconfig file, you should be able to use go get to fetch repos from your local server.

Example

To clone a repo from a local server with go get, you can use the following command:

go get git@<hostname>:<user>/<repo>.git
Copy after login

Replace with the hostname of your server, with your username, and with the name of the repo you want to clone.

For example, to clone the 'my-repo' repo from the 'example.com' server using the 'John Doe' user, you would use the following command:

go get git@example.com:John Doe/my-repo.git
Copy after login

This command will clone the 'my-repo' repo into the 'my-repo' directory in your GOPATH.

The above is the detailed content of How to Make `go get` Work with a Local Server Repository?. 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