SlideShare a Scribd company logo
1 of 50
Git Basics
Gitlab X SourceTree
Tom Chen <tom@ifp.io>
第一次安裝
產生金鑰 (SSH Key)
• 讓 Gitlab 認得你的電腦
• 一台電腦只需要做一次
• 產生一組 SSH 的 public/private Key
• 給 Gitlab public key, 配合自己電腦的 private key 就可以驗證 ok
• Tools  Create or Import SSH Keys
• 按下 Generate 在空白的地方隨便移動滑鼠來製造亂數
• 儲存 private key (Save Private Key), 隨便儲存一個檔名 (.ppk)
存檔的時候會問你
是否真的不要在每次存取金鑰的時候
用一個密碼保護?
如果你想要安全一點, 就設定一個密碼,
填在左圖中 Key passphrase 跟 Confirm passphrase 中
或者不要的話就… 以可以啦 orz
• 匯入 Public Key 到 Gitlab
Copy 這整段
點選 Profile Settings
點選 SSH Keys
點選 Add SSH Key
2. 剛剛 Copy 的貼上
1. 給個名字, 譬如 Work Machine (工作機) 之類的
3. 按下 Add Key, Gitlab 這邊匯入就大功告成
設定名稱跟 E-mail
2. 填寫你的全名跟 E-mail1. 去到 Tools -> Options
產生一個新的 Repository
點選 New Project
取一個好的名字, 通常全部小寫, 中間用 - 隔開
記得選 ifp (我們自己的 group)
預設就是 Private 就不用改了
最後按下 Create Project
最重要的就是這個網址了!!
按下 Clone / New
1. 貼上
3. 按下 Clone
2. 選好你希望他在本機端的哪個資料夾中
TADA!!!
新增檔案
• 假設本地端目錄在 C:UsersUserMy Documentstest-project
• 到這個目錄底下建立一些檔案
• 例如: test.txt, 打一些字並且存檔
還沒有被追蹤版本控管的檔案
按下 Add 把沒有被追蹤的加入版本控管
1. 按下 Commit 把這一次的變更編入版本控管
寫下這一次變更的註解
2. 按下 Commit 確認
按下 Push 把變更推到伺服器上
推到伺服器的 master 分支
這時候再去 Gitlab 的 Files 查看就看得到變更了!!
變更檔案
• 把剛才的 test.txt 更改一些內容
• 隨便新增一個檔案
SourceTree 會自動偵測變更
按下 Add 把目前的變更加入
1. 按下 Commit
2. 寫下這一次
變更的註解
3. 這邊打勾的話, 就可
以直接 Commit 的時候
順便 Push 到伺服器上
4. 按下 Commit 確認
在 Gitlab 的 Commits 可以看到每次變更的內容
拉變更 (pull)
• Repository 並不是只有你一個人在使用
• 也有可能有別人做了變更
• 你需要拉別人的變更下來 (pull)
Workflow
1. 從 Server Pull 下來
2. 按照原本的作業方式修改檔案, 新增檔案… 等等
3. 變更後的東西都在 Unstaged files, 把這一次的批次變更的檔案放到
Staged files
4. 進行 Commit 並且寫下這一次變更的註解
5. Push 到 Server
3 跟 4 可以用 Checkbox 勾選的方式一次一起做
也可以做了一大堆 1-3 之後再一次做 4 把一堆 push 到 server
.gitignore
• 如果是程式專案, 通常會從程式專案的目錄整個進到 git
• 但是有些檔案通常不會進到 repository, 例如
• 編譯後的檔案 (.o, .obj, .so, .lib, .dll, .pyc, …)
• 暫存檔 (.swp)
• 外掛套件 (node_modules)
• 某些設定檔
.gitignore
• 只要在 .gitignore 設定的就會被 git 忽略
• 說明文件
http://git-scm.com/docs/gitignore
• 打入關鍵字幫你產生 .gitignore 的服務
https://www.gitignore.io/
• github 上的 .gitignore 設定
https://github.com/github/gitignore
安全性
• 帳號密碼千萬別加到 repository
• Auth Key 也不要
• Cookie Secret 或任何 secret 類的都不要進到 repository
Markdown
同場加映
到 Wiki
• 內部用的文件別再用 Word 了
• 大家都編輯會有很多 Copy, 散落各處 (Google Docs 可解決)
• 超級難做出一致與精美的樣式
• 一直用滑鼠在調整字形大小、顏色…
• Markdown 只要依照他簡易的格式 + 別人寫好的樣式
• 看起來很乾淨
• 類似網頁有超連結的概念
• GitLab 裡頭還可以指向特定的檔案、程式碼的某一行或者是 Issue
• 版本控管
• https://gitlab.com/help/markdown/markdown
• 另外一個 Popular 的格式 reStructuredText (rst)
• http://sphinx-doc.org/rest.html
• 最後, 一個小分享
每週分享: 如何寫好程式碼的「Commit Message」?
https://passionbean.wordpress.com/2012/02/22/why-good-commit-
message/
• 版本控管使用方式很多種, 如果大家都有共識 follow 共同的方式
對大家來說會輕鬆很多 :D

More Related Content

What's hot

Git與source tree 基礎教學
Git與source tree 基礎教學Git與source tree 基礎教學
Git與source tree 基礎教學Duncan Chen
 
開發用不著打一架 - 分散式版本控制 Git
開發用不著打一架 - 分散式版本控制 Git開發用不著打一架 - 分散式版本控制 Git
開發用不著打一架 - 分散式版本控制 GitCalvin Huang
 
A successful git branching model 導讀
A successful git branching model 導讀A successful git branching model 導讀
A successful git branching model 導讀Wen Liao
 
初心者 Git 上手攻略
初心者 Git 上手攻略初心者 Git 上手攻略
初心者 Git 上手攻略Lucien Lee
 
Mercurial簡介與教學
Mercurial簡介與教學Mercurial簡介與教學
Mercurial簡介與教學芳本 林
 
Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀Wen-Tien Chang
 
Yet another introduction to Git - from the bottom up
Yet another introduction to Git - from the bottom upYet another introduction to Git - from the bottom up
Yet another introduction to Git - from the bottom upWen-Tien Chang
 
Git and git hub
Git and git hubGit and git hub
Git and git hub唯 李
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to gitBo-Yi Wu
 
寫給大家的 Git 教學
寫給大家的 Git 教學寫給大家的 Git 教學
寫給大家的 Git 教學littlebtc
 
Git & Sourcetree 介紹
Git & Sourcetree 介紹Git & Sourcetree 介紹
Git & Sourcetree 介紹Adison wu
 
git, repo, Gerrit 基礎教學
git, repo, Gerrit 基礎教學git, repo, Gerrit 基礎教學
git, repo, Gerrit 基礎教學Doremi Lin
 
Git基礎介紹
Git基礎介紹Git基礎介紹
Git基礎介紹Max Ma
 
git merge 與 rebase 的觀念與實務應用
git merge 與 rebase 的觀念與實務應用git merge 與 rebase 的觀念與實務應用
git merge 與 rebase 的觀念與實務應用Will Huang
 
Git flow 與團隊合作
Git flow 與團隊合作Git flow 與團隊合作
Git flow 與團隊合作Bo-Yi Wu
 
版本控制 使用Git & git hub
版本控制   使用Git & git hub版本控制   使用Git & git hub
版本控制 使用Git & git hub維佋 唐
 
連哈秋都懂的Git教學
連哈秋都懂的Git教學連哈秋都懂的Git教學
連哈秋都懂的Git教學hydai
 
幸福快樂的完美結局
幸福快樂的完美結局幸福快樂的完美結局
幸福快樂的完美結局Anna Su
 

What's hot (20)

Git與source tree 基礎教學
Git與source tree 基礎教學Git與source tree 基礎教學
Git與source tree 基礎教學
 
開發用不著打一架 - 分散式版本控制 Git
開發用不著打一架 - 分散式版本控制 Git開發用不著打一架 - 分散式版本控制 Git
開發用不著打一架 - 分散式版本控制 Git
 
A successful git branching model 導讀
A successful git branching model 導讀A successful git branching model 導讀
A successful git branching model 導讀
 
初心者 Git 上手攻略
初心者 Git 上手攻略初心者 Git 上手攻略
初心者 Git 上手攻略
 
Mercurial簡介與教學
Mercurial簡介與教學Mercurial簡介與教學
Mercurial簡介與教學
 
Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀
 
Yet another introduction to Git - from the bottom up
Yet another introduction to Git - from the bottom upYet another introduction to Git - from the bottom up
Yet another introduction to Git - from the bottom up
 
Git and git hub
Git and git hubGit and git hub
Git and git hub
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
寫給大家的 Git 教學
寫給大家的 Git 教學寫給大家的 Git 教學
寫給大家的 Git 教學
 
Git & Sourcetree 介紹
Git & Sourcetree 介紹Git & Sourcetree 介紹
Git & Sourcetree 介紹
 
git, repo, Gerrit 基礎教學
git, repo, Gerrit 基礎教學git, repo, Gerrit 基礎教學
git, repo, Gerrit 基礎教學
 
Git基礎介紹
Git基礎介紹Git基礎介紹
Git基礎介紹
 
git merge 與 rebase 的觀念與實務應用
git merge 與 rebase 的觀念與實務應用git merge 與 rebase 的觀念與實務應用
git merge 與 rebase 的觀念與實務應用
 
Git flow 與團隊合作
Git flow 與團隊合作Git flow 與團隊合作
Git flow 與團隊合作
 
版本控制 使用Git & git hub
版本控制   使用Git & git hub版本控制   使用Git & git hub
版本控制 使用Git & git hub
 
Git 經驗分享
Git 經驗分享Git 經驗分享
Git 經驗分享
 
連哈秋都懂的Git教學
連哈秋都懂的Git教學連哈秋都懂的Git教學
連哈秋都懂的Git教學
 
幸福快樂的完美結局
幸福快樂的完美結局幸福快樂的完美結局
幸福快樂的完美結局
 
Git由超淺入超深
Git由超淺入超深Git由超淺入超深
Git由超淺入超深
 

Viewers also liked

真蝦意外接到的Case
真蝦意外接到的Case真蝦意外接到的Case
真蝦意外接到的CaseTom Chen
 
Live Performance Effects
Live Performance EffectsLive Performance Effects
Live Performance EffectsTom Chen
 
Pytables
PytablesPytables
Pytablesgowell
 
Command line 初級寶典
Command line 初級寶典Command line 初級寶典
Command line 初級寶典Tom Chen
 
Introduction to Gitlab
Introduction to GitlabIntroduction to Gitlab
Introduction to GitlabJulien Pivotto
 
Elasticsearch intro output
Elasticsearch intro outputElasticsearch intro output
Elasticsearch intro outputTom Chen
 
Two scoops of django Introduction
Two scoops of django IntroductionTwo scoops of django Introduction
Two scoops of django Introductionflywindy
 
Two scoops of Django - Deployment
Two scoops of Django - DeploymentTwo scoops of Django - Deployment
Two scoops of Django - Deploymentflywindy
 
AngularJS Sharing
AngularJS SharingAngularJS Sharing
AngularJS SharingTom Chen
 
Working with the django admin
Working with the django admin Working with the django admin
Working with the django admin flywindy
 
愛樂工程師
愛樂工程師愛樂工程師
愛樂工程師Tom Chen
 
Django 實戰 - 自己的購物網站自己做
Django 實戰 - 自己的購物網站自己做Django 實戰 - 自己的購物網站自己做
Django 實戰 - 自己的購物網站自己做flywindy
 
Integrating tornado and webpack
Integrating tornado and webpackIntegrating tornado and webpack
Integrating tornado and webpackTom Chen
 
那些年,我用 Django Admin 接的案子
那些年,我用 Django Admin 接的案子那些年,我用 Django Admin 接的案子
那些年,我用 Django Admin 接的案子flywindy
 
Learning django step 1
Learning django step 1Learning django step 1
Learning django step 1永昇 陳
 
Django workshop homework 3
Django workshop homework 3Django workshop homework 3
Django workshop homework 3flywindy
 

Viewers also liked (20)

Introduction to Git (part 1)
Introduction to Git (part 1)Introduction to Git (part 1)
Introduction to Git (part 1)
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
真蝦意外接到的Case
真蝦意外接到的Case真蝦意外接到的Case
真蝦意外接到的Case
 
Live Performance Effects
Live Performance EffectsLive Performance Effects
Live Performance Effects
 
Pytables
PytablesPytables
Pytables
 
Xmas
XmasXmas
Xmas
 
Command line 初級寶典
Command line 初級寶典Command line 初級寶典
Command line 初級寶典
 
Introduction to Gitlab
Introduction to GitlabIntroduction to Gitlab
Introduction to Gitlab
 
Elasticsearch intro output
Elasticsearch intro outputElasticsearch intro output
Elasticsearch intro output
 
Two scoops of django Introduction
Two scoops of django IntroductionTwo scoops of django Introduction
Two scoops of django Introduction
 
Two scoops of Django - Deployment
Two scoops of Django - DeploymentTwo scoops of Django - Deployment
Two scoops of Django - Deployment
 
AngularJS Sharing
AngularJS SharingAngularJS Sharing
AngularJS Sharing
 
Django step0
Django step0Django step0
Django step0
 
Working with the django admin
Working with the django admin Working with the django admin
Working with the django admin
 
愛樂工程師
愛樂工程師愛樂工程師
愛樂工程師
 
Django 實戰 - 自己的購物網站自己做
Django 實戰 - 自己的購物網站自己做Django 實戰 - 自己的購物網站自己做
Django 實戰 - 自己的購物網站自己做
 
Integrating tornado and webpack
Integrating tornado and webpackIntegrating tornado and webpack
Integrating tornado and webpack
 
那些年,我用 Django Admin 接的案子
那些年,我用 Django Admin 接的案子那些年,我用 Django Admin 接的案子
那些年,我用 Django Admin 接的案子
 
Learning django step 1
Learning django step 1Learning django step 1
Learning django step 1
 
Django workshop homework 3
Django workshop homework 3Django workshop homework 3
Django workshop homework 3
 

Similar to Gitlab

COSCUP 2015 開源之道-Git工作坊教學簡報
COSCUP 2015 開源之道-Git工作坊教學簡報COSCUP 2015 開源之道-Git工作坊教學簡報
COSCUP 2015 開源之道-Git工作坊教學簡報Bachue Zhou
 
Learning to Use Git | WeiYuan
Learning to Use Git | WeiYuanLearning to Use Git | WeiYuan
Learning to Use Git | WeiYuanWei-Yuan Chang
 
CICD Workshop 20180922
CICD Workshop 20180922CICD Workshop 20180922
CICD Workshop 20180922Earou Huang
 
Git 使用介绍
Git 使用介绍Git 使用介绍
Git 使用介绍medcl
 
Github简介及实用入门
Github简介及实用入门Github简介及实用入门
Github简介及实用入门Rongxing Liu
 
Git 入门实战
Git 入门实战Git 入门实战
Git 入门实战icy leaf
 
為自己學 Git
為自己學 Git為自己學 Git
為自己學 Git昀 李
 
FHIR Server 安裝與使用
FHIR Server 安裝與使用FHIR Server 安裝與使用
FHIR Server 安裝與使用Lorex L. Yang
 
Visual Studio Code 快速上手指南
Visual Studio Code 快速上手指南Visual Studio Code 快速上手指南
Visual Studio Code 快速上手指南Shengyou Fan
 
Learn git
Learn gitLearn git
Learn git甘 李
 
Continuous Delivery with Ansible x GitLab CI (2e)
Continuous Delivery with Ansible x GitLab CI (2e)Continuous Delivery with Ansible x GitLab CI (2e)
Continuous Delivery with Ansible x GitLab CI (2e)Chu-Siang Lai
 
Git&Github Tutorial
Git&Github TutorialGit&Github Tutorial
Git&Github TutorialTing Wen Su
 
大家應該都要會的工具 Git 從放棄到會用1-基礎篇
大家應該都要會的工具 Git   從放棄到會用1-基礎篇大家應該都要會的工具 Git   從放棄到會用1-基礎篇
大家應該都要會的工具 Git 從放棄到會用1-基礎篇Alan Tsai
 
Software Engineer Talk
Software Engineer TalkSoftware Engineer Talk
Software Engineer TalkLarry Cai
 
Git & git flow
Git & git flowGit & git flow
Git & git flowAmo Wu
 
Android 程式設計(4)
Android 程式設計(4)Android 程式設計(4)
Android 程式設計(4)Roy Wang
 

Similar to Gitlab (20)

COSCUP 2015 開源之道-Git工作坊教學簡報
COSCUP 2015 開源之道-Git工作坊教學簡報COSCUP 2015 開源之道-Git工作坊教學簡報
COSCUP 2015 開源之道-Git工作坊教學簡報
 
Learning to Use Git | WeiYuan
Learning to Use Git | WeiYuanLearning to Use Git | WeiYuan
Learning to Use Git | WeiYuan
 
CICD Workshop 20180922
CICD Workshop 20180922CICD Workshop 20180922
CICD Workshop 20180922
 
Git 使用介绍
Git 使用介绍Git 使用介绍
Git 使用介绍
 
Github简介及实用入门
Github简介及实用入门Github简介及实用入门
Github简介及实用入门
 
Git 入门实战
Git 入门实战Git 入门实战
Git 入门实战
 
Git基础培训
Git基础培训Git基础培训
Git基础培训
 
為自己學 Git
為自己學 Git為自己學 Git
為自己學 Git
 
FHIR Server 安裝與使用
FHIR Server 安裝與使用FHIR Server 安裝與使用
FHIR Server 安裝與使用
 
Visual Studio Code 快速上手指南
Visual Studio Code 快速上手指南Visual Studio Code 快速上手指南
Visual Studio Code 快速上手指南
 
Learn git
Learn gitLearn git
Learn git
 
Continuous Delivery with Ansible x GitLab CI (2e)
Continuous Delivery with Ansible x GitLab CI (2e)Continuous Delivery with Ansible x GitLab CI (2e)
Continuous Delivery with Ansible x GitLab CI (2e)
 
Git&Github Tutorial
Git&Github TutorialGit&Github Tutorial
Git&Github Tutorial
 
Cocoa on Rails 4th
Cocoa on Rails 4thCocoa on Rails 4th
Cocoa on Rails 4th
 
Git教學
Git教學Git教學
Git教學
 
大家應該都要會的工具 Git 從放棄到會用1-基礎篇
大家應該都要會的工具 Git   從放棄到會用1-基礎篇大家應該都要會的工具 Git   從放棄到會用1-基礎篇
大家應該都要會的工具 Git 從放棄到會用1-基礎篇
 
Software Engineer Talk
Software Engineer TalkSoftware Engineer Talk
Software Engineer Talk
 
Git & git flow
Git & git flowGit & git flow
Git & git flow
 
Android 程式設計(4)
Android 程式設計(4)Android 程式設計(4)
Android 程式設計(4)
 
Git Tutorial
Git TutorialGit Tutorial
Git Tutorial
 

Gitlab