1. 配置文件
Git的配置文件有三個:
- 系統(tǒng)配置: /private/etc/gitconfig
- 用戶配置: ~/.gitconfig
- 項目配置:.git/config
2. 用戶憑證
由于Git和Github交互操作可能會很頻繁,那么一定少了用戶授權(quán)的操作,為了防止每次操作重復(fù)輸入用戶名和密碼,Git提供了兩種解決方法:
-
秘鑰
首先創(chuàng)建一對秘鑰 ssh-keygen -t rsa,然后將 id_rsa.pub (公鑰)內(nèi)容拷貝到github中,日后操作無需再輸入用戶名和密碼。
注意:這種方式需要使用GIt中 git@github.com:WuPeiqi/xxxxx.git 格式地址。
-
密碼
Https訪問git時,避免每次操作需要輸入用戶名和密碼,可以在配置文件中添加如下配置項:
[credential]
helper = store/cache/第三方
store:
表示將用戶名和密碼保存在硬盤上
第一次輸入過用戶名和密碼之后,用戶名和密碼就會保存在當(dāng)前用戶根目錄的 .git-credentials 文件中,內(nèi)容格式為:https://用戶名:密碼@github.com
自動添加配置命令:git config credential.helper store
cache:
表示將用戶名和密碼保存在緩存中
第一次輸入過用戶名和密碼之后,用戶名和密碼就會保存在緩存中,默認超時時間是 900 秒,緩存相關(guān)文件保存在當(dāng)前用戶根目錄的 git-credential-cache 中
自動添加配置命令:
git config credential.helper cache
git config credential.helper 'cache --timeout=300'
相關(guān)操作:
清除緩存:git credential-cache exit
指定超時:
[credential]
helper = cache --timeout=300
注意:這種方式需要使用GIt中 https://github.com/cx/xxxx.git 格式地址。
<pre data-filtered="filtered" style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;"> 以斜杠“/
”開頭表示目錄;
以星號“
*
”通配多個字符;
以問號“?”通配單個字符
以方括號“[]”包含單個字符的匹配列表;
以嘆號“!”表示不忽略(跟蹤)匹配到的文件或目錄;