使用git連接本地和遠程github


使用git連接本地和遠程github

網上很多github的流程比較亂,自己嘗試整理了一下,主要是步驟較為清晰,如果有不清楚的可詳細進行搜索對比

1. 申請和設置github

https://github.com/
該過程請自行參考

2. 使用gitbash設置用戶名和郵箱

打開gitbash,輸入命令設置用戶名和郵箱

$ git config --global user.name "your name"
$ git config --global user.email "your email"

3. 生成ssh配置

通過郵箱名稱生成ssh key,在輸入第一行命令后火提示輸入保存key的地址,根據自己的結構指定文件的地址,

$ ssh-keygen -t rsa -C "xxx@gmail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/kf/.ssh/id_rsa): D:/ssh/github
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in D:/ssh/github.
Your public key has been saved in D:/ssh/github.pub.
The key fingerprint is:
SHA256:8J70WllHBwvnolh+LVG2pIOMKRkhzJibLjyoiZNBXvA 
xxx@gmail.com
The key's randomart image is:
+---[RSA 2048]----+
|   =. o.    . *  |
| .o o. o + . O + |
|  oo  + o + = = .|
| .oE   + + . * . |
|=..     S o + o  |
|++.    o o + o   |
|o=.     o +      |
|*        o       |
| .      .        |
+----[SHA256]-----+

4. 配置github ssh

執行成功后,生成目錄下會生成兩個文件,一個是私鑰一個是公鑰,找到后綴是 .pub 的公鑰文件,拷貝全部文件內容到github中,具體方法是在github頁面中Settings > SSH and GPG keys > New SSH key 中設置,title內容隨意設置。

5. 配置本地ssh

執行ssh-add -l 查看本地ssh配置情況

$ ssh-add -l

如果返回如下,則說明配置正確

2048 SHA256:8J70WllHBwvnolh+LVG2pIOMKRkhzJibLjyoiZNBXvA /d/ssh/github (RSA)

如果返回下面一句話,這說明沒有起效

Could not open a connection to your authentication agent.

需要執行如下語句:

$ ssh-agent bash
$ ssh-add /d/ssh/github

6. 驗證連接

ssh配置成功后驗證是否能夠正確連接github

$ ssh -T git@github.com
Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.

7. 與github同步

將本地項目上傳到github

$ git remote add origin git@github.com:your_project.git  
$ git push -u origin master 

如果本地沒有則先下載到本地再同步

$ git clone your_project.git  
$ git push -u origin master


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM