SlideShare a Scribd company logo
Git & Github
基礎教學
蘇⿍鼎⽂文
Git
• 版本控制⼯工具,採⽤用分布式版本庫(與CVS、
Subversion不同)
• 永遠不再弄丟你們的程式碼
• 每個⼈人都可以了解修改過程(包跨未來的學弟妹)
好處
• 可追蹤、回復每個⼈人所做過的網⾴頁更動
• ⽤用Branch確保網⾴頁處在Deployable的狀態
• 發佈issue記錄Bug問題、未來⺫⽬目標
• 可以將⽂文件寫在Wiki上⾯面
• 可以⽤用在備份MySql資料庫的部分
• 只需要將repository傳給下⼀一個組別即可完成交接
Install
• 直接安裝 GitHub for Windows ⼯工具,
• 內建⼀一個以 Windows PowerShell 為主的 Git Shell
執⾏行環境,已內建 Git for Windows ⼯工具
• 或你想在CMD直接下指令的話可以安裝msysGit
Git Basic
• init & add
• Commit
• Branch
• Merge
• Reset
新增local repository
• git init
• 產⽣生⼀一個.git隱藏資料夾 所有版本記錄內容都在裡
⾯面(勿刪!!)
新增檔案
• Git 會找到資料夾所有的檔案,但你要告訴他你想追蹤
更動的檔案
• EX: Git add xxx.html
• 當你有不想被追蹤的檔案格式或資料夾的時候
(.JPG、.xml)新增⼀一個.gitignore檔案裡寫下你不想要
被追蹤的部分
• EX: 

/bin 

.jpg
Commit
• 在已追蹤的檔案產⽣生了更動的時候,需要將庚動
作⼀一次提交(Commit),提交過後檔案才會被記錄
下來
• git commit -m “第⼀一次提交”
commit 8044c7b9c6ed1907836b546811d560679caf0ae6
Author: de <dfd>
Date: Thu Jun 19 16:27:46 2014 +0800
Commit Example I
Commit Example II
• After git Commit, C2變成最新的Commit
• Master分⽀支指向C2
Tips
• 做⼀一個⼩小功能修改就建⽴立版本,這樣才容易追蹤
變更
• 千萬不要累積⼀一⼤大堆修改後才建⽴立⼀一個「⼤大版本」
• 有邏輯、有順序的修正功能,確保相關的版本修
正可以按順序提交(commit),這樣才便於追蹤
Branch
• Branch 很好⽤用,開 Branch 不⽤用錢
• git branch <new_branch_name>
• git checkout <branch_name>

(注意到如果你有檔案修改了卻還沒 commit,會
不能切換 branch solution git stash ;git stash pop)
Tips
• ⺟母Branch永遠是 “master”<-當作最穩定的版本
• 帶有實驗性質的變更,例如想改寫新的演算法、
重構程式碼等
• 新功能 feature 開發
• Bug fixes,你可能需要做些實驗才知道到底怎麼
修。等 Bugs 修正後,在透過「合併」的⽅方式將
bugfix 分⽀支上的變更重新套⽤用到 master 上⾯面
Merge
• 兩個分⽀支合併成⼀一個。
• git merge [另⼀一個分⽀支]
• 若是無任何衝突,會⾃自動產⽣生⼀一個merge commit
• ⼿手動將另⼀一個分⽀支給移除,這樣才符合「兩個分⽀支合併成
⼀一個」的概念。
衝突發⽣生
• 當⽀支線合併時有在同個地⽅方卻是不同的內容的時候就會
產⽣生衝突
• 從<<<<<<< HEAD 到 ======= 的內容

代表 HEAD 裡 a.txt 的內容。註:HEAD 代表當前
master 分⽀支的最新版。
• 從 ======= 到 >>>>>>> hotfixes 的內容,代表
hotfixes 分⽀支裡 a.txt 的內容
• 這時就需要⼈人⼯工檢視⼿手動把這些衝突的檔案改好
⼈人⾮非聖賢 孰能無過?
• Git 提供更多「修正版本記錄」的機制,讓你在「分享」版本
給其他⼈人的時候,能夠預先做個整理。讓版本提交到遠端伺服
器上的時候,就已經是完美的版本狀態。
• 不⼩小⼼心執⾏行了 git commit 動作,但還有些檔案忘了加進去 (git
add [filepath]) 或只是紀錄訊息寫錯,想重新補上的話,直接
執⾏行 git commit --amend 即可
• git reset --hard “HEAD^" HEAD 指向的位址改到了前⼀一個版本
( HEAD^ ) 最新版本就會被刪除了[被刪除的提交還是存在 git
reset --hard ORIG_HEAD]就⾏行了
·• 當你「分享」特定分支給其他人之後,這些「已分享」的版本
歷史紀錄就別再改了!!
Github
• 全世界最多⼈人採⽤用的 Git 線上管理平台
• 包含了完整的 Git 遠端儲存庫實作,還有完整的議
題追蹤機制與報表
• 剛剛所講的指令Github都已經提供圖形化界⾯面來
操作
• 下載:https://windows.github.com
Git&Github Tutorial
Remote & Local
Remote
[Github]
Coworker Coworker Server
push/pull

(Sync)
clone
Issue Tracking
• ⼈人的腦袋是有限度的,網站開發者也是⼀一樣,事
情⼀一多就會亂掉
• 給開發者下⼀一步的動作,幫助開發者記住他們接
下來要做的事情
• 到 issue tracker 上⾯面回報您希望開發者做的事
情-諸如修正網站問題,或是希望網站有新功能
Issue Tracking
Git&Github Tutorial
• 標題,務必取⼀一個讓⼈人⼀一⺫⽬目了然的標題。
• 下⾯面是內容,如果是網站有問題,請務必告訴:您使⽤用哪種
瀏覽器?您的使⽤用環境為何?怎樣的步驟可以看到這個問題?
這些描述有助於幫助找到問題點。如果有圖⽚片更好,可以點
選底下的「choose an image」上傳圖⽚片。
• issue可隨時編輯
• 每個issue都有編號,可⽤用#標⽰示
如果問題解決了,就點選「Close」這個選項,

把問題給關閉吧!
⽂文件管理
• 希望你們將⽂文件寫在Github Wiki上⾯面,並且維持
在最新版本上,EX:
• 系統操作流程
• 功能操作、規格說明
• 伺服器規格(適⽤用的PHP、APACHE、MYSQL版
本)
Wiki
Git 教學資源
• http://pcottle.github.io/learnGitBranching/
• http://blog.miniasp.com/post/2013/08/19/
Learning-Git-Part-1-Installation-Options-Tool-
Usage-on-Local.aspx
• http://blog.miniasp.com/post/2013/11/04/
Learning-Git-Part-2-Master-Git-in-30-days.aspx
Ad

Recommended

開發用不著打一架 - 分散式版本控制 Git
開發用不著打一架 - 分散式版本控制 Git
Calvin Huang
 
Git與source tree 基礎教學
Git與source tree 基礎教學
Duncan Chen
 
寫給大家的 Git 教學
寫給大家的 Git 教學
littlebtc
 
Xcode 的 git 版本管理
Xcode 的 git 版本管理
彼得潘 Pan
 
Visual Studio 2015 與 Git 開發實戰
Visual Studio 2015 與 Git 開發實戰
Will Huang
 
把玩 Jenkins CI
把玩 Jenkins CI
Hao Lee
 
Docker基礎
Docker基礎
Perry Tsai
 
DevOps Taiwan CICD Pipeline Tools
DevOps Taiwan CICD Pipeline Tools
scott liao
 
Rancher 快速打造叢集的解決方案
Rancher 快速打造叢集的解決方案
Miles Chou
 
開發人員不可不知的 Windows Container 容器技術預覽
開發人員不可不知的 Windows Container 容器技術預覽
Will Huang
 
Git & Sourcetree 介紹
Git & Sourcetree 介紹
Adison wu
 
Intro to Git 投影片
Intro to Git 投影片
Tony Yeh
 
工程師必備第一工具 - Git
工程師必備第一工具 - Git
Alan Tsai
 
Azure Web App on Linux @ Global Azure Bootcamp 2017 Taiwan
Azure Web App on Linux @ Global Azure Bootcamp 2017 Taiwan
Will Huang
 
git, repo, Gerrit 基礎教學
git, repo, Gerrit 基礎教學
Doremi Lin
 
Android 程式設計(4)
Android 程式設計(4)
Roy Wang
 
Mercurial簡介與教學
Mercurial簡介與教學
芳本 林
 
Git 入門與實作
Git 入門與實作
奕浦 郭
 
Use Git-flow Manage Your Git Workflow
Use Git-flow Manage Your Git Workflow
Liangjun Jiang
 
A successful git branching model 導讀
A successful git branching model 導讀
Wen Liao
 
Gitlab
Gitlab
Tom Chen
 
Angular 4 網站開發最佳實務 (Modern Web 2017)
Angular 4 網站開發最佳實務 (Modern Web 2017)
Will Huang
 
Rancher: 建立你的牧場艦隊
Rancher: 建立你的牧場艦隊
Miles Chou
 
初探Jenkins
初探Jenkins
Huang Bruce
 
初心者 Git 上手攻略
初心者 Git 上手攻略
Lucien Lee
 
Git 使用介绍
Git 使用介绍
medcl
 
Git 版本控制 (使用教學)
Git 版本控制 (使用教學)
Jui An Huang (黃瑞安)
 
Git Flow 管理
Git Flow 管理
Pu Lee
 
Semantic video classification based on subtitles and domain terminologies
Semantic video classification based on subtitles and domain terminologies
Ting Wen Su
 
A complex network approach to text summarization
A complex network approach to text summarization
Ting Wen Su
 

More Related Content

What's hot (20)

Rancher 快速打造叢集的解決方案
Rancher 快速打造叢集的解決方案
Miles Chou
 
開發人員不可不知的 Windows Container 容器技術預覽
開發人員不可不知的 Windows Container 容器技術預覽
Will Huang
 
Git & Sourcetree 介紹
Git & Sourcetree 介紹
Adison wu
 
Intro to Git 投影片
Intro to Git 投影片
Tony Yeh
 
工程師必備第一工具 - Git
工程師必備第一工具 - Git
Alan Tsai
 
Azure Web App on Linux @ Global Azure Bootcamp 2017 Taiwan
Azure Web App on Linux @ Global Azure Bootcamp 2017 Taiwan
Will Huang
 
git, repo, Gerrit 基礎教學
git, repo, Gerrit 基礎教學
Doremi Lin
 
Android 程式設計(4)
Android 程式設計(4)
Roy Wang
 
Mercurial簡介與教學
Mercurial簡介與教學
芳本 林
 
Git 入門與實作
Git 入門與實作
奕浦 郭
 
Use Git-flow Manage Your Git Workflow
Use Git-flow Manage Your Git Workflow
Liangjun Jiang
 
A successful git branching model 導讀
A successful git branching model 導讀
Wen Liao
 
Gitlab
Gitlab
Tom Chen
 
Angular 4 網站開發最佳實務 (Modern Web 2017)
Angular 4 網站開發最佳實務 (Modern Web 2017)
Will Huang
 
Rancher: 建立你的牧場艦隊
Rancher: 建立你的牧場艦隊
Miles Chou
 
初探Jenkins
初探Jenkins
Huang Bruce
 
初心者 Git 上手攻略
初心者 Git 上手攻略
Lucien Lee
 
Git 使用介绍
Git 使用介绍
medcl
 
Git 版本控制 (使用教學)
Git 版本控制 (使用教學)
Jui An Huang (黃瑞安)
 
Git Flow 管理
Git Flow 管理
Pu Lee
 
Rancher 快速打造叢集的解決方案
Rancher 快速打造叢集的解決方案
Miles Chou
 
開發人員不可不知的 Windows Container 容器技術預覽
開發人員不可不知的 Windows Container 容器技術預覽
Will Huang
 
Git & Sourcetree 介紹
Git & Sourcetree 介紹
Adison wu
 
Intro to Git 投影片
Intro to Git 投影片
Tony Yeh
 
工程師必備第一工具 - Git
工程師必備第一工具 - Git
Alan Tsai
 
Azure Web App on Linux @ Global Azure Bootcamp 2017 Taiwan
Azure Web App on Linux @ Global Azure Bootcamp 2017 Taiwan
Will Huang
 
git, repo, Gerrit 基礎教學
git, repo, Gerrit 基礎教學
Doremi Lin
 
Android 程式設計(4)
Android 程式設計(4)
Roy Wang
 
Mercurial簡介與教學
Mercurial簡介與教學
芳本 林
 
Git 入門與實作
Git 入門與實作
奕浦 郭
 
Use Git-flow Manage Your Git Workflow
Use Git-flow Manage Your Git Workflow
Liangjun Jiang
 
A successful git branching model 導讀
A successful git branching model 導讀
Wen Liao
 
Angular 4 網站開發最佳實務 (Modern Web 2017)
Angular 4 網站開發最佳實務 (Modern Web 2017)
Will Huang
 
Rancher: 建立你的牧場艦隊
Rancher: 建立你的牧場艦隊
Miles Chou
 
初心者 Git 上手攻略
初心者 Git 上手攻略
Lucien Lee
 
Git 使用介绍
Git 使用介绍
medcl
 
Git Flow 管理
Git Flow 管理
Pu Lee
 

Viewers also liked (18)

Semantic video classification based on subtitles and domain terminologies
Semantic video classification based on subtitles and domain terminologies
Ting Wen Su
 
A complex network approach to text summarization
A complex network approach to text summarization
Ting Wen Su
 
About me
About me
rachelw057
 
Presentación1
Presentación1
machado-109
 
Memahami etimologi multimedia 1
Memahami etimologi multimedia 1
kopishare
 
Dore Dore case study
Dore Dore case study
Rupam Jash l CSCA
 
Fruits and veggies in bc
Fruits and veggies in bc
rachelw057
 
Work system design
Work system design
Rupam Jash l CSCA
 
Chopra Meindl Chapter 6
Chopra Meindl Chapter 6
Rupam Jash l CSCA
 
Chopra Meindl Chapter 5
Chopra Meindl Chapter 5
Rupam Jash l CSCA
 
Chopra Meindl Chapter 9
Chopra Meindl Chapter 9
Rupam Jash l CSCA
 
Chopra Meindl Chapter 2
Chopra Meindl Chapter 2
Rupam Jash l CSCA
 
Chopra Meindl Chapter 8
Chopra Meindl Chapter 8
Rupam Jash l CSCA
 
Chopra Meindl Chapter 3
Chopra Meindl Chapter 3
Rupam Jash l CSCA
 
Chopra Meindl Chapter 4
Chopra Meindl Chapter 4
Rupam Jash l CSCA
 
Chopra Meindl Chapter 1
Chopra Meindl Chapter 1
Rupam Jash l CSCA
 
Chopra Meindl Chapter 10
Chopra Meindl Chapter 10
Rupam Jash l CSCA
 
About strategy
About strategy
Chris Chang
 
Semantic video classification based on subtitles and domain terminologies
Semantic video classification based on subtitles and domain terminologies
Ting Wen Su
 
A complex network approach to text summarization
A complex network approach to text summarization
Ting Wen Su
 
Memahami etimologi multimedia 1
Memahami etimologi multimedia 1
kopishare
 
Fruits and veggies in bc
Fruits and veggies in bc
rachelw057
 
Ad

Similar to Git&Github Tutorial (20)

版本控制 使用Git & git hub
版本控制 使用Git & git hub
維佋 唐
 
Git introduction
Git introduction
mythnc
 
Git Tutorial
Git Tutorial
Drake Huang
 
Git 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹
PingLun Liao
 
Git初步入門
Git初步入門
recast203
 
Git 簡介(古時候的簡報備份)
Git 簡介(古時候的簡報備份)
Hsin-lin Cheng
 
Github簡介
Github簡介
Radian Jheng
 
Learning to Use Git | WeiYuan
Learning to Use Git | WeiYuan
Wei-Yuan Chang
 
Git &amp; git hub v1.2
Git &amp; git hub v1.2
Chris Chen
 
為自己學 Git
為自己學 Git
昀 李
 
Git and git hub
Git and git hub
唯 李
 
Introduction to git
Introduction to git
Bo-Yi Wu
 
Git 教學
Git 教學
Ming-Sian Lin
 
Git in a nutshell
Git in a nutshell
Nelson Tai
 
COSCUP 2015 開源之道-Git工作坊教學簡報
COSCUP 2015 開源之道-Git工作坊教學簡報
Bachue Zhou
 
Git tutorial for windows user (給 Windows user 的 Git 教學)
Git tutorial for windows user (給 Windows user 的 Git 教學)
Cloud Tu
 
20150313 ian git
20150313 ian git
LearningTech
 
Git and Github basic with SourceTree
Git and Github basic with SourceTree
Chu-Siang Lai
 
Git 好吃嗎
Git 好吃嗎
Szuping Wang
 
Git 入門與應用
Git 入門與應用
Allen Chou
 
版本控制 使用Git & git hub
版本控制 使用Git & git hub
維佋 唐
 
Git introduction
Git introduction
mythnc
 
Git 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹
PingLun Liao
 
Git初步入門
Git初步入門
recast203
 
Git 簡介(古時候的簡報備份)
Git 簡介(古時候的簡報備份)
Hsin-lin Cheng
 
Learning to Use Git | WeiYuan
Learning to Use Git | WeiYuan
Wei-Yuan Chang
 
Git &amp; git hub v1.2
Git &amp; git hub v1.2
Chris Chen
 
為自己學 Git
為自己學 Git
昀 李
 
Git and git hub
Git and git hub
唯 李
 
Introduction to git
Introduction to git
Bo-Yi Wu
 
Git in a nutshell
Git in a nutshell
Nelson Tai
 
COSCUP 2015 開源之道-Git工作坊教學簡報
COSCUP 2015 開源之道-Git工作坊教學簡報
Bachue Zhou
 
Git tutorial for windows user (給 Windows user 的 Git 教學)
Git tutorial for windows user (給 Windows user 的 Git 教學)
Cloud Tu
 
Git and Github basic with SourceTree
Git and Github basic with SourceTree
Chu-Siang Lai
 
Git 入門與應用
Git 入門與應用
Allen Chou
 
Ad

Git&Github Tutorial