白日依山尽,黄河入海流。欲穷千里目,更上一层楼。 -- 唐·王之涣

gitlab http方式存储密码(含Mac)

1、优先配置 username

1
2
git config --global user.email "你的git的注册邮箱"
git config --global user.user"你的git用户名"

2、配置存储密码

官网参考文档 https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage

image-20221014163431858

1、默认是每次需要输入用户名和密码的

1
2
3
4
5
# 每次提示需要 用户名和密码
git clone http://gitlab.xxx.com/groupname/projectname.git

# 可以在URL中直接指定账号密码(不建议)
git clone http://your-gitname:your-gitpasswd@gitlab.xxx.com/groupname/projectname.git

2、配置cache,默认是15分钟,当然也可以指定缓存时间

1
2
git config --global credential.helper cache
git config --global credential.helper 'cache --timeout=3600'

3、store 方式存储,是文件的形式存储在磁盘上

1
2
# 这条命令会在用户目录生成 .git-credentials 文件
git config --global credential.helper store

4、如果使用的是Mac系统 那么使用 osxkeychain 存储

1
2
# Mac存储在keychain
git config --global credential.helper osxkeychain

5、特殊的Windows也可以使用一种叫做Git Credential Manager, 可以独立安装,或者是在 gitbash中继承

3、其他配置

1
2
3
4
5
6
7
8
9
# 1、移除ssh方式 (需要进入对应的项目目录下)
git remote rm origin

# 2、然后增加https
# URL中配置账号和密码(不建议)
git remote add origin http://yourname:password@git.oschina.net/name/project.git

# 使用本地存储的账号密码
git remote add origin http://git.oschina.net/name/project.git

如果觉得文章对你有用,请不吝点赞和关注公众号搜索 全栈运维 或者 DailyJobOps

个人博客 http://blog.colinspace.com/

知乎平台 https://www.zhihu.com/people/colin-31-49

CSDN平台 https://blog.csdn.net/eagle5063

简书平台 https://www.jianshu.com/u/6d793fbacc88