Git配置詳解

2021-09-03 09:44:56 字數 1503 閱讀 6941

由於重灌系統和不同的電腦都需要重新配置git,記錄下來,就可以節約配置git的時間。

git config  --global user.email "[email protected]"

git config --global user.name "chengshuyi"

必須用上面的命令進行配置,不然無法進行git commit命令

git config --help可以檢視配置資訊

ssh-keygen -t rsa -b 4096 -c "[email protected]"執行這個命令就可以生成id_rsa.pubpush有兩種方式,一種是基於https,另外一種是基於ssh的。不同的push方式需要不同的配置。

基於https的push需要的是賬號和密碼,就像登入https的網頁一樣。

基於ssh的push需要的是rsa的私鑰,同時公鑰要放在github上面。

具體的配置流程如下:

3.1 基於https的免密push

進入c:\users\administrator目錄,如果看見有.gitconfig檔案,那就對了。在git bash中輸入下面的命令

touch .git-credentials

vim .git-credentials

git config --global credential.helper store輸入命令

3.2 基於ssh的免密push

ssh-keygen -t rsa -b 4096 -c "[email protected]"執行這個命令就可以生成id_rsa.pubid_rsaid_rsa.pub放在對應的github設定裡面。(settings->ssh and gpg keys)

3.4 多台電腦共享ssh的公鑰和私鑰

儲存配置的ssh的私鑰,可以很方便的給新增乙個使用者。比如重灌了系統之後就不需要在配置ssh;換一台電腦也不需要重新配置。只需要拷貝私鑰到指定的目錄即可。

拷貝.ssh檔案到使用者目錄。(windows的使用者預設目錄為c:\users\***,***代表windows的使用者名稱;切換到linux的預設目錄使用cd ~命令即可。)

windows 10拷貝命令copy .\.ssh\* 'c:\users\c1527\.ssh\';linux拷貝命令為copy -f .ssh/ ~/

ubuntu注意許可權問題:

eval 「$(ssh-agent -s)」

ssh-add

chmod -r 700 ~/.ssh/

git中ssh key配置詳解

當使用git方式 時,如果沒有配置過ssh key,則會有如下錯誤提示 下面就介紹一下如何配置git的ssh key,以便我們www.cppcns.com可以用git方式 原始碼。首先用如下命令 如未特別說明,所有命令均預設在git bash工具下執行 檢查一下使用者名稱和郵箱是否配置 github...

Git操作詳解

版本狀態 要隨時掌握工作區的狀態,使用git status命令。如果git status告訴你有檔案被修改過,用git diff可以檢視修改內容。比較不同 git diff可以檢視修改內容。檢視歷史記錄 git log git log pretty oneline美化輸出,只包含commit id ...

GIT 操作詳解

1 git 建立庫 找到目錄檔案 git init 2 建立檔案 eg hello.php 注意要utf 8 3 新增 git add hello.php 如果是 就是新增全部 4 提交到注釋資訊 git commit m new php file hello.php create 5 檢視hell...