4-07 3 views
我们在使用Git时,经常会先要保存个人的名称和邮箱,用于在Commit时进行标识自己的身份
1 2 |
git config --global user.name "Eirc Winn" git config --global user.email "eng.eric.winn@gmail.com" |
但是这个只是用户名和邮箱,密码要怎么能记住呢?
有两种方式(我这里说的是命令行,如果是使用IDE工具的另当别论)
第一种:Clone时直接带认证信息
1 |
git clone https://username:password@bitbucket.org/abc/abc.git |
这种方式,认证信息是写在.git/config文件中的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
$ git remote -v origin https://username:password@bitbucket.org/abc/abc.git [fetch] origin https://username:password@bitbucket.org/abc/abc.git [push] $ git config --list user.email=eng.eric.winn@gmail.com user.name=Eric Winn core.repositoryformatversion=0 core.filemode=true core.bare=false core.logallrefupdates=true remote.origin.url=https://username:password@bitbucket.org/abc/abc.git remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* branch.master.remote=origin branch.master.merge=refs/heads/master $ cat .git/config [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "origin"] url = https://username:password@bitbucket.org/abc/abc.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master |
另一种方式:存在credentials中
你可以直接编辑.git/config,对当前仓库生效
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
$ vim .git/config # windows没有vim,可以直接用写字板打开编辑 [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "origin"] url = https://bitbucket.org/abc/abc.git #删掉个人账户信息 fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master # 添加以下两行 [credential] helper = store |
也可以使用全局设置命令,像设置名称和邮箱一样
这种设置方式,是将账户信息保存在~/.git-credentials
1 |
git config --global credential.helper store |
1 2 3 4 5 6 |
$ cat ~/.gitconfig [user] email = eng.eric.winn@gmail.com name = Eric Winn [credential] helper = store |
这种设置方式,是将账户信息保存在~/.git-credentials
1 2 |
$ cat ~/.git-credentials https://username:password@bitbucket.org |
另外需要记住一点,这种设置方式,当你不想保存账户信息,使用unset取消credential的设置时,.git-credentials文件需要手工删除

Comments are closed, but trackbacks and pingbacks are open.