# 體驗社課 --- ## 專題研究班 ---- ### Q1. 這個班在做(教)什麼? ---- ### Q2. 完全沒有程式語言基礎適合嗎? ---- ### Q3. 要帶筆電來嗎? ---- ### Q4. 社展? ---- ### Q5. 提問... --- ## 那就開始今天的主題吧! --- ## git? GitHub? ![](https://hackmd.io/_uploads/HJLzQl7ah.png) --- ![](https://hackmd.io/_uploads/rkteANma2.png) ---- ### git是啥? git是一個版本控制系統, 用來管理軟體項目或是專案中的更改。 ---- ### 為什麼要用git? ---- ### 1.版本控制 git 能夠跟蹤文件和程式的每個變更, 可以查看、比較和恢復不同版本的內容。 ---- ### 2.分支和合併 可以創建分支,這麼做可以避免衝突, 然後可以將分支合併回主要的專案。 ---- ### 3.多人協作 成員可以在自己的分支上工作, 而不會干擾其他人。 --- ![](https://hackmd.io/_uploads/B1_CaVXTn.png) ---- ### GitHub又是啥? ---- ### GitHub 簡介 GitHub 是一個基於 Git 分散式版本控制系統的網絡平台,用於協作開發項目、管理代碼版本,以及促進開源社區合作。它提供了許多強大的功能,能夠簡化代碼管理、協作和項目追蹤。 ---- ### 主要功能: ---- ### 1.版本控制 GitHub 使用 Git 來追蹤文件和代碼的每個變更。可以輕鬆查看、比較和恢復不同版本的內容。 ---- ### 2.協作與共享 您可以在 GitHub 上創建儲存庫(repositories),使團隊成員可以同時工作、協作和共享程式。每個儲存庫都是一個完整專案,包含程式、文檔...等。 ---- ### 3.問題追蹤 GitHub 的 "Issues" 功能讓使用者可以輕鬆創建、分配和追蹤問題、錯誤和任務。 ---- ### 4.分支和合併 使用分支(Branches)功能,可以在不影響主要程式的情況下進行新功能或修復的開發。合併(Merge)功能使您能夠將分支的更改整合回主要程式。 ---- ### 5.Pull 請求 通過 "Pull Requests",您可以將您的更改提交到主要程式庫,並邀請其他人進行審查。這有助於確保更改的一致性。 ---- ### 6.GitHub Pages GitHub Pages 是 GitHub 提供的一項服務,可以輕鬆地將靜態網站和網頁部署到網路上。 ---- ### 7.開源社區 GitHub 是一個龐大的開源社區,您可以在其中發現數以百萬計的開源項目。您可以查看程式、參與討論,並向其他項目做出貢獻。 --- ## lets start ---- ### 安裝git 去[官網](https://git-scm.com/downloads)下載或使用 package manager(套件管理工具)例如: | Windows | Macos | linux | | -------- | -------- | -------- | | chocolatey | brew | apt | ---- ### git init 初始化一個新的資料夾(專案) ```bash user@user:~[project path]$ git init ``` ---- ### 如果想要移除git的話 這段程式要小心不要打錯 (有可能會刪到不該刪東西) ```bash user@user:~[project path]$ rm -rf .git ``` `rm` (remove) `-rf` (r:directory,f:force) ---- ### .gitignore 顧名思義這個檔案就是要讓一些檔案不要被加到git ```bash user@user:~[project path]$ touch .gitignore ``` 你可以編輯它(nano, vim ...) ```bash user@user:~[project path]$ vim .gitignore ``` ---- ### git add 添加單一檔案 ```bash user@user:~[project path]$ git add <file name> ``` 添加全部 ```bash user@user:~[project path]$ git add . ``` ---- ### git reset ```bash user@user:~[project path]$ git reset <file name> ``` ```bash user@user:~[project path]$ git reset . ``` ---- ### git status 你可以直接在terminal裏面看或是使用vscode套件 ![](https://hackmd.io/_uploads/ryA5CmIT3.png) ---- ![](https://hackmd.io/_uploads/ryeUe4Lp2.png) ---- ### git commit ```bash user@user:~[project path]$ git commit -m "first commit" ``` ---- ### git branch ![](https://hackmd.io/_uploads/HkM8vNIa2.png) ---- ```bash user@user:~[project path]$ git branch *master user@user:~[project path]$ git checkout -b "fix_bug" Switched to a new branch 'fix_bug' user@user:~[project path]$ git branch *fix_bug master ``` ---- ### git pull/ push 當你已經commit完你的程式到你所在的branch之後就可以push到GitHub repository上了 --- ## 夢幻聯動git&GitHub ![](https://hackmd.io/_uploads/SysFJbDa2.png) ---- ### 安裝GitHub CLI 直接從[官網](https://cli.github.com/)下載或是package manager例如: | Windows | Macos | linux | | -------- | -------- | -------- | | chocolatey | brew | apt | [詳細說明](https://github.com/cli/cli#installation) ---- ### 新增一個repository用(github.com) ### (或使用Github CLI) ![](https://hackmd.io/_uploads/ryJjkevTn.png) ---- ### 可以使用HTTPS, SSH或是直接用 ### GitHub Desktop來remote ![](https://hackmd.io/_uploads/r1qkxePTn.png) ---- ```bash user@user:~[project path]$ git init user@user:~[project path]$ touch a user@user:~[project path]$ ls a user@user:~[project path]$ git add . user@user:~[project path]$ git commit -m "add a" ``` ```bash user@user:~[project path]$ git remote add origin \ https://github.com/[user name]/[repository name].git user@user:~[project path]$ git branch -M main user@user:~[project path]$ git push -u origin main ``` ---- ### 就會發現你的repository多了一個a 而且中間寫的就是你的commit(add a) ![](https://hackmd.io/_uploads/B1tOAlvTh.png) ---- ### clone一個repository也是一樣的做法 ```bash user@user:~$ git clone \ https://github.com/[user name]/[repository name].git user@user:~$ cd [repository name] user@user:~[repository name]$ ls a ``` ```bash user@user:~[repository name]$ touch b user@user:~[repository name]$ ls a b user@user:~[repository name]$ git add . user@user:~[repository name]$ git commit -m "add b" user@user:~[repository name]$ git push ``` ---- ### 就會發現你的repository又多了一個b ![](https://hackmd.io/_uploads/rkVqzbwph.png) ---- ### 如果不想這麼麻煩可以使用 ### [GitHub Desktop](https://desktop.github.com/) 雖然用這個很簡單,但上面的基礎指令 還是希望各位要會,所以我才會把這個放到最後講 --- ### 上完這些,各位應該已經對git&GitHub ### 有比較清楚的瞭解了 那就可以開始建立自己的repository做專案了! --- ## 有問題也可以直接來問喔!
{"description":"type : slide","title":"git","contributors":"[{\"id\":\"e0c7dab8-be31-4e15-a8e7-22968131e3e1\",\"add\":5174,\"del\":658}]"}
    192 views