SlideShare a Scribd company logo
Git 指令與觀念
與大家合作做專案之前必學技能之一
上課時間: 2 Hours
Jacob Lin
Organizer
Ryan Lin
Project Lead
本日Outline
19:05 關於「多人開發專案」 p3
19:15 踏入 Git 的第一步 p9
19:30 用 Git 指令與別人開發 p26
20:00 中場休息
20:15 用 GitHub 貢獻你的成果 p52
20:30 VS Code 內建 GUI 操作 p62
// 19:00 - 21:00
關於 「多人開發專案」
3
什麼是「開發程式專案」?
眾多的程式碼的集合體,由一人以上撰寫而成
● 網頁設計
● 手機 APP
● 遊戲開發
4
5
多人開發專案遇到問題
6
● 同步開發衝突
● 想回去之前的版本
想像一下...... 同時編輯一個檔案 - 協同開發
7
我想要增加
加法的功能
我想要增加
乘法的功能
calculator.py
你是否想找之前的版本 - 版本控制
8
calculator.py
A week ago
calculator.py
3 days ago
calculator.py
currently
Add func Add func
Multiply func
(x) Add func
(x) Multiply func
踏入 Git 的第一步
9
實作:GitHub 註冊與 Git 下載
10
● 註冊 GitHub 帳號
● 下載 Git 工具
● 在你的電腦終端機設定並登入你的 Git 帳號
註冊 GitHub 帳號
11
● 前往 https://github.com/ 之後點選 Sign up 按鈕
● 輸入帳號密碼等資料
● 證明你是人類(要有點耐心,做錯要重來......)
● 填寫一些問卷
● 驗證電子郵件
● 完成 !
12
13
Now It’s your Turn !!
14
下載 Git 工具: 檢查看看你的電腦有沒有 Git
15
● Windows 使用者:
○ 打開命令提示字元 Command Line 或是 PowerShell
○ 輸入 Git 指令看是否存在
● MacOS or Ubuntu (Linux) 使用者:
○ 打開終端機 (Terminal)
○ 輸入 Git 指令看是否存在
16
下載 Git 工具 - Windows
17
● 前往 https://git-scm.com/download/win
● 在 Standalone Installer 底下下載 32 or 64 位元版本
● 執行下載的 exe 檔案
● 就跟一般安裝東西一樣,瘋狂按 next 到 finish
● 檢查看看你的電腦有沒有安裝成功 Git
下載 Git 工具 - MacOS
18
● 打開終端機 (Terminal)
● 輸入安裝指令: `brew install git`
● 如果找不到 `brew` 指令,請至 https://brew.sh/ 網頁複製安裝指令:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”
● 檢查看看你的電腦有沒有安裝成功 Git
● 前往 https://git-scm.com/download/linux ,有許多不同系統對應的安裝指令
● 打開終端機 (Terminal)
● 輸入對應的安裝指令,像是: `apt-get install git`
● 檢查看看你的電腦有沒有安裝成功 Git
下載 Git 工具 - Ubuntu (Linux)
19
設定 Git 相關配置
20
● 設定使用者名稱:git config --global user.name "Your username"
● 設定電子郵件:git config --global user.email YourEmail@example.com
● 輸入指令檢視設定:git config --list
Now It’s your Turn !!
21
在 Git 裡常提到的一些名詞
22
● repository (儲存庫) (repo),等同於你的專案資料夾。
● commit (提交): 專案 (repo) 的變更記錄。
● branch (分支):專案 (repo) 中的一個獨立開發線。
23
Repository 示意圖
A lot of Code Files
Repository
24
Commit 示意圖
calculator.py
A week ago
calculator.py
3 days ago
Add func Add func
Multiply func
Commit
25
Branch 是什麼
Add func
Add func
Multiply func
Commit
Commit
Add func
Divide func
Branch 2
Branch 1
用 Git 指令與別人開發
26
實作:創建第一個 Repository
27
● 請在你們組別派一個代表作為 Owner
● 在 Owner 的 GitHub 帳號下創一個 Repository
● 給予其他人存取權限
● 確保大家都擁有相同的 Repository
用 GitHub 創一個 Repository
28
● 前往個人資料 profile 首頁,網址 https://github.com/YourUsername
● 點選 Repository 檢視目前的 repo 清單
● 點選 New 新增 Repo
● 取名後完成創建
29
30
發送邀請連結給予其他人
31
● 前往你的 repo 首頁,點選設定
● 點選 Collaborator
● 點選 Add people
● 輸入 username or email 邀請別人
● 查看清單檢視邀請狀態
32
33
34
Now It’s your Turn !!
35
在你的電腦終端機設定並登入你的 Git 帳號
36
拿取 token,就像你的專屬鑰匙
● 前往 https://github.com/settings/tokens
37
38
39
怎麼在終端機登入 GitHub 帳號
40
● 後續實作中輸入 git clone, git push, git pull 關鍵指令將會觸發登入驗證事件
● 輸入 username, token 後 enter,將完成登入!
41
42
把你的 repo 拿下來
● git clone 你的專案網址
Now It’s your Turn !!
43
實作:一起在共同的專案開發
44
● 每個人開一個新分支
● 在自己的分支下寫任何你想要的程式
● 提交至 GitHub 上
git add
45
檔案新增至暫存區
暫存區
git commit
46
暫存區
暫存區的變更記錄到 repo
Commit
git push
47
Commit
本地 repo 內容上傳到 GitHub
48
Git Cheet Sheet
49
指令細節
● git checkout -b 你的 branch 名稱
● git add 你的檔案名稱 -> 移動至暫存區
● git commit -m “你的訊息” 你的暫存區檔案的名稱
● git push 把檔案傳到 GitHub
Now It’s your Turn !!
50
51
中場休息
10 分鐘
用 GitHub 貢獻你的成果
52
實作:提交你的第一個 PR
53
● 在你先前提交的上去的 branch 發起一個 PR
● 請給其他人檢視並確認後合併至 main branch
● 查看你的成果 !
54
55
56
57
實作:提出你的第一個 issue
58
● 在 Repo 中提交一個 issue 提出你的意見
● Owner 檢視過 issue 後在底下留言
● Owner 回應了你的意見後關閉你的 issue
59
60
Now It’s your Turn !!
61
VS Code 內建 GUI 操作
62
63
- GitHub Codespaces 介紹
- 基礎 git 操作
- 合併 PR 操作
on GitHub Codespaces
VS Code 內建 GUI 操作
在瀏覽器中直接以 VS Code 介面
操作的雲端 Linux VM
* 每月 60 小時免費額度
GitHub Codespaces
64
65
66
之前開的(休眠中)
新增 Codespaces
67
Codespaces =
在瀏覽器 VS Code
操作雲端 Linux VM
68
以一般的方式新增檔案
以及操作終端機
直接以圖形界面(GUI)操作 git
搭配圖像記憶,方便快速
在 VS Code 中操作版本控制
69
70
版本控制分頁
71
Stage All Changes
相當於 git add
72
提交
相當於 git commit
73
同步變更
相當於 git push / git pull
74
多數 git 操作都在這
視覺化的 git status
75
新增 branch
76
輸入 branch 名稱
77
簡單改一行後提交
78
將新的 branch push 上去
在 VS Code 中操作 GitHub
Pull Request 合併流程
GitHub VS Code Extension
79
80
直接發 PR
81
填寫 PR 標題與描述
82
查看 PR
83
合併 PR
84
85
切換 branch
86
選擇 local main branch
87
從遠端 pull 最新狀態
88
可以看到合併完的樣子
89
直接關掉分頁即可
Codespaces 幾分鐘後就會進入休眠
90
GitHub 上也可以看到
合併完的樣子
91
GitHub 上也可以看到
合併完的樣子
Thank you for
Your Attend !!!
92

More Related Content

PDF
Git and Github basic with SourceTree
PDF
COSCUP 2015 開源之道-Git工作坊教學簡報
PDF
初探GitHub Copilot - 2025 Global AI Bootcamp
PDF
CICD Workshop 20180922
PPTX
Github初上手教學
PPTX
Github in xcode
PDF
Learn github-from-zero
PDF
Git tutorial for windows user (給 Windows user 的 Git 教學)
Git and Github basic with SourceTree
COSCUP 2015 開源之道-Git工作坊教學簡報
初探GitHub Copilot - 2025 Global AI Bootcamp
CICD Workshop 20180922
Github初上手教學
Github in xcode
Learn github-from-zero
Git tutorial for windows user (給 Windows user 的 Git 教學)

Similar to GDSC Lecture - 與大家合作做專案之前必學_ Git 指令與觀念.pdf (20)

PDF
Bootstrap個人網站 20141117
PDF
First meetingwithgit
PDF
Learning to Use Git | WeiYuan
PDF
Android studio & Git in Windows
PPTX
Visual Studio 2015 與 Git 開發實戰
PDF
Git 入门实战
PPTX
大家應該都要會的工具 Git 從放棄到會用2-分支篇
PDF
為自己學 Git
PPT
Cocoa on Rails 4th
PDF
像Hackers一样写博客-hustcalm
PPTX
Git Flow 管理
PDF
Git 版本控制 (使用教學)
PDF
在 DigitalOcean 架設 Gitlab
PPTX
Android 程式設計(4)
PPT
Github简介及实用入门
PDF
Git 版本控制系統 -- 從微觀到宏觀
PPTX
Git 使用介绍
PPTX
Github簡介
PPTX
Git introduction
PPTX
构建网络工具箱
Bootstrap個人網站 20141117
First meetingwithgit
Learning to Use Git | WeiYuan
Android studio & Git in Windows
Visual Studio 2015 與 Git 開發實戰
Git 入门实战
大家應該都要會的工具 Git 從放棄到會用2-分支篇
為自己學 Git
Cocoa on Rails 4th
像Hackers一样写博客-hustcalm
Git Flow 管理
Git 版本控制 (使用教學)
在 DigitalOcean 架設 Gitlab
Android 程式設計(4)
Github简介及实用入门
Git 版本控制系統 -- 從微觀到宏觀
Git 使用介绍
Github簡介
Git introduction
构建网络工具箱
Ad

GDSC Lecture - 與大家合作做專案之前必學_ Git 指令與觀念.pdf