Skip to content

hsychen/GitHub-FirstTry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

GitHub-FirstTry

GitHub 簡單設定以及同步 GitHub 與電腦間兩端的 code

本文參考沈弘哲的 YouTube 教學 github 基本教學 - 從無到有

在 GitHub 網站申請帳號

參考 Signing up for a new GitHub account

GitHub 網站先申請帳號。

在新電腦上設定 Git

  1. Git 網站下載 Git 並且安裝。

  2. 產生 SSH Key:

    參考 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)。

  3. 將 SSH Key 加到自己的 GitHub 帳戶:

    參考 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 的通知信。

  4. Git 設定帳號與 Email:

    參考 Setting your username in Git

    在 Git Bash 輸入以下指令:

    $ git config --global user.name "your name"
    $ git config --global user.email "your_email@example.com"

在 GitHub 網站開新專案

參考 Creating a new repository

右上角 + 號下的 New Repository

輸入專案名稱,其餘可視需要填寫,填寫完後按下 Create repository

複製專案到電腦

在該專案頁面下,找到 Clone or Download,複製該網址。

在電腦上開一個資料夾,Git Bash 切換到該路徑下,輸入剛才複製的網址內容。

$ git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY

整個專案就會下載為以該專案為檔名的資料夾了,當中有 REDAME.md 檔案。

若電腦內專案的檔案內容有更新

  1. Git Bash 切換到該專案路徑。

  2. 將有變更的檔案加入追蹤:

    $ git add modified.file
  3. Commit。並且需要加上一點註解 / 訊息。

    $ git commit -m "Some comment"
  4. 將專案上傳至 GitHub:

    $ git push

    過程如圖所示:

    此時回到 GitHub 專案頁面,會發覺頁面更新了。

若 GitHub 上專案內容有更新

  1. 先將 GitHub 上的 README.md 內容稍作修改。

  2. Git Bash 切換到該專案路徑。

  3. 輸入以下指令

    $ git pull --rebase

About

GitHub 簡單設定以及同步 GitHub 與電腦間兩端的 code

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published