1. 程式人生 > >git 免賬號密碼push原始碼方法

git 免賬號密碼push原始碼方法

git預設push需要填寫賬號密碼才能成功,通過配置賬號和ssh可以實現直接推送,節省時間。步驟如下:

1. 開啟.git/config,找到[remote "origin"]欄下的url,將https認證改成git認證,格式如下

[email protected]:xxx/learngit.git

xxx是賬號

2開啟家目錄下.ssh目錄,如果存在id.rsa,id.rsa.pub,表示已有金鑰生成,如果不用可直接刪除,重新生成。

ssh-keygen -t rsa -b 4096 -C "xxx",一路回車

ssh-add ~/.ssh/id_rsa

3 開啟id_rsa.pub,複製公鑰資訊,開啟github的setting頁,ssh gpg keys選項,點選new ssh key,貼上公鑰資訊,輸入名稱,如cloud-key,點選提交。

測試方法,執行命令
 git push -u origin master

結果如下:

Counting objects: 4, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 424 bytes | 0 bytes/s, done.
Total 4 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To [email protected]:xxx/learngit.git
   b877021..8c0d0f4  master -> master
Branch master set up to track remote branch master from origin.