一、Git查看全局賬號密碼
在Git中,可以通過以下命令查看全局賬號密碼:
$ git config --global --list
user.name=[Your Name]
user.email=[Your Email]
credential.helper=osxkeychain
其中credential.helper=osxkeychain表示使用OSX Keychain來存儲Git賬號密碼,可以避免每次都需要輸入賬號密碼。
如果你的Git沒有設置OSX Keychain,可以使用如下命令設置:
$ git config --global credential.helper osxkeychain
這樣,在你第一次使用Git拉去代碼時,會彈出一個窗口讓你輸入賬號密碼,之後再使用Git pull/push等命令就不需要再次輸入密碼。
二、Git查看本地倉庫賬號密碼
有時我們需要查看某個Git本地倉庫的賬號密碼,可以使用如下命令:
$ cat .git/config
...
[remote "origin"]
url = https://github.com/[Your Name]/[Your Repo].git
fetch = +refs/heads/*:refs/remotes/origin/*
username = [Your Username]
...
其中的username即為該倉庫的賬號名。
此外,下面這個命令也可以查看本地倉庫的賬號名和密碼:
$ git config --local -l
credential.helper=osxkeychain
user.name=[Your Name]
user.email=[Your Email]
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=https://github.com/[Your Name]/[Your Repo].git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
其中remote.origin.url即為該倉庫的地址。
三、注意事項
最後,提供幾條使用Git查看賬號密碼時要注意的事項:
1、一定要保護好自己的賬號密碼,不要輕易泄露。
2、在使用Git時,應該養成使用SSH方式連接伺服器的習慣,這樣可以避免賬號密碼泄露。
3、如果不希望Git保存密碼,可以使用以下命令:
$ git config --global credential.helper ""
這樣就會清除OSX Keychain里的Git賬號密碼信息。
原創文章,作者:FQCDK,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/329347.html