GitHub 簡單設定以及同步 GitHub 與電腦間兩端的 code
本文參考沈弘哲的 YouTube 教學 github 基本教學 - 從無到有。
參考 Signing up for a new GitHub account。
在 GitHub 網站先申請帳號。
-
到 Git 網站下載 Git 並且安裝。
-
參考 Generating a new SSH key and adding it to the ssh-agent。
開啟 Git Bash,輸入以下指令:
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
進入互動模式,輸入
Enter
鍵即表示接受預設值。預設會在 User Profile 目錄下的 \.ssh 目錄產生私鑰檔案 (id_rsa) 與 公鑰檔案 (id_rsa.pub)。 -
參考 Adding a new SSH key to your GitHub account。
開啟公鑰檔案(~\.ssh\id_rsa.pub),複製其內容。
開啟 GitHub 網站,點選右上角 Settings。
再點到 SSH and GPG Keys ➜ SSH Keys ➜
New SSH Key
按鍵。張貼到網頁的 Key 欄位中,再輸入 Title 後,按下
Add SSH Key
。完成後,Email 信箱會收到一封來自 GitHub 的通知信。
-
參考 Setting your username in Git。
在 Git Bash 輸入以下指令:
$ git config --global user.name "your name" $ git config --global user.email "your_email@example.com"
右上角 +
號下的 New Repository
:
輸入專案名稱,其餘可視需要填寫,填寫完後按下 Create repository
:
在該專案頁面下,找到 Clone or Download
,複製該網址。
在電腦上開一個資料夾,Git Bash 切換到該路徑下,輸入剛才複製的網址內容。
$ git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY
整個專案就會下載為以該專案為檔名的資料夾了,當中有 REDAME.md 檔案。
-
$ git add modified.file
-
$ git commit -m "Some comment"
-
$ git push
過程如圖所示:
此時回到 GitHub 專案頁面,會發覺頁面更新了。