首先在本地創建 SSH Keys
$ ssh-keygen -t rsa -C "wx166@163.com"
后面的郵箱即為 github 注冊郵箱,之后會要求確認路徑和輸入密碼,一路回車就行。
成功的話會在 ~/
下生成 .ssh
文件夾,進去,打開 id_rsa.pub
,復制里面的key
。
那么問題來了,如何進入到 ~/ 路徑下找到 .ssh 文件夾呢?
使用命令
cd ~/.ssh
出現提示 "No such file or directory",此時可以選擇手動創建一個 .ssh 文件夾,如下:
然后執行之前的命令生成 SSH Keys
此時 SSH Keys 已經生成,查看內容
復制全部內容,打開 GitHub 主頁,左側選擇 SSH and GPG Keys, 點擊 Add SSH Keys,然后輸入名稱,並將復制的內容粘貼過來,添加即可。
驗證 SSH Keys 是否添加成功
$ ssh -T git@github.com
如果是第一次的會提示是否continue,輸入yes就會看到:You've successfully authenticated, but GitHub does not provide shell access 。這就表示已成功連上github。
接下來我們要做的就是把本地倉庫傳到github上去,在此之前還需要設置username和email,因為github每次commit都會記錄他們。
1 $ git config --global user.name 'wangxi' 2 $ git config --global user.email 18817801185@163.com
進入要上傳的倉庫,右鍵 git bash,添加遠程地址
$ git remote add origin git@github.com:wangxi/Node-React-MongoDB-TodoList.git
加完之后進入 .git,打開 config,這里會多出一個remote "origin"內容,這就是剛才添加的遠程地址,也可以直接修改config來配置遠程地址。
創建新文件夾,打開,然后執行 git init
以創建新的 git 倉庫。
檢出倉庫
git clone /path/to/repository
檢出服務器上的倉庫
git clone username@host:/path/to/repository