SlideShare a Scribd company logo
Learning to Use Git
2017/09/06 (Wed.)
WeiYuan
site: v123582.github.io
line: weiwei63
§ 全端⼯程師 + 資料科學家
略懂⼀點網站前後端開發技術,學過資料探勘與機器
學習的⽪⽑。平時熱愛參與技術社群聚會及貢獻開源
程式的樂趣。
Outline
§ Version Control
§ The History of Version Control
§ Installation
§ About Git
§ Work Flow
§ Git Flow
§ Git GUI and Repo Host
3
Discuss
1. 如何做程式碼的檔案管理?
2. 如果要開發新功能又不想覆蓋掉原本的版本怎麼辦?
3. 萬一改一改發現改壞了會怎麼做?
4. 想要請別人幫我檢查這樣寫法有沒有問題要如何分享?
4
Outline
§ Version Control
§ The History of Version Control
§ Installation
§ About Git
§ Work Flow
§ Git Flow
§ Git GUI and Repo Host
5
Version Control
6
Version Control
7
Backup
Synchronize
Record
WHY ?
§ 檔案被別⼈或⾃⼰覆蓋,甚⾄遺失
§ 想復原前幾天寫的版本
§ 想知道跟昨天寫的差在哪裡?
§ 軟體發⾏時,可以⽅便管理不同版本
8
WHY ?
§ 檔案被別⼈或⾃⼰覆蓋,甚⾄遺失
• 多⼈協作時,不會把別⼈的東⻄蓋掉
§ 想復原前幾天寫的版本
• 可以隨時復原修改,回到之前的版本
§ 想知道跟昨天寫的差在哪裡?
• 保留修改歷史記錄,以供查詢
§ 軟體發⾏時,可以⽅便管理不同版本
• 軟體發⾏,需要分成維護版跟開發版
9
How ?
10
DistributedCentralized
Outline
§ Version Control
§ The History of Version Control
§ Installation
§ About Git
§ Work Flow
§ Git Flow
§ Git GUI and Repo Host
11
12
Localized
VCS
Centralized
VCS
Distributed
VCS
Localize VCS
• Cloud
• FTP
13
Localize VCS
• Cloud
• FTP
14
#Discuss: 你覺得「本地端」的版本控制可能會遇到什麼問題?
Centralized VCS
15
• CVS(Concurrent
Versions System)
• SVN(Subversion)
Centralized VCS
16
• CVS(Concurrent
Versions System)
• SVN(Subversion)
#Discuss: 你覺得「集中式」的版本控制可能會遇到什麼問題?
Distributed VCS
17
• Git
18
Centralized Distributed
19
Centralized Distributed
Outline
§ Version Control
§ The History of Version Control
§ Installation
§ About Git
§ Work Flow
§ Git Flow
§ Git GUI and Repo Host
20
Installation
21
1
2
3
$ brew install git
Installation
22
1
2
3
$ brew install git
• What is terminal?
• What is brew?
Config
23
1
2
3
$ git config --list
$ git config --global user.name "<name>"
$ git config --global user.email "<email>"
Config
24
1
2
3
$ git config --list
$ git config --global user.name "<name>"
$ git config --global user.email "<email>"
• Global Config
• Local Conig
Try it!
§ #練習:在你的電腦上確定 git 的安裝,並設定上⾃⼰的 git 資料。
25
Outline
§ Version Control
§ The History of Version Control
§ Installation
§ About Git
§ Work Flow
§ Git Flow
§ Git GUI and Repo Host
26
About Git
§ Git 由 Linus Torvalds (Linux 的核⼼開發者)所開發的新式版本
控制系統。Git為分散式版本控制系統,是為了更好管理Linux內
核⽽開發的。Git 可以把檔案的狀態作為更新歷史記錄保存起來。
因此可以把編輯過的檔案復原到以前的狀態,也可以顯⽰編輯過
內容的差異。⽽且,當有⼈想將編輯過的舊檔案上傳到伺服器、
覆蓋其他⼈的最新檔案時,系統會發出警告,因此可以避免在無
意中覆蓋他⼈的編輯內容。
27
§ Repository
• Local
• Remote
28
§ Working Tree
• Node/Blob/Flie
• Commit/Revision
29
§ Working Directory
• Untracked
• Modified
§ Staging Area
• Staged
§ Git Directory(Repository)
• Committed
30
§ Working Directory
• Untracked
• Modified
§ Staging Area
• Staged
§ Git Directory(Repository)
• Committed
31
§ Branch
• merge
• conflict
• resolve
32
§ Branch
• merge
• conflict
• resolve
33
§ Fork
§ Clone
§ Pull
§ Push
34
35
1
2
3
$ git status
$ git log
$ git diff
36
1
2
3
$ git commit -C HEAD -a –amend 'new commit'
$ git reset HEAD~2
$ git revert HEAD~2
Outline
§ Version Control
§ The History of Version Control
§ Installation
§ About Git
§ Work Flow
§ Git Flow
§ Git GUI and Repo Host
37
本機端的版本控制
38
1
2
3
$ mkdir demo & cd demo
$ git init # 初始化
$ ...
$ git status # 檢查目前的檔案狀態
$ git add . # 把所有更動過的檔案加入暫存區
$ git commit -a -m "<depiction>" # 存檔!
Try it!
§ #練習:修改上一次的 commit 訊息
39
Try it!
§ #練習:把新加入的檔案加到上一個 commit 版本內
40
Try it!
§ #練習:在 git 內加入一個空的目錄。
41
Try it!
§ #練習:在 git 內設定壹些項目不要被放到 repo。
42
Try it!
§ #練習: 取消 commit 。
43
Try it!
§ #練習: 回到上一個版本 。
44
本機端的分⽀操作
45
1
2
3
$ git branch <branch_name>
$ git checkout <branch_name>
$ ...
$ git checkout master
$ git merge <branch_name>
• merge
• rebase
Try it!
§ #練習: 建立一個 branch,做一些變化,再 commit 一次。
46
Try it!
§ #練習: 將剛剛的 branch 合併回 master。
47
遠端的版本控制
48
1
2
3
$ git clone <remote.git> <project>
$ cd <project>
$ git pull origin master
$ ...
$ git push origin master
Try it!
§ #練習: 從遠端拉 code 下來,做一些變化後 commit。
49
Try it!
§ #練習: 試著 push 上去,然後發現要先 pull 然後遇到衝突怎麼
辦?
50
與別⼈⼀起協作
§ 1. clone -> pull -> commit -> push
§ 2. clone -> pull -> branch -> commit -> push -> pull request
§ 3. fork -> clone -> pull -> branch -> commit -> push -> pull request
51
Try it!
§ #練習: 使用 github 提供的 git 教學跑一次流程
52
Try it!
§ #練習:
1. 建立一個資料夾,進去之後初始化 git
2. 進行一些變更後,在 commit 一次
3. 開一個 branch,做一些變更後 commit
4. 切回去 master,做一些變更後 commit
5. 把剛剛開的 branch merge 回 master
6. 到 github 上面開一個新的專案,把剛剛的資料夾 push 上去
53
Try it!
§ #練習:
1. 在 github 上面開一個新的專案
2. 將專案 clone 下來
3. 進行一些變更後,在 commit 一次
4. 開一個 branch,做一些變更後 commit
5. 切回去 master,做一些變更後 commit
6. 把剛剛開的 branch merge 回 master
7. 把⺫前的資料夾 push 回 github
54
Try it!
§ #練習:承上題
1. 離開⺫前的資料夾,在 clone ⼀次剛剛的 github 專案
2. 開⼀個新的 branch,進⾏變更後 commit
3. 把這個 branch push 到 github 上⾯
4. 在 github 上,發起 PR,merge 回 master
5. 回到上⼀題的資料夾,進⾏變更後 commit
6. push 回 github 上⾯
55
Try it!
§ #練習:
1. fork ⼀份我的 github 檔案到你的 github 帳號
2. clone 下來,開⼀個 branch 進⾏⼀些變更後 commit
3. push 回去你的 github 帳號,發起⼀個 PR 回 我的 github 帳
號
56
Outline
§ Version Control
§ The History of Version Control
§ Installation
§ About Git
§ Work Flow
§ Git Flow
§ GitHub and GitLab
57
58
59
Outline
§ Version Control
§ The History of Version Control
§ Installation
§ About Git
§ Work Flow
§ Git Flow
§ Git GUI and Repo Host
60
Repo Host
61
Git GUI
62
Thanks for listening.
2017/09/06 (Wed.) Learning to Use Git
Wei-Yuan Chang
v123582@gmail.com
v123582.github.io

More Related Content

What's hot (20)

PPTX
Visual Studio 2015 與 Git 開發實戰
Will Huang
 
PDF
連哈秋都懂的Git教學
hydai
 
PDF
版本控制 使用Git & git hub
維佋 唐
 
PPTX
Git基礎介紹
Max Ma
 
PDF
Git 簡介(古時候的簡報備份)
Hsin-lin Cheng
 
PDF
Git tutorial for windows user (給 Windows user 的 Git 教學)
Cloud Tu
 
PDF
Introduction to git
Bo-Yi Wu
 
PDF
A successful git branching model 導讀
Wen Liao
 
PPTX
Git & Sourcetree 介紹
Adison wu
 
PPTX
git merge 與 rebase 的觀念與實務應用
Will Huang
 
PDF
Git 入门实战
icy leaf
 
PPTX
Git 使用介绍
medcl
 
PDF
First meetingwithgit
Rhythm Sun
 
PDF
Git由超淺入超深
羊 小咩 (lamb-mei)
 
PPTX
Github簡介
Radian Jheng
 
PDF
Git and Github basic with SourceTree
Chu-Siang Lai
 
PDF
寫給大家的 Git 教學
littlebtc
 
PPTX
Jenkins x GitLab CI
Yihsuan Chen
 
PPTX
電子內容管理 使用Git 與 github 1
Alan Tsai
 
PDF
Git in a nutshell
Nelson Tai
 
Visual Studio 2015 與 Git 開發實戰
Will Huang
 
連哈秋都懂的Git教學
hydai
 
版本控制 使用Git & git hub
維佋 唐
 
Git基礎介紹
Max Ma
 
Git 簡介(古時候的簡報備份)
Hsin-lin Cheng
 
Git tutorial for windows user (給 Windows user 的 Git 教學)
Cloud Tu
 
Introduction to git
Bo-Yi Wu
 
A successful git branching model 導讀
Wen Liao
 
Git & Sourcetree 介紹
Adison wu
 
git merge 與 rebase 的觀念與實務應用
Will Huang
 
Git 入门实战
icy leaf
 
Git 使用介绍
medcl
 
First meetingwithgit
Rhythm Sun
 
Git由超淺入超深
羊 小咩 (lamb-mei)
 
Github簡介
Radian Jheng
 
Git and Github basic with SourceTree
Chu-Siang Lai
 
寫給大家的 Git 教學
littlebtc
 
Jenkins x GitLab CI
Yihsuan Chen
 
電子內容管理 使用Git 與 github 1
Alan Tsai
 
Git in a nutshell
Nelson Tai
 

Similar to Learning to Use Git | WeiYuan (20)

PDF
Git Tutorial
Drake Huang
 
PPTX
Git introduction
mythnc
 
PPTX
大家應該都要會的工具 Git 從放棄到會用1-基礎篇
Alan Tsai
 
PPTX
Git and git hub
唯 李
 
ODP
Git 程式碼版本控制軟體介紹
PingLun Liao
 
PDF
Git 版本控制系統 -- 從微觀到宏觀
Wen-Tien Chang
 
PPTX
Git &amp; git hub v1.2
Chris Chen
 
PPTX
Git入門介紹
mudream4869
 
PDF
Intro to Git 投影片
Tony Yeh
 
PPT
Git 超簡單學習懶人包(軟體程式版本控管系統)
flylon
 
ODP
Git 教學
Ming-Sian Lin
 
PDF
Git 入門與應用
Allen Chou
 
PDF
為自己學 Git
昀 李
 
PPTX
Git初步入門
recast203
 
PPTX
Introduction to Version Control System for Windows
Peter Chang
 
PDF
Yet another introduction to Git - from the bottom up
Wen-Tien Chang
 
ODP
Git basis - usage
Eason Cao
 
PPTX
Git & git flow
Amo Wu
 
PDF
COSCUP 2015 開源之道-Git工作坊教學簡報
Bachue Zhou
 
PPTX
GIT實務操作與理論
鵬 大
 
Git Tutorial
Drake Huang
 
Git introduction
mythnc
 
大家應該都要會的工具 Git 從放棄到會用1-基礎篇
Alan Tsai
 
Git and git hub
唯 李
 
Git 程式碼版本控制軟體介紹
PingLun Liao
 
Git 版本控制系統 -- 從微觀到宏觀
Wen-Tien Chang
 
Git &amp; git hub v1.2
Chris Chen
 
Git入門介紹
mudream4869
 
Intro to Git 投影片
Tony Yeh
 
Git 超簡單學習懶人包(軟體程式版本控管系統)
flylon
 
Git 教學
Ming-Sian Lin
 
Git 入門與應用
Allen Chou
 
為自己學 Git
昀 李
 
Git初步入門
recast203
 
Introduction to Version Control System for Windows
Peter Chang
 
Yet another introduction to Git - from the bottom up
Wen-Tien Chang
 
Git basis - usage
Eason Cao
 
Git & git flow
Amo Wu
 
COSCUP 2015 開源之道-Git工作坊教學簡報
Bachue Zhou
 
GIT實務操作與理論
鵬 大
 
Ad

More from Wei-Yuan Chang (20)

PDF
Python Fundamentals - Basic
Wei-Yuan Chang
 
PDF
Data Analysis with Python - Pandas | WeiYuan
Wei-Yuan Chang
 
PDF
Data Crawler using Python (I) | WeiYuan
Wei-Yuan Chang
 
PDF
Scientific Computing with Python - NumPy | WeiYuan
Wei-Yuan Chang
 
PDF
Basic Web Development | WeiYuan
Wei-Yuan Chang
 
PDF
資料視覺化 - D3 的第一堂課 | WeiYuan
Wei-Yuan Chang
 
PDF
JavaScript Beginner Tutorial | WeiYuan
Wei-Yuan Chang
 
PDF
Python fundamentals - basic | WeiYuan
Wei-Yuan Chang
 
PDF
Introduce to PredictionIO
Wei-Yuan Chang
 
PDF
Analysis and Classification of Respiratory Health Risks with Respect to Air P...
Wei-Yuan Chang
 
PDF
Forecasting Fine Grained Air Quality Based on Big Data
Wei-Yuan Chang
 
PDF
On the Coverage of Science in the Media a Big Data Study on the Impact of th...
Wei-Yuan Chang
 
PDF
On the Ground Validation of Online Diagnosis with Twitter and Medical Records
Wei-Yuan Chang
 
PDF
Effective Event Identification in Social Media
Wei-Yuan Chang
 
PDF
Eears (earthquake alert and report system) a real time decision support syst...
Wei-Yuan Chang
 
PDF
Fine Grained Location Extraction from Tweets with Temporal Awareness
Wei-Yuan Chang
 
PPTX
Practical Lessons from Predicting Clicks on Ads at Facebook
Wei-Yuan Chang
 
PDF
How many folders do you really need ? Classifying email into a handful of cat...
Wei-Yuan Chang
 
PDF
Extending faceted search to the general web
Wei-Yuan Chang
 
PDF
Discovering human places of interest from multimodal mobile phone data
Wei-Yuan Chang
 
Python Fundamentals - Basic
Wei-Yuan Chang
 
Data Analysis with Python - Pandas | WeiYuan
Wei-Yuan Chang
 
Data Crawler using Python (I) | WeiYuan
Wei-Yuan Chang
 
Scientific Computing with Python - NumPy | WeiYuan
Wei-Yuan Chang
 
Basic Web Development | WeiYuan
Wei-Yuan Chang
 
資料視覺化 - D3 的第一堂課 | WeiYuan
Wei-Yuan Chang
 
JavaScript Beginner Tutorial | WeiYuan
Wei-Yuan Chang
 
Python fundamentals - basic | WeiYuan
Wei-Yuan Chang
 
Introduce to PredictionIO
Wei-Yuan Chang
 
Analysis and Classification of Respiratory Health Risks with Respect to Air P...
Wei-Yuan Chang
 
Forecasting Fine Grained Air Quality Based on Big Data
Wei-Yuan Chang
 
On the Coverage of Science in the Media a Big Data Study on the Impact of th...
Wei-Yuan Chang
 
On the Ground Validation of Online Diagnosis with Twitter and Medical Records
Wei-Yuan Chang
 
Effective Event Identification in Social Media
Wei-Yuan Chang
 
Eears (earthquake alert and report system) a real time decision support syst...
Wei-Yuan Chang
 
Fine Grained Location Extraction from Tweets with Temporal Awareness
Wei-Yuan Chang
 
Practical Lessons from Predicting Clicks on Ads at Facebook
Wei-Yuan Chang
 
How many folders do you really need ? Classifying email into a handful of cat...
Wei-Yuan Chang
 
Extending faceted search to the general web
Wei-Yuan Chang
 
Discovering human places of interest from multimodal mobile phone data
Wei-Yuan Chang
 
Ad

Learning to Use Git | WeiYuan