設置記住密碼(默認15分鍾):
git config --global credential.helper cache
如果想自己設置時間,可以這樣做:
git config credential.helper 'cache --timeout=3600'
這樣就設置一個小時之后失效
長期存儲密碼:
git config --global credential.helper store
增加遠程地址的時候帶上密碼也是可以的。(推薦)
從倉庫的config的里面修改url,后面加上密碼
http://yourname:password@git.oschina.net/name/project.git
補充:使用客戶端也可以存儲密碼的。
git設置用戶名密碼
設置git用戶名/郵箱
git config --global user.name [username] git config --global user.email [email]
但是這個僅僅是設置用戶名密碼,如果你的git 源每次操作需要你輸入用戶名/密碼驗證,你依然需要每次設置,那么該如何辦呢?
git保存用戶名密碼
這里主要是配置一個config項
有兩個方法,基本上原理都是一樣,都是修改.git/config
文件
1.使用如下命令,修改config文件即可保存
echo "[credential]" >> .git/config echo " helper = store" >> .git/config
2.直接修改.git/config文件
在linux/mac下可以直接使用vim工具修改config文件
ubuntu@VM-7-212-ubuntu:~/kernel-code/kernel-netfilter-sample-code$ vim .git/config ##修改成如下 [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "origin"] url = https://github.com/Miss-you/kernel-netfilter-sample-code.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master ##主要是后面這兩行,如果不想保存,則刪除即可 [credential] helper = store ##保存
這樣就可以保存用戶名密碼,不用每次都輸入了!
git config查看配置
使用git config --list
查看已設配置
feiqianyousadeMacBook-Pro:xt_GTPU yousa$ git config --list
core.excludesfile=/Users/yousa/.gitignore_global user.name=Miss-you user.email=snowfly1993@gmail.com core.repositoryformatversion=0 core.filemode=true core.bare=false core.logallrefupdates=true core.ignorecase=true core.precomposeunicode=true remote.origin.url=https://github.com/Miss-you/xt_GTPU.git remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* branch.master.remote=origin branch.master.merge=refs/heads/master