Home >Backend Development >Golang >How to Use `go get` or `go dep` with Private GitLab Subgroups?
Using 'go get' or 'go dep' with GitLab Subgroups
When attempting to retrieve dependencies from a private GitLab repository using 'go get' or 'go dep', you may encounter an error indicating that the remote repository is inaccessible. This issue is due to security measures implemented for private repositories on GitLab.
According to the GitLab support tracker, the recommended solution is to explicitly include .git in the URL when using 'go get' or 'go dep'. However, a more comprehensive solution that addresses both dependency managers and modern Go modules is to leverage 'go get's' support for .netrc.
Step-by-Step Solution:
Create a Personal Access Token on GitLab:
Create a ~/.netrc File:
Add the following content to the file:
machine gitlab.com login <your gitlab username> password <the token created in step 1>
Protect the .netrc File:
Use the following command to restrict access:
chmod 600 ~/.netrc
Usage:
After completing these steps, you should be able to successfully retrieve dependencies using either 'go get' or 'go dep':
Using 'go get':
go get gitlab.com/<company>/<subgroup>/<project>
Using 'go dep':
dep ensure -add gitlab.com/<company>/<subgroup>/<project>
Note:
If you are using a private GitLab installation, replace gitlab.com with the appropriate hostname in the provided commands.
The above is the detailed content of How to Use `go get` or `go dep` with Private GitLab Subgroups?. For more information, please follow other related articles on the PHP Chinese website!