git配置私有仓库
1、mod使用私有仓库的包
Golang go mod 环境变量配置:
- 第一次配置go环境
go env -w GOROOT=(系统环境配置时对应的路径)
go env -w GOPATH=(系统环境配置时对应的路径)
go env -w GOPROXY=https://goproxy.cn,direct,https://mirrors.aliyun.com
- 设置 go mod 环境变量
windows:
set GO111MODULE=on
set GOPROXY=https://goproxy.cn,direct
set GOPRIVATE=gitlab2.aishu.cn
linux:
export GO111MODULE=on
export GOPROXY=https://goproxy.cn,direct
export GOPRIVATE=gitlab.aishu.cn //私有仓库
- 创建gitlab账号
- 本地配置git用户.gitconfig
git config --global user.name "your name"
git config --global user.email "you email"
git config --global url."git@gitlab2.aishu.cn:".instandOf "https://gitlab2.aishu.cn/" (私有仓库地址)
改配置是指将https://gitlab2.aishu.cn/替换为git@gitlab2.aishu.cn:
cat ~/.gitconfig
可查看配置
- 创建公钥,这个公钥添加到github上后,才能下载里面项目的代码的
ssh-keygen -C "your email" -t rsa
创建的公钥会在cat ~/.ssh/id_rsa.pub
,添加公钥到github
- 设置账户信息
- gitlab2.aishu.cn访问令牌创建, 创建后产生token密钥
windows:
在c:\Users\<username>目录下,创建_netrc文件,写入信息: `machine gitlab2.aishu.cn login Wenqiang.liu(git登录用户名称) password sdfwe23edd32(git登录用户token,上一步生成的)`
linux:
[root]# echo 'machine gitlab2.aishu.cn login Wenqiang.liu(git登录用户名称) password sdfwe23edd32(git登录用户token,上一步生成的)' > ~/.netrc
-
克隆私有仓库代码
-
初始化go mod
go mod init <项目名> go mod tidy
-
go get
安装想要的分支[root]# go get <path-to-repo>@<branch>
branch可以是分支最后一次提交的哈希值