一、克隆的时候直接保存用户名密码

可以克隆git存储库,并在命令中指定用户名和密码,推送的时候就不需要输入用户名密码了。
例:
git clone https://用户名:密码@localhost:1080/mdm.git

[root@LXCL-Web config-server]# git clone http://mdm:mdm123@localhost:1080/mdm.git
正克隆到 'mdm'...
remote: Counting objects: 127, done.
remote: Compressing objects: 100% (122/122), done.
remote: Total 127 (delta 57), reused 0 (delta 0)
接收对象中: 100% (127/127), 15.16 KiB | 0 bytes/s, done.
处理 delta 中: 100% (57/57), done.
[root@LXCL-Web config-server]# 

信息存储查看:cat mdm/.git/config和git config --list

[root@LXCL-Web config-server]# cat mdm/.git/config
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = http://mdm:mdm123@localhost:1080/mdm.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master

[root@LXCL-Web mdm]# git config --list
user.name=mdm
user.email=mdm@example.com
push.default=simple
##credential.helper=store
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=http://mdm@localhost:1080/mdm.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master

二、后期解决

1、每次拉取或者提交的时候带入用户名密码

例如:
git pull http://用户名:密码@localhost:1080/mdm.git
git push https://用户名:密码@localhost:1080/mdm.git

[root@LXCL-Web mdm]# git pull http://mdm:mdm123@localhost:1080/mdm.git
来自 http://localhost:1080/mdm
 * branch            HEAD       -> FETCH_HEAD
Already up-to-date.
[root@LXCL-Web mdm]#
2、配置文件加用户名密码

.git目录下,有一个config文件,vim .git/config加入用户名密码:

[root@LXCL-Web config-server]# cat mdm/.git/config
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = http://用户名:密码@localhost:1080/mdm.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
3、设置存储文件

1、取消弹出登陆页面

[root@LXCL-Web mdm]# git config --global --unset credential.helper

2、修改凭证策略,增加 credential.helper=store 一行

[root@LXCL-Web mdm]# git config --global credential.helper store

3、查看相关配置信息

[root@LXCL-Web mdm]# git config --list
user.name=mdm
user.email=mdm@example.com
push.default=simple
##credential.helper=store
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=http://mdm@localhost:1080/mdm.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master

4、这时候你再次提交输入用户密码之后,第二次再提交就不用输入用户名密码了。

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐