# 講座一:淺談版本管理與分岔(實作) * 講義: [TOC] ## 實作一:探索 Git 儲存庫託管平台 逛一逛幾個 Git 儲存庫(Repository)的託管網站 * The Linux Kernel Archives * https://kernel.org  * Audacity GitHub * https://github.com/audacity/audacity * Blender GitHub * https://github.com/blender/blender * NotePad++ (台灣開發者侯今吾寫的文字編輯器) * https://github.com/notepad-plus-plus * Aesthetic-Programming 《美學程式設計》GitLab * https://gitlab.com/aesthetic-programming * 最後,申請一個 GitHub 帳號 * https://github.com/  ## 實作二:安裝 Git(本地端工具) Ref: [How to Install Git on Mac and Windows! (Beginner's Guide)](https://www.youtube.com/watch?v=7ouVv6PFZGc) (youtube) 步驟: 1. 前往 https://git-scm.com/downloads * Windwos 用戶下載 `64-bit Git for Windows Setup.` * Mac 用戶依照指引使用 brew 安裝 git 1. 先依照 https://brew.sh/ 的指示安裝 brew ``` /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` 2. 再透過 brew 安裝 git ``` brew install git ``` * 驗證:在終端機下執行 `git --version` 看看是否輸出版本編號      ## 實作三:在 GitHub 建立第一個儲存庫 指令: | Git 指令 | 說明 | |----------------------|-------------| |`git --help` | 查詢 git 指令 | |`git status` | 查看 repository 狀態 | |`git init` | 建立一個「空的」local repo | |`git add` | 將檔案納管,暫時加入 暫存區(Stage) | |`git commit -m "訊息"` | 將暫存區(Stage) 內的檔案,提交(Commit)到 local repo | |`git log` | 顯示 commit logs | |`git diff` | 顯示 commit 前修改的內容 | |`git push` | 將 local 端 repo 的狀態同步到 remote 端 | |`git pull` | 將 remote 端 repo 的狀態同步回 local 端 | github 申請後 ``` git config --global user.email "you@example.com" git config --global user.name "Your Name" ``` ### Step 1. 在 local 端建立自己的儲存庫,並且提交幾個檔案  操作示範:  如果剛剛沒有設定 email 和名稱,commit 時會報錯  ### Step 2. 在 GitHub 建立一個 remote 端的空儲存庫 建立一個 remote repo   ### Step 3. 將 local 端的儲存庫上傳(push)到 remote 端(GitHub)  push 指令: ``` git remote add origin git@github.com:<你的帳號>/<你的repo_name>.git git push -u origin main ``` ## 實作四:練習修改遠端檔案並同步 | Git 指令 | 說明 | |----------------------|-------------| |`git pull` | 將 remote 端 repo 的狀態同步回 local 端 | 實驗步驟 1. 直接在 GitHub(remote端) 修改或新增檔案 2. 在 local 端開啟終端機,進入「由 git 控管的目錄」,執行 ``` git pull ``` 3. 檢查看看 local 端的檔案是否已經與 remote 端同步  ## 實作五:回溯到特定版本  指令 ``` git checkout <SHA/revision> ``` ``` git checkout HEAD ``` ## 實作六:Fork 儲存庫,製作自己的副本  ## 實作七:讓你的貢獻被看見(從 Fork 到 Merge)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up