Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Git and GitHub Basic with SourceTree

Git and GitHub Basic with SourceTree

這是一份寫給 Git 新手的入門簡報。相信藉由 SourceTree 這套圖形化的版本控制工具,可降低不少入門時的門壏。
 
* Blog - http://note.drx.tw/2015/05/git-and-github-basic-with-sourcetree.html

Chu-Siang Lai

April 29, 2015
Tweet

More Decks by Chu-Siang Lai

Other Decks in Technology

Transcript

  1. [ chusiang@nsysucm ~ ] $ cat .profile
    # Author: 㲺Ռᗼ / chusiang.lai (at) gmail.com
    # Blog: http://note.drx.tw
    # Modified: 2015-04-29 17:50
    GitHub
    &
    Bacis with SourceTree
    1

    View full-size slide

  2. 橕ෝ㲺Ռᗼ
    • 5 ଙ犥Ӥጱ Git ֵአ妿涢牐
    • 獮 Foxconn 敟誢ૡ纷䒍牐
    • 匍肬 DrSays IT ૡ纷䒍牐
    • ፘ橕֢ߝ޾茐֢物
    • LifeZMD
    • @be_vimmer_tw
    • ̽ਠ獊አ GNU/Linux ૡ֢̾
    • 㲺Ռጱ執懿
    2

    View full-size slide

  3. 伛猋অӞ矐绗ᒌ㻟牫樄ত㾏牦
    3

    View full-size slide

  4. Outline
    I. Git ฎՋ讕?
    II. GitHub ݈ฎՋ讕?
    III. Git & GitHub ݢ犥ெ讕ሻ?
    IV. 10 ೗౮傶 Git य़䒍牐
    V. GitHub 褰璤介涢牐
    4

    View full-size slide

  5. Ⅰ. Git ฎՋ讕?
    5

    View full-size slide

  6. –Wikipedia
    Git ฎӞ㮆獤碂ୗ粚๜矒ګ敟誢牧磧ڡኧ຋羳ේ牨
    箓絮艌 (Linus Torvalds) 獺֢牧ෝ 2005 ଙ犥 GPL
    朰ڊ牐磧ڡฎ傶ԧๅ磪硳ሲጱᓕቘ Linux Kernel 樄
    咳ᘒ戔懯ጱ牐
    6

    View full-size slide

  7. Git ฎՋ讕?
    • SCM (Source Code Management, Software
    Configuration Management)
    • VCS (Version Control Software)
    • 獤碂ୗጱ粚๜矒ګ羬翄
    • ᛔኧ敟誢 (GPL License)
    7
    ྭ襑 Server牧ݢ櫝娄ֵአ
    犋ொᤩ薛䥁牏犋ொ౮傶敟誢疅㱾

    View full-size slide

  8. ䷱磪粚๜矒ᓕጱӮኴ
    य़疑᮷妿稲螂ጱ̿ಋ䵝̀ଙդ
    8

    View full-size slide

  9. 9
    䲆礯䄸
    粚๜矒ګ
    翕᪠臻蟠
    粚๜矒ګ
    • FTP 粚๜矒ګ
    • 瓟婘䲆粚๜矒ګ
    • Google 襇ᒒᏝ繕粚๜矒ګ
    • Dropbox 粚๜矒ګ
    • ...

    View full-size slide

  10. ᮎ֖ሴҨұک皈ฎࣁ䌃Ջ讕ࠡ牦
    10

    View full-size slide

  11. 磪 SVN ጱӮኴ
    य़疑᮷妿稲螂ጱ̿ಋ䵝̀ଙդ #2
    11

    View full-size slide

  12. ䷱磪翕᪠ฎᥝெ讕䌃 code ࠡ牦牦
    12

    View full-size slide

  13. 磪 Git ጱӮኴ
    ಋ䵝? 粋 code? 猖猖獤ጱ竃༩
    13

    View full-size slide

  14. 抑? ࣁ֜碻?
    ᛔ౯硼蝄
    狶ԧՋ讕?
    ࣁ Git ጱӮኴ愊眅ݢ犥፡ک …




    14

    View full-size slide

  15. 獡蚎螂஠ኸ綫撪
    15

    View full-size slide

  16. –jserv
    ̿Git ฎӞ㮆ݢ犥虏匍ࣁጱᛔ૩牏螂݄ጱᛔ૩޾๚㬵
    ጱᛔ૩وݶ樄咳ጱ粚๜矒ګ羬翄牐̀
    16

    View full-size slide

  17. Git 10 蝰ଙ牧Linux ԏᆿ
    藳犢ฎெ讕ࣁ 10 ॠ獉樄咳ਠ౮
    ֋禼ࣁ娄 - http://goo.gl/zvavk3
    17

    View full-size slide

  18. Ⅱ. GitHub ݈ฎՋ讕?
    18

    View full-size slide

  19. –chusiang
    GitHub ฎӞ㮆൉׀݋珿ጱ Git դᓕ牏
    Issue tracking ... 缛ጱ纷ୗ嘨ᐒԻଘݣ牐
    19

    View full-size slide

  20. GitHub ਥො翕ᒊ
    https://github.com/
    20

    View full-size slide

  21. Issue Tracking
    23

    View full-size slide

  22. Ⅲ. Git ޾ GitHub ݢ犥ெ讕ሻ?
    26

    View full-size slide

  23. ग़Ո㶧ݶ樄咳
    • LifeZMD 傶 Charlie, Chu, Dick,
    Olga, Steven, chusiang ෝ iDSBG
    ᒫӣ䌵 HTML5 Hackathon ಅ蕣֢牐
    • 穉搴౮婧物ᒫ 4 ݷ牐
    • 穉搴碻樌物2 ॠ 1 ज़牐
    • 㿁褧Ո碍物6 Ո牐
    LifeZMD - http://goo.gl/OHJK9u
    27

    View full-size slide

  24. 覌眲翕ᒊ
    SM ฎ㮆ֵአ GitHub Pages ๐率޾
    ጱ HTML, CSS ޾ Javascript ಅ䌃౮
    ጱय़ਁ䁭 Web Apps牐
    SM - http://sm.drx.tw
    28

    View full-size slide

  25. 蝑 Patch
    憽஑獨Ոጱ䌕礯犋䄪ਠ聅牫
    ᮎ疰ض fork 獨Ոጱ䌕礯牧
    硬ਠ code ٚ蝑 Pull Requests 㹧牦
    @be_vimmer_tw - http://goo.gl/TVYHsL
    29

    View full-size slide

  26. 䌃䨗
    • 萞ኧ GitHub ޾ GitBook ๐率ጱ碉
    ݳ牧౯㮉ݢ犥ֵአ Markdown 承ဩ
    砰䌃෈ᒍ牧㪔碉ቘ౮㲘牐
    • GitBook ݶ碻ඪൔ Web, PDF, ePub
    ޾ mobi 缛ग़圵໒ୗ牐
    ਠ獊አ GNU/Linux ૡ֢ - http://goo.gl/OHJK9u
    30

    View full-size slide

  27. 瞱媲碉ݳ (CI)
    砇蟴䔶य़ጱ Jenkins CI牧ܨݢ蝱ᤈ

    ᛔ㵕玕介手 (Web UI, Unit test)牏

    翥捌 (AOSP)牏蝢Ꭳ懱௳ (Email,
    HipChat, Slack) ... 缛碉ݳ牐
    Jenkins CI - https://ci.jenkins-ci.org/
    31

    View full-size slide

  28. –chusiang
    ̿磪ԧ Git 疰অ穉䌃纷ୗݢ犥蚤ሻ㻌秚蝿瞁Ӟ䰬牧
    ݢ犥褰碻㱪ਂ޾捝玲蝱ଶ牧犋ᓕฎᥝ盠蝧Ꮘ橕螭ฎ
    ᥝ誢涢ݱ㮆獤ඪ玀眐᮷ݢ犥斕誫ጱ旰ک牐̀
    32

    View full-size slide

  29. Ⅳ. 10 ೗౮傶 Git य़䒍
    33

    View full-size slide


  30. 樄ত ԏ獮殾伛猋
    ۑ毆珿ٌԪ牧஠ضڥٌ瑊

    Tool
    34

    View full-size slide

  31. SourceTree Terminal
    or
    35

    View full-size slide

  32. 螭磪 ᪒᪡࿯竝

    ID ޾
    Email
    36

    View full-size slide

  33. # 戔ਧֵአᘏݷ圸
    $ git config --global user.name "foo"
    # 戔ਧ襎ৼמᓟ
    $ git config --global user.email "[email protected]"
    37

    View full-size slide

  34. ᒫ 1 ೗物蕦蕣 (clone) 膏ڡত玕 (init)
    మ盠蝧Ӥಋ牫ᮎ疰ضℂಧ樄ত㹧牦
    38

    View full-size slide

  35. ٚ clone 獮牧 藶ض fork
    傶׎ෝݶྍ๜犥ӥ砺֢絑ह牧藶ضᛗ GitHub 蝱ᤈ fork牐
    ૢ棎
    39

    View full-size slide

  36. 蕦蕣 (clone)
    舙犋ฎℂᛔ૩ጱ GitHub 蝱ᤈ蕦蕣 (clone)牧毆戔ฎ䷱磪稗褖Ӥ㯽 (push) ጱࡂ牦
    40

    View full-size slide

  37. ૢ棎
    ૢ棎
    41
    # 蕦蕣 (clone)
    $ git clone [email protected]:chusiang/sandbox.git
    夺ਁ
    蟂犩藶硬౮ᛔ૩ጱ癱蒈
    夺ਁ蟂犩藶硬౮ᛔ૩ጱ癱蒈
    夺ਁ蟂犩藶硬

    View full-size slide

  38. ڡত玕 (init)
    ࣁୌ缏Ӟ㮆碝ጱ Git 䌕礯ԏ獮牧౯㮉襑ಋ㵕ୌ缏๜瑿ᒒጱ碍硁䓚 (Local Repository)牧֕舙磪獮
    Ո (蝢ଉ䨝ฎ羬翄ᓕቘ㹓) ୌ缏অ牧౲ fork ٌਙ䌕礯牧蝡碻౯㮉疰ݢ犥ኼ螂牐
    42

    View full-size slide

  39. ૢ棎
    ૢ棎
    # ୌ缏䌕礯ፓ袅㪔獥矦ᛗ扗ፓ袅皈ӥ
    $ mkdir /Users/jonny/vcs/demo; cd $_
    # ୌ缏๜瑿碍硁䓚 (local repository)
    $ git init 43

    View full-size slide

  40. ᒫ 2 ೗物碝ी (add)牏ᑏ㵕 (mv)牏㳫ᴻ (rm)
    ݢమ౮ฎ CRUD 愊ጱ Create, Upgrade, Delete牐
    44

    View full-size slide

  41. ݦ棎
    # 碝ी (Add)牏㳫ᴻ (Remove)
    $ git { add | rm } README.md
    # ᑏ㵕 (Move)
    $ git mv README.md foo.md

    View full-size slide

  42. ᒫ 3 ೗物൉Ի (commit)
    ࣁ Git ጱྯӞ㵕愊牧᮷ฎአ commit 㬵懿袅ጱ牐
    46

    View full-size slide

  43. # ൉Ի (Commit)
    $ git commit README.md
    git commit ૢ棎
    蜍獈෈ਁ
    47

    View full-size slide

  44. Upgrade
    to Lv1
    48

    View full-size slide

  45. ᒫ 4 ೗物礚፡制眲 (status) 膏稲ݥ懿袅 (log)
    ࣁ Git ጱӮኴ蝈᪠碻牧አ status ޾ log 疰䌘ԧ牐
    49

    View full-size slide

  46. 礚፡制眲 (status)
    匍ࣁ狶کߺӞ㵕ԧ? ፡ status 疰Ꭳ螇ԧ牦
    50

    View full-size slide

  47. # 粚๜制眲 (Status)
    $ git status
    git status
    51

    View full-size slide

  48. 礚፡稲ݥ懿袅 (log)
    ࣁ Console 愊㲺Ռ聜䙼አ git lg ጱ獨ݷ (alias) 㬵፡粚๜䰽牐
    52

    View full-size slide

  49. # 薪፡粚๜懿袅
    $ git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset
    %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'
    git log
    53

    View full-size slide

  50. ᒫ 5 ೗物礚፡懿袅 (checkout)
    拻ਠԧ㱪ਂ蝱ଶ牧矑ӥ㬵疰ฎ捝玲 (Read) 蝱ଶ牐
    54

    View full-size slide

  51. # 礚፡礓蝱ଶ碻ጱ懿袅
    $ git checkout 09a3d66
    ૢ棎
    ૢ棎
    ૢ棎
    55

    View full-size slide

  52. ᒫ 6 ೗物穉䌘粚๜癩吖 (diff)
    㴄㴄硬ԧՋ讕 code? 磪 diff ܨݢӞፓ啻簁牐
    56

    View full-size slide

  53. # 穉䌘 (Different) 吚獮粚๜癩吖
    $ git diff HEAD
    57

    View full-size slide

  54. Upgrade
    to Lv2
    58

    View full-size slide

  55. ᒫ 7 ೗物വ蝑 (push)
    Ӥ㯽ᛗ螐ᒒ (remote) ጱ碍硁䓚 (Repository)牐
    59

    View full-size slide

  56. # വ蝑 (Push)
    $ git push origin master
    ૢ棎
    ૢ棎
    60

    View full-size slide

  57. ᒫ 8 ೗物೉玲 (pull)
    ℂ螐ᒒ (remote) 碍硁䓚 (Repository) ӥ斉牐
    61

    View full-size slide

  58. # ೉玲 (Pull)
    $ git pull origin master
    ૢ棎
    ૢ棎
    62

    View full-size slide

  59. ᒫ 9 ೗物䞳祌狕硬 (checkout)
    纷ୗ䌃粋ԧ? ᮎ疰᯿毣㬵螂މ牦
    63

    View full-size slide

  60. # 萞ኧ checkout 䞳祌狕硬
    $ git checkout README.md
    ૢ棎
    ૢ棎
    64

    View full-size slide

  61. 65
    Upgrade
    to Lv3

    View full-size slide

  62. ᒫ܈೗物獤ඪ (branch) 膏ݳ㬫 (merge)
    䋊䨝 branch ޾ merge ܨݢ藯ฎ聜஑य़౮ۑێԧ牦
    66

    View full-size slide

  63. 粚๜䰽
    ࣁ樄ত獮ض፡Ӟӥ奾ຎ牐
    master
    dev
    67

    View full-size slide

  64. 獤ඪ (branch)
    ݶӞ稠蝿瞁牧者磪犋ݶጱ獤ඪ玀眐牐
    68

    View full-size slide

  65. # ୌ缏獤ඪ
    $ git branch dev
    $ git checkout -b dev
    ૢ棎
    master
    69
    ૢ棎

    View full-size slide

  66. # ڜڊ獤ඪ
    $ git branch
    master
    70

    View full-size slide

  67. # 萞ኧ checkout 獥矦ᛗ dev 獤ඪ
    $ git checkout dev
    ૢ棎 x2
    dev
    master
    71

    View full-size slide

  68. # ෝ dev 獤ඪ碝ी䲆礯牧㪔൉Ի
    $ git add branch_demo.txt
    $ git commit -m 'Demo for branch'
    dev
    72

    View full-size slide

  69. Branch? 膐ಋݢ஑
    樄ԧ碝ጱ branch 盅螭ᥝࣁ碝ጱ branch
    愊 commit 螂಍፡஑ک獤ඪ䰽牐
    dev
    master
    Uncommitted
    changes
    73

    View full-size slide

  70. ݳ㬫 (merge)
    玀眐獤ඪԋԧ牧者磪ࢧکԆ娄ጱӞॠ牐
    74

    View full-size slide

  71. ૢ棎 x2
    # 萞ኧ checkout 獥矦ᛗ master 獤ඪ
    $ git checkout master
    dev
    master
    75

    View full-size slide

  72. # ෝ master ݳ㬫 dev 獤ඪ
    $ git merge --no-ff dev
    master
    76

    View full-size slide

  73. ݳ㬫ਠ౮牦
    master
    77

    View full-size slide

  74. 眅૪聜஑Ӥ犔ஞဩ
    Congratulation !
    78

    View full-size slide

  75. Ⅴ. GitHub 褰璤介涢
    79

    View full-size slide

  76. च๜砺֢ (Basic)
    1. ጭ獈 Github牐

    - https://github.com/
    2. 䌘 Lab ጱ Repository 蝱ᤈ fork牐

    - https://github.com/chusiang/sandbox/
    3. ӥ斉纷ୗ嘨牐

    $ git clone https://github.com/YourName/sandbox.git
    4. 碝ी䲆礯㪔൉Ի牐

    $ git { add | status | commit }
    5. Ӥ㯽纷ୗ嘨牐

    $ git push
    80
    Login GitHub
    fork Repository
    git clone
    git add
    git commit
    git status
    git push
    Finish?
    Yes
    No

    View full-size slide

  77. 蝱褩砺֢ (Advanced)
    1. ෝٌਙ᪠䕩ٚ稞ӥ斉纷ୗ嘨牐

    $ git clone https://github.com/YourName/sandbox.git
    2. 碝ी牏狕硬牏㳫ᴻ䲆礯㪔൉Իग़稞牐

    $ git { add | mv | rm | status | commit }
    3. 碝ी獤ඪ㪔൉Իग़稞牐
    4. 獥矦ᛗݱ㮆夵袅讨޾獤ඪ牐

    $ git checkout OXOXOXX
    5. ݳ㬫獤ඪ牐
    6. Ӥ㯽纷ୗ嘨牐

    $ git push origin master
    81
    dev
    master
    Finish

    View full-size slide

  78. ૡ珶๐率
    82

    View full-size slide

  79. 2015
    2015.10.?
    - http://mopcon.org
    83

    View full-size slide

  80. ਥො翕ᒊ
    http://mopcon.org
    罭妟ᗭ
    http://fb.me/mopcon
    84

    View full-size slide

  81. http://coscup.org
    86

    View full-size slide

  82. Q & A
    瑥纔ೌ಑訤觬
    藶㷢ᘍ匍䁰و執෈կ - http://goo.gl/aqTTYO
    87

    View full-size slide

  83. Reference
    • 匍䁰و執෈կ - http://goo.gl/aqTTYO
    • 匍䁰ፗ砮翕࣎ - https://youtu.be/5ftNjrpzVqM
    • 蝫糞ৼ᮷胼睞ጱ Git 獈槹瞲ܖ | 揔໒禼 (Backlog) - http://backlogtool.com/git-guide/tw/
    • 䌃妔य़疑ጱ Git 硽䋊 | slideshare - http://www.slideshare.net/littlebtc/git-5528339
    • Git 䋿率瑽薹 | slideshare - http://www.slideshare.net/pokaichang72/git-42427674
    • Git ਥො෈կ - http://git-scm.com/book/zh-tw/v1
    • 瑽粙㬵რ物
    • 㾴疑瑿ቘ褾扮 - http://www.ngtaiwan.com
    • 10 Years of Git | Atlassian Git Tutorial - https://www.atlassian.com/git/articles/10-years-of-git/
    88

    View full-size slide