SlideShare ist ein Scribd-Unternehmen logo
1 von 117
Downloaden Sie, um offline zu lesen
Git and GitHub
  ihower@gmail.com
       2011/3
       CC BY-NC-SA 3.0
            Pro Git
?
•          a.k.a. ihower

 • http://ihower.tw
 • http://twitter.com/ihower
• Ruby on Rails Developer since 2006
• The organizer of Ruby Taiwan Community
 • http://ruby.tw              2
Agenda

‧1.        DVCS
‧2.        Git
‧3. Git
‧4. Github
‧5. Git



                           3
‧2002                 (     copy       )

‧2005 SubVersion
‧2007 SVK
‧2008 Git ( SVN          push/pull)

‧2009 Git (         master                     feature branches)

‧2011 Git ( git flow                   topic branch       rebase)




                                                         4
1.   DVCS ?




              5
Version Control System
‧     repository
‧
‧
‧Branch(     )
‧Tag(    )




                                  6
Local VCS
copy paste      , rcs




                        7
Local VCS
copy paste      , rcs




                        7
Centralized VCS
 CVS, Subversion, Perforce




                             8
Centralized VCS
 CVS, Subversion, Perforce




            1.

          2. Single point of failure




                                       8
Distributed VCS
 Git, Mercurial(Hg), Bazaar




                              9
Distributed VCS
 Git, Mercurial(Hg), Bazaar




                              workflows
                                     !




                                          9
Local development
‧         CSV
      commit          history log




‧       CSV
 commit     history log


                                    10
2.   Git ?




             11
Git
‧       Linux Torvalds (Linux creator)
‧            Linux Kernel
‧2005/4             2005/6             Linix
 Kernel 2005/12        1.0




                                        12
Git?
‧Git            ‧Qt
‧Linux Kernel   ‧Ruby on Rails
‧Perl           ‧Android
‧Eclipse        ‧PostgreSQL
‧Gnome          ‧Debian
‧KDE            ‧X.org



                                 13
other VCS way




                14
Git Way
 metadata   snapshots




                        15
Git Way
 metadata       snapshots




    I’m a mini filesystem!
        Not just VCS.




                             15
Git Way
 metadata        snapshots




    I’m a mini filesystem!
        Not just VCS.




              Apple   Time
       Machine         !
                             15
: Working tree/Staging area/Repository




                              16
Why Git is Better than X
          http://zh-tw.whygitisbetterthanx.com

‧
‧
‧Git
‧Git
‧Staging
‧
‧
‧        GitHub!
Git
                SVN
‧svn          merge
 branch         branch
‧svn    log
‧svn commit   checkout
    commit




                         18
3-1. Git




           19
Install
‧      Git
    http://help.github.com/set-up-git-redirect
‧      Git GUI(optional)
    GitX (Mac)
    TortoiseGit/Git Extensions (Windows)
    qgit (Linux)
‧      SSH Key
    ssh-keygen -t rsa -C "your_email@youremail.com"

                                                 20
Setup
‧      ~/.gitconfig
‧git config --global user.name "Your Name"
‧git config --global user.email "your@email.com"
‧git config --global color.ui true
‧git config --global core.editor "mate -w" (Textmate)




                                            21
Setup (Windows only)
‧
‧git config --global core.autocrlf true
‧git config --global core.safecrlf true




                                         22
Repository

‧mkdir sandbox
‧cd sandbox
‧git init




                              23
Repository
‧SSH
    git clone git@github.com:ihower/sandbox.git
‧HTTP/HTTPS
    git clone https://ihower@github.com/ihower/sandbox.git
‧ Git protocol                                    (                                  )
    git clone git://github.com/ihower/sandbox.git
‧File              (     Dropbox       git init --bare --shared        !! Crazy!!)

    git clone file://path/to/repo.git
                                                                  24
commit
‧touch README
‧git add README
‧git status
‧git commit -m “First Commit”




                                25
‧        README
‧git status
‧git diff
‧git add .
 (                                    !)
‧git status
‧git diff --cached
‧git commit -m “Update README”
                                 26
Staging                commit
‧touch a.rb
‧touch b.rb
‧git add a.rb
‧git commit “Update a”
‧git add b.rb
‧git commit “Update b”


                                  27
‧git rm a.rb
‧git mv b.rb c.rb
‧git add .
‧git commit “Remove a, Rename b to c”
‧      copy ?     Git
 cp



                                        28
commit
Untracked files      Changes not      Changes to be
                 staged for commit    committed




                                                 29
‧git log
‧git log --oneline
‧git log --oneline --decorate --graph
‧          GUI




                                        30
‧        .gitignore (                commit        )
‧        ~/.gitignore (      Global    )
‧                 commit
     .gitkeep
‧.gitignore
 https://github.com/github/gitignore



                                              31
commit   ?
‧tmp/*
‧log/*
‧                      (               )
‧
‧build/*   compile
‧.DS_Store
‧Thumbs.rb

                                  32
Commit
‧                /     /
                                bug fixed
           unit test           commit
                           commit
                             commit
‧git diff --check
‧commit



                                           33
3-2. Git




           34
Branch ?

‧topic feature
‧Bug fixes
‧      (refactor)
‧




                               35
branch
‧git branch new_feature
‧git branch
‧git checkout new_feature
‧touch new_feature.rb
‧git add new_feature.rb
‧git commit -m “New feature”


                               36
branch
‧git branch new_feature
‧git branch
‧git checkout new_feature
‧touch new_feature.rb
‧git add new_feature.rb
‧git commit -m “New feature”
                       checkout
                                  working tree
                                            36
branch
‧git checkout master
‧git merge new_feature




                          37
38
(master) git branch iss53




                            39
(iss53) git commit




                     40
(master) git branch hotfix
   (hotfix) git commit




                            41
(master) git merge hotfix




                           42
(master) git merge hotfix




             fast-forward
                            42
(iss53) git commit




                     43
(master) git merge iss53




                           44
(master) git merge iss53




                C6      merge
                     commit

                                44
‧Straight merge
                  branch commits
              merge commit
      Parents
           fast-forward            merge
    commit              --no-ff




                                           45
(cont.)
‧Squashed commit
    git merge new_feature --squash
                     merge-commit
        log SVN    merge
‧cherry-pick
    git cherry-pick 714cba
                     commit



                                         46
branch
‧      working tree  branch
    staging area    modified
‧         commit            push
 reset
‧         stash
    git stash
    git stash apply
    git stash clear

                                   47
3-3. Git   push




              48
push                        branch
                         ...
‧    SVN       Git     Commit
                     commit logs!!
     commits
     commit
     commit           commits
     commits



                                         49
reset (        commit                 )
‧git reset e37c75787
‧git reset HEAD^ (          working tree)
‧git reset HEAD^ --soft (        staging area)
‧git reset HEAD^ --hard (        )




                                                50
revert (           commit     )
‧    reset      revert           commit

‧git revert e37c75787
‧git revert HEAD^




                                    51
rebase (                    commit                      )
‧git rebase -i e37c7578
pick 048b59e first commit
pick 995dbb3 change something
pick aa3e16e changed

#   Rebase 0072886..1b6475f onto 0072886
#
#   Commands:
#    p, pick = use commit
#    r, reword = use commit, but edit the commit message
#    e, edit = use commit, but stop for amending
#    s, squash = use commit, but meld into previous commit
#    f, fixup = like "squash", but discard this commit's log message
#    x, exec = run command (the rest of the line) using shell
#
#   If you remove a line here THAT COMMIT WILL BE LOST.
#   However, if you remove everything, the rebase will be aborted.


                                                                     52
: rebase
‧rebase                (             local branch)
   1.                 branch
   2.         branch     commits
   apply/patch
                    commit log
           local branch




                                              53
:                new_feature
           master

         D---E new_feature
     /
A---B---C---F master




                             54
merge
(new_feature) git merge master

          D--------E
         /          
    A---B---C---F----G new_feature

             master




                                 55
rebase            G !
(new_feature) git rebase master


 A---B---C---F---D'---E' new_feature

          master




                                 56
rebase            G !
(new_feature) git rebase master


 A---B---C---F---D'---E' new_feature

          master




                      merge commit
                                     56
push           commits

   push   !!




                         57
rebase + merge
        (              feature branch           develop)

‧
    feature branch                merge
    feature branch       typo commit
    feature branch          commits
‧
            feature branch      git rebase develop -i
    (                   ) git rebase          -i
            develop branch       git merge feature --no-ff
                                                      58
merge
commit




            59
(1)
‧          --no-ff         merge commit
        fast-forward
‧rebase         feature branch          push

‧               feature branch




                                       60
(2)
‧     rebase                  conflict

‧              rebase
    branch               rebase




                             61
4. Github   ?




                62
Git and Github
=
GitHub?
‧twitter     ‧jQuery
‧facebook    ‧YUI 3
‧rackspace   ‧mootools
‧digg        ‧Ruby on Rails
‧Yahoo!      ‧node.js
‧shopify     ‧symfony
‧EMI         ‧mongodb
‧six apart   ‧Erlang
                              65
Watch!   Fork
67
Fork network




               68
Patch           ?
‧Fork            Repository
‧Clone
‧Fix bugs  Enhance features
‧Push
‧ Pull request




                              69
Fork & Pull Requests
        75%   fork   outside merge               !!
watch                25%      outside contributions    !!




                                                  70
Follow!
Wiki




       72
Code Review


Diff
Download Source
  or Package




                  74
Github pages
             http://pages.github.com/

‧   your.github.com       repository Github
         http://your.github.com
‧   gh-pages               your_project Github
            http://your.github.com/your_project




                                        75
Github pages
               http://pages.github.com/

‧   your.github.com       repository Github
         http://your.github.com
‧   gh-pages               your_project Github
            http://your.github.com/your_project



         Git

           (   Branch                     merge)

                                                   75
3-4. Git




           76
Push               GitHub Reporitory

‧ Github
‧git remote add origin git@github.com:your_account/
 sandbox.git
‧git push -u origin master
‧              git push
         ![rejected]           git pull


                                           77
Pull
‧git pull origin master       git pull
     git fetch          branch
                         branch   merge
‧git pull --rebase
           rebase




                                          78
git pull --rebase
   merge
http://ihower.tw/blog/archives/3843




                                      79
git pull --rebase
   merge
http://ihower.tw/blog/archives/3843




                branch
                  master
                               !




                                      79
git pull            merge?
                     rebase?
‧                         conflict          merge
                          feature branch         ?
‧                               conflict
          --rebase




                                            80
git pull            merge?
                     rebase?
‧                           conflict           merge
                           feature branch           ?
‧                                conflict
          --rebase
                               git flow
                      branches
                             merge        !


                                               80
Git Submodule
‧Git      SVN
‧                                ?   SVN Externals?
‧      http://josephjiang.com/entry.php?id=342
‧        ? http://josephjiang.com/entry.php?id=357
‧
        Ruby/Rails Develops         XD
          Bundler             dependencies


                                             81
‧git tag
‧git archive
‧git bisect
‧git blame
‧git grep
‧git show
‧git reflog (   commits 90 )

‧git gc

                              82
5. Git




         83
1.
     Repositories ?



                      84
Centralized Workflow
              Push           Repository
   Branches          (   )




                               85
Integration-Manager Workflow
    Open Source                              Push
 Repository            request pull
       GitHub     Fork   Pull Request




                                        86
Dictator and Lieutenants Workflow
              Open Source          Linux Kernel
           patch    pull request




                                     87
2.         Repository
     Branches ?



                        88
Git flow:                                    branches
  http://nvie.com/posts/a-successful-git-branching-model/
             http://ihower.tw/blog/archives/5140




                                                      89
‧master:    production-ready
‧develop:




                               90
(1)
‧Feature branches
                     bugs
      develop
           merge     develop
                                         develop
           (        merge      rebase)




                                             91
(1)
‧Feature branches
                     bugs
      develop
           merge     develop
                                         develop
           (        merge      rebase)




                            branch!!

                                             91
(2)
‧Release branches
           release              bugs
      develop
           merge     master   develop




                                        92
(3)
‧Hotfix branches
         release                  master

        master
          merge    master   develop




                                           93
: Feature branches
: develop
 release branches
: hotfix branches
: master




           94
git-flow
‧git flow init
‧git flow feature finish feature_name
‧git flow feature publish feature_name
‧git flow feature track feature_name
‧git flow feature finish feature_name




                                        95
Branch-Owner Policy
‧          project leaders       commit/merge
 develop branch
‧          release team            master branch
‧                   topic branches            pull
 request           code review
 merge    develop
‧GitHub     pull request

                                           96
Code Review



              97
Branch   Diff




         98
the maintainer workflow for git itself
 http://www.kernel.org/pub/software/scm/git/docs/gitworkflows.html

‧master tracks the commits that should go into
 the next release
‧maint tracks the commits that should go into the
 next "maintenance release"
‧next is intended as a testing branch for topics
 being tested for stability for master.
‧pu (proposed updates branches) is an integration
 branch for things that are not quite ready for
 inclusion yet
‧topic branches for any nontrivial feature99
Ruby on Rails      workflow
‧        Rails            3.0.5
‧master                           release 3.1
‧stable branches
    2-2-stable
    2-3-stable bug fixes
    3-0-stable bug fixes



                                   100
One more thing...




                    101
git-svn
‧         SubVersion
                       Git        Git        !
‧git svn clone http://url/svn/trunk/ project_name
‧(normal git operations)
‧git svn dcommit




                                           102
‧http://progit.org/book/
‧http://git-scm.com
‧http://help.github.com/
‧http://gitimmersion.com
‧http://www.gitready.com/
‧http://gitref.org
‧http://ihower.tw/blog/category/git
‧Pragmatic Version Control Using Git, Pragmatic
                                         103
Thank you.
google “ihower”




                         104

Weitere ähnliche Inhalte

Was ist angesagt?

Git and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overviewGit and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overviewRueful Robin
 
Git - An Introduction
Git - An IntroductionGit - An Introduction
Git - An IntroductionBehzad Altaf
 
Learning git
Learning gitLearning git
Learning gitSid Anand
 
Git-flow workflow and pull-requests
Git-flow workflow and pull-requestsGit-flow workflow and pull-requests
Git-flow workflow and pull-requestsBartosz Kosarzycki
 
A Practical Introduction to git
A Practical Introduction to gitA Practical Introduction to git
A Practical Introduction to gitEmanuele Olivetti
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to GitLukas Fittl
 
Git Introduction Tutorial
Git Introduction TutorialGit Introduction Tutorial
Git Introduction TutorialThomas Rausch
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hubVenkat Malladi
 
Git Terminologies
Git TerminologiesGit Terminologies
Git TerminologiesYash
 
Git Tutorial I
Git Tutorial IGit Tutorial I
Git Tutorial IJim Yeh
 
The everyday developer's guide to version control with Git
The everyday developer's guide to version control with GitThe everyday developer's guide to version control with Git
The everyday developer's guide to version control with GitE Carter
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsLee Hanxue
 

Was ist angesagt? (20)

Git and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overviewGit and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
 
Git - An Introduction
Git - An IntroductionGit - An Introduction
Git - An Introduction
 
Learning git
Learning gitLearning git
Learning git
 
git and github
git and githubgit and github
git and github
 
Git for beginners
Git for beginnersGit for beginners
Git for beginners
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
 
Git-flow workflow and pull-requests
Git-flow workflow and pull-requestsGit-flow workflow and pull-requests
Git-flow workflow and pull-requests
 
A Practical Introduction to git
A Practical Introduction to gitA Practical Introduction to git
A Practical Introduction to git
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Git Introduction Tutorial
Git Introduction TutorialGit Introduction Tutorial
Git Introduction Tutorial
 
Git real slides
Git real slidesGit real slides
Git real slides
 
Intro to Git and GitHub
Intro to Git and GitHubIntro to Git and GitHub
Intro to Git and GitHub
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
Git Terminologies
Git TerminologiesGit Terminologies
Git Terminologies
 
Basic Git Intro
Basic Git IntroBasic Git Intro
Basic Git Intro
 
Git Tutorial I
Git Tutorial IGit Tutorial I
Git Tutorial I
 
The everyday developer's guide to version control with Git
The everyday developer's guide to version control with GitThe everyday developer's guide to version control with Git
The everyday developer's guide to version control with Git
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
 
Git and github
Git and githubGit and github
Git and github
 
Git 101 for Beginners
Git 101 for Beginners Git 101 for Beginners
Git 101 for Beginners
 

Andere mochten auch

Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners HubSpot
 
Getting Git Right
Getting Git RightGetting Git Right
Getting Git RightSven Peters
 
Introduction to Git/Github - A beginner's guide
Introduction to Git/Github - A beginner's guideIntroduction to Git/Github - A beginner's guide
Introduction to Git/Github - A beginner's guideRohit Arora
 
Git 101 Presentation
Git 101 PresentationGit 101 Presentation
Git 101 PresentationScott Chacon
 
寫給大家的 Git 教學
寫給大家的 Git 教學寫給大家的 Git 教學
寫給大家的 Git 教學littlebtc
 
[NDC16] Effective Git
[NDC16] Effective Git[NDC16] Effective Git
[NDC16] Effective GitChanwoong Kim
 
Advanced Git
Advanced GitAdvanced Git
Advanced Gitsegv
 
Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀Wen-Tien Chang
 
初心者 Git 上手攻略
初心者 Git 上手攻略初心者 Git 上手攻略
初心者 Git 上手攻略Lucien Lee
 
Git 實務圖解
Git 實務圖解Git 實務圖解
Git 實務圖解Pokai Chang
 
Git 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using GitGit 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using GitGeoff Hoffman
 
いつやるの?Git入門 v1.1.0
いつやるの?Git入門 v1.1.0いつやるの?Git入門 v1.1.0
いつやるの?Git入門 v1.1.0Masakazu Matsushita
 
Control de versiones con Git y Github
Control de versiones con Git y GithubControl de versiones con Git y Github
Control de versiones con Git y Githubguest638090
 

Andere mochten auch (20)

Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners
 
Getting Git Right
Getting Git RightGetting Git Right
Getting Git Right
 
Introduction to Git/Github - A beginner's guide
Introduction to Git/Github - A beginner's guideIntroduction to Git/Github - A beginner's guide
Introduction to Git/Github - A beginner's guide
 
Git Tutorial 教學
Git Tutorial 教學Git Tutorial 教學
Git Tutorial 教學
 
Getting Git
Getting GitGetting Git
Getting Git
 
Git 101 Presentation
Git 101 PresentationGit 101 Presentation
Git 101 Presentation
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
寫給大家的 Git 教學
寫給大家的 Git 教學寫給大家的 Git 教學
寫給大家的 Git 教學
 
Inside GitHub with Chris Wanstrath
Inside GitHub with Chris WanstrathInside GitHub with Chris Wanstrath
Inside GitHub with Chris Wanstrath
 
Introduction git
Introduction gitIntroduction git
Introduction git
 
Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
Introduction to Git and GitHub
 
[NDC16] Effective Git
[NDC16] Effective Git[NDC16] Effective Git
[NDC16] Effective Git
 
Advanced Git
Advanced GitAdvanced Git
Advanced Git
 
Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀
 
初心者 Git 上手攻略
初心者 Git 上手攻略初心者 Git 上手攻略
初心者 Git 上手攻略
 
Git 實務圖解
Git 實務圖解Git 實務圖解
Git 實務圖解
 
Git best practices workshop
Git best practices workshopGit best practices workshop
Git best practices workshop
 
Git 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using GitGit 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using Git
 
いつやるの?Git入門 v1.1.0
いつやるの?Git入門 v1.1.0いつやるの?Git入門 v1.1.0
いつやるの?Git入門 v1.1.0
 
Control de versiones con Git y Github
Control de versiones con Git y GithubControl de versiones con Git y Github
Control de versiones con Git y Github
 

Ähnlich wie Git and Github

インフラエンジニアのためのGit入門
インフラエンジニアのためのGit入門インフラエンジニアのためのGit入門
インフラエンジニアのためのGit入門Kouhei Maeda
 
Git Version Control System
Git Version Control SystemGit Version Control System
Git Version Control SystemKMS Technology
 
SCM for Android Developers Using Git
SCM for Android Developers Using GitSCM for Android Developers Using Git
SCM for Android Developers Using GitTony Hillerson
 
Git for the Android Developer
Git for the Android DeveloperGit for the Android Developer
Git for the Android DeveloperEffectiveUI
 
Git for the Android Developer
Git for the Android DeveloperGit for the Android Developer
Git for the Android DeveloperEffective
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With GitNick Quaranto
 
Brown bag sessions git workshop
Brown bag sessions git workshopBrown bag sessions git workshop
Brown bag sessions git workshopBishant Shrestha
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git TutorialSage Sharp
 
Why Git Sucks and you'll use it anyways
Why Git Sucks and you'll use it anywaysWhy Git Sucks and you'll use it anyways
Why Git Sucks and you'll use it anywaysCarlos Taborda
 
Git basic stanley hsiao 2010_12_15
Git basic stanley hsiao 2010_12_15Git basic stanley hsiao 2010_12_15
Git basic stanley hsiao 2010_12_15Chen-Han Hsiao
 
Why You Should Be Using Git
Why You Should Be Using GitWhy You Should Be Using Git
Why You Should Be Using GitFrancisco Vieira
 

Ähnlich wie Git and Github (20)

Git 101 for_tarad_dev
Git 101 for_tarad_devGit 101 for_tarad_dev
Git 101 for_tarad_dev
 
インフラエンジニアのためのGit入門
インフラエンジニアのためのGit入門インフラエンジニアのためのGit入門
インフラエンジニアのためのGit入門
 
Git
GitGit
Git
 
Git Version Control System
Git Version Control SystemGit Version Control System
Git Version Control System
 
SCM for Android Developers Using Git
SCM for Android Developers Using GitSCM for Android Developers Using Git
SCM for Android Developers Using Git
 
Git for the Android Developer
Git for the Android DeveloperGit for the Android Developer
Git for the Android Developer
 
Git for the Android Developer
Git for the Android DeveloperGit for the Android Developer
Git for the Android Developer
 
Git training
Git trainingGit training
Git training
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
 
Git in Eclipse
Git in EclipseGit in Eclipse
Git in Eclipse
 
Git basics
Git basicsGit basics
Git basics
 
Brown bag sessions git workshop
Brown bag sessions git workshopBrown bag sessions git workshop
Brown bag sessions git workshop
 
Wokshop de Git
Wokshop de Git Wokshop de Git
Wokshop de Git
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
 
Git Basics Philips
Git Basics PhilipsGit Basics Philips
Git Basics Philips
 
Why Git Sucks and you'll use it anyways
Why Git Sucks and you'll use it anywaysWhy Git Sucks and you'll use it anyways
Why Git Sucks and you'll use it anyways
 
Git basic stanley hsiao 2010_12_15
Git basic stanley hsiao 2010_12_15Git basic stanley hsiao 2010_12_15
Git basic stanley hsiao 2010_12_15
 
Git.odp 0
Git.odp 0Git.odp 0
Git.odp 0
 
Why You Should Be Using Git
Why You Should Be Using GitWhy You Should Be Using Git
Why You Should Be Using Git
 
Git Tech Talk
Git  Tech TalkGit  Tech Talk
Git Tech Talk
 

Mehr von Wen-Tien Chang

⼤語⾔模型 LLM 應⽤開發入⾨
⼤語⾔模型 LLM 應⽤開發入⾨⼤語⾔模型 LLM 應⽤開發入⾨
⼤語⾔模型 LLM 應⽤開發入⾨Wen-Tien Chang
 
Ruby Rails 老司機帶飛
Ruby Rails 老司機帶飛Ruby Rails 老司機帶飛
Ruby Rails 老司機帶飛Wen-Tien Chang
 
A brief introduction to Machine Learning
A brief introduction to Machine LearningA brief introduction to Machine Learning
A brief introduction to Machine LearningWen-Tien Chang
 
淺談 Startup 公司的軟體開發流程 v2
淺談 Startup 公司的軟體開發流程 v2淺談 Startup 公司的軟體開發流程 v2
淺談 Startup 公司的軟體開發流程 v2Wen-Tien Chang
 
RSpec on Rails Tutorial
RSpec on Rails TutorialRSpec on Rails Tutorial
RSpec on Rails TutorialWen-Tien Chang
 
ALPHAhackathon: How to collaborate
ALPHAhackathon: How to collaborateALPHAhackathon: How to collaborate
ALPHAhackathon: How to collaborateWen-Tien Chang
 
Exception Handling: Designing Robust Software in Ruby (with presentation note)
Exception Handling: Designing Robust Software in Ruby (with presentation note)Exception Handling: Designing Robust Software in Ruby (with presentation note)
Exception Handling: Designing Robust Software in Ruby (with presentation note)Wen-Tien Chang
 
Exception Handling: Designing Robust Software in Ruby
Exception Handling: Designing Robust Software in RubyException Handling: Designing Robust Software in Ruby
Exception Handling: Designing Robust Software in RubyWen-Tien Chang
 
從 Classes 到 Objects: 那些 OOP 教我的事
從 Classes 到 Objects: 那些 OOP 教我的事從 Classes 到 Objects: 那些 OOP 教我的事
從 Classes 到 Objects: 那些 OOP 教我的事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
 
A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩
A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩
A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩Wen-Tien Chang
 
Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介Wen-Tien Chang
 
A brief introduction to SPDY - 邁向 HTTP/2.0
A brief introduction to SPDY - 邁向 HTTP/2.0A brief introduction to SPDY - 邁向 HTTP/2.0
A brief introduction to SPDY - 邁向 HTTP/2.0Wen-Tien Chang
 
RubyConf Taiwan 2012 Opening & Closing
RubyConf Taiwan 2012 Opening & ClosingRubyConf Taiwan 2012 Opening & Closing
RubyConf Taiwan 2012 Opening & ClosingWen-Tien Chang
 
從 Scrum 到 Kanban: 為什麼 Scrum 不適合 Lean Startup
從 Scrum 到 Kanban: 為什麼 Scrum 不適合 Lean Startup從 Scrum 到 Kanban: 為什麼 Scrum 不適合 Lean Startup
從 Scrum 到 Kanban: 為什麼 Scrum 不適合 Lean StartupWen-Tien Chang
 
那些 Functional Programming 教我的事
那些 Functional Programming 教我的事那些 Functional Programming 教我的事
那些 Functional Programming 教我的事Wen-Tien Chang
 
RubyConf Taiwan 2011 Opening & Closing
RubyConf Taiwan 2011 Opening & ClosingRubyConf Taiwan 2011 Opening & Closing
RubyConf Taiwan 2011 Opening & ClosingWen-Tien Chang
 
BDD style Unit Testing
BDD style Unit TestingBDD style Unit Testing
BDD style Unit TestingWen-Tien Chang
 
RSpec 讓你愛上寫測試
RSpec 讓你愛上寫測試RSpec 讓你愛上寫測試
RSpec 讓你愛上寫測試Wen-Tien Chang
 

Mehr von Wen-Tien Chang (20)

⼤語⾔模型 LLM 應⽤開發入⾨
⼤語⾔模型 LLM 應⽤開發入⾨⼤語⾔模型 LLM 應⽤開發入⾨
⼤語⾔模型 LLM 應⽤開發入⾨
 
Ruby Rails 老司機帶飛
Ruby Rails 老司機帶飛Ruby Rails 老司機帶飛
Ruby Rails 老司機帶飛
 
A brief introduction to Machine Learning
A brief introduction to Machine LearningA brief introduction to Machine Learning
A brief introduction to Machine Learning
 
淺談 Startup 公司的軟體開發流程 v2
淺談 Startup 公司的軟體開發流程 v2淺談 Startup 公司的軟體開發流程 v2
淺談 Startup 公司的軟體開發流程 v2
 
RSpec on Rails Tutorial
RSpec on Rails TutorialRSpec on Rails Tutorial
RSpec on Rails Tutorial
 
RSpec & TDD Tutorial
RSpec & TDD TutorialRSpec & TDD Tutorial
RSpec & TDD Tutorial
 
ALPHAhackathon: How to collaborate
ALPHAhackathon: How to collaborateALPHAhackathon: How to collaborate
ALPHAhackathon: How to collaborate
 
Exception Handling: Designing Robust Software in Ruby (with presentation note)
Exception Handling: Designing Robust Software in Ruby (with presentation note)Exception Handling: Designing Robust Software in Ruby (with presentation note)
Exception Handling: Designing Robust Software in Ruby (with presentation note)
 
Exception Handling: Designing Robust Software in Ruby
Exception Handling: Designing Robust Software in RubyException Handling: Designing Robust Software in Ruby
Exception Handling: Designing Robust Software in Ruby
 
從 Classes 到 Objects: 那些 OOP 教我的事
從 Classes 到 Objects: 那些 OOP 教我的事從 Classes 到 Objects: 那些 OOP 教我的事
從 Classes 到 Objects: 那些 OOP 教我的事
 
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
 
A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩
A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩
A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩
 
Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介
 
A brief introduction to SPDY - 邁向 HTTP/2.0
A brief introduction to SPDY - 邁向 HTTP/2.0A brief introduction to SPDY - 邁向 HTTP/2.0
A brief introduction to SPDY - 邁向 HTTP/2.0
 
RubyConf Taiwan 2012 Opening & Closing
RubyConf Taiwan 2012 Opening & ClosingRubyConf Taiwan 2012 Opening & Closing
RubyConf Taiwan 2012 Opening & Closing
 
從 Scrum 到 Kanban: 為什麼 Scrum 不適合 Lean Startup
從 Scrum 到 Kanban: 為什麼 Scrum 不適合 Lean Startup從 Scrum 到 Kanban: 為什麼 Scrum 不適合 Lean Startup
從 Scrum 到 Kanban: 為什麼 Scrum 不適合 Lean Startup
 
那些 Functional Programming 教我的事
那些 Functional Programming 教我的事那些 Functional Programming 教我的事
那些 Functional Programming 教我的事
 
RubyConf Taiwan 2011 Opening & Closing
RubyConf Taiwan 2011 Opening & ClosingRubyConf Taiwan 2011 Opening & Closing
RubyConf Taiwan 2011 Opening & Closing
 
BDD style Unit Testing
BDD style Unit TestingBDD style Unit Testing
BDD style Unit Testing
 
RSpec 讓你愛上寫測試
RSpec 讓你愛上寫測試RSpec 讓你愛上寫測試
RSpec 讓你愛上寫測試
 

Git and Github

  • 1. Git and GitHub ihower@gmail.com 2011/3 CC BY-NC-SA 3.0 Pro Git
  • 2. ? • a.k.a. ihower • http://ihower.tw • http://twitter.com/ihower • Ruby on Rails Developer since 2006 • The organizer of Ruby Taiwan Community • http://ruby.tw 2
  • 3. Agenda ‧1. DVCS ‧2. Git ‧3. Git ‧4. Github ‧5. Git 3
  • 4. ‧2002 ( copy ) ‧2005 SubVersion ‧2007 SVK ‧2008 Git ( SVN push/pull) ‧2009 Git ( master feature branches) ‧2011 Git ( git flow topic branch rebase) 4
  • 5. 1. DVCS ? 5
  • 6. Version Control System ‧ repository ‧ ‧ ‧Branch( ) ‧Tag( ) 6
  • 9. Centralized VCS CVS, Subversion, Perforce 8
  • 10. Centralized VCS CVS, Subversion, Perforce 1. 2. Single point of failure 8
  • 11. Distributed VCS Git, Mercurial(Hg), Bazaar 9
  • 12. Distributed VCS Git, Mercurial(Hg), Bazaar workflows ! 9
  • 13. Local development ‧ CSV commit history log ‧ CSV commit history log 10
  • 14. 2. Git ? 11
  • 15. Git ‧ Linux Torvalds (Linux creator) ‧ Linux Kernel ‧2005/4 2005/6 Linix Kernel 2005/12 1.0 12
  • 16. Git? ‧Git ‧Qt ‧Linux Kernel ‧Ruby on Rails ‧Perl ‧Android ‧Eclipse ‧PostgreSQL ‧Gnome ‧Debian ‧KDE ‧X.org 13
  • 18. Git Way metadata snapshots 15
  • 19. Git Way metadata snapshots I’m a mini filesystem! Not just VCS. 15
  • 20. Git Way metadata snapshots I’m a mini filesystem! Not just VCS. Apple Time Machine ! 15
  • 21. : Working tree/Staging area/Repository 16
  • 22. Why Git is Better than X http://zh-tw.whygitisbetterthanx.com ‧ ‧ ‧Git ‧Git ‧Staging ‧ ‧ ‧ GitHub!
  • 23. Git SVN ‧svn merge branch branch ‧svn log ‧svn commit checkout commit 18
  • 24. 3-1. Git 19
  • 25. Install ‧ Git http://help.github.com/set-up-git-redirect ‧ Git GUI(optional) GitX (Mac) TortoiseGit/Git Extensions (Windows) qgit (Linux) ‧ SSH Key ssh-keygen -t rsa -C "your_email@youremail.com" 20
  • 26. Setup ‧ ~/.gitconfig ‧git config --global user.name "Your Name" ‧git config --global user.email "your@email.com" ‧git config --global color.ui true ‧git config --global core.editor "mate -w" (Textmate) 21
  • 27. Setup (Windows only) ‧ ‧git config --global core.autocrlf true ‧git config --global core.safecrlf true 22
  • 29. Repository ‧SSH git clone git@github.com:ihower/sandbox.git ‧HTTP/HTTPS git clone https://ihower@github.com/ihower/sandbox.git ‧ Git protocol ( ) git clone git://github.com/ihower/sandbox.git ‧File ( Dropbox git init --bare --shared !! Crazy!!) git clone file://path/to/repo.git 24
  • 30. commit ‧touch README ‧git add README ‧git status ‧git commit -m “First Commit” 25
  • 31. README ‧git status ‧git diff ‧git add . ( !) ‧git status ‧git diff --cached ‧git commit -m “Update README” 26
  • 32. Staging commit ‧touch a.rb ‧touch b.rb ‧git add a.rb ‧git commit “Update a” ‧git add b.rb ‧git commit “Update b” 27
  • 33. ‧git rm a.rb ‧git mv b.rb c.rb ‧git add . ‧git commit “Remove a, Rename b to c” ‧ copy ? Git cp 28
  • 34. commit Untracked files Changes not Changes to be staged for commit committed 29
  • 35. ‧git log ‧git log --oneline ‧git log --oneline --decorate --graph ‧ GUI 30
  • 36. .gitignore ( commit ) ‧ ~/.gitignore ( Global ) ‧ commit .gitkeep ‧.gitignore https://github.com/github/gitignore 31
  • 37. commit ? ‧tmp/* ‧log/* ‧ ( ) ‧ ‧build/* compile ‧.DS_Store ‧Thumbs.rb 32
  • 38. Commit ‧ / / bug fixed unit test commit commit commit ‧git diff --check ‧commit 33
  • 39. 3-2. Git 34
  • 40. Branch ? ‧topic feature ‧Bug fixes ‧ (refactor) ‧ 35
  • 41. branch ‧git branch new_feature ‧git branch ‧git checkout new_feature ‧touch new_feature.rb ‧git add new_feature.rb ‧git commit -m “New feature” 36
  • 42. branch ‧git branch new_feature ‧git branch ‧git checkout new_feature ‧touch new_feature.rb ‧git add new_feature.rb ‧git commit -m “New feature” checkout working tree 36
  • 43. branch ‧git checkout master ‧git merge new_feature 37
  • 44. 38
  • 47. (master) git branch hotfix (hotfix) git commit 41
  • 48. (master) git merge hotfix 42
  • 49. (master) git merge hotfix fast-forward 42
  • 51. (master) git merge iss53 44
  • 52. (master) git merge iss53 C6 merge commit 44
  • 53. ‧Straight merge branch commits merge commit Parents fast-forward merge commit --no-ff 45
  • 54. (cont.) ‧Squashed commit git merge new_feature --squash merge-commit log SVN merge ‧cherry-pick git cherry-pick 714cba commit 46
  • 55. branch ‧ working tree branch staging area modified ‧ commit push reset ‧ stash git stash git stash apply git stash clear 47
  • 56. 3-3. Git push 48
  • 57. push branch ... ‧ SVN Git Commit commit logs!! commits commit commit commits commits 49
  • 58. reset ( commit ) ‧git reset e37c75787 ‧git reset HEAD^ ( working tree) ‧git reset HEAD^ --soft ( staging area) ‧git reset HEAD^ --hard ( ) 50
  • 59. revert ( commit ) ‧ reset revert commit ‧git revert e37c75787 ‧git revert HEAD^ 51
  • 60. rebase ( commit ) ‧git rebase -i e37c7578 pick 048b59e first commit pick 995dbb3 change something pick aa3e16e changed # Rebase 0072886..1b6475f onto 0072886 # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit's log message # x, exec = run command (the rest of the line) using shell # # If you remove a line here THAT COMMIT WILL BE LOST. # However, if you remove everything, the rebase will be aborted. 52
  • 61. : rebase ‧rebase ( local branch) 1. branch 2. branch commits apply/patch commit log local branch 53
  • 62. : new_feature master D---E new_feature / A---B---C---F master 54
  • 63. merge (new_feature) git merge master D--------E / A---B---C---F----G new_feature master 55
  • 64. rebase G ! (new_feature) git rebase master A---B---C---F---D'---E' new_feature master 56
  • 65. rebase G ! (new_feature) git rebase master A---B---C---F---D'---E' new_feature master merge commit 56
  • 66. push commits push !! 57
  • 67. rebase + merge ( feature branch develop) ‧ feature branch merge feature branch typo commit feature branch commits ‧ feature branch git rebase develop -i ( ) git rebase -i develop branch git merge feature --no-ff 58
  • 69. (1) ‧ --no-ff merge commit fast-forward ‧rebase feature branch push ‧ feature branch 60
  • 70. (2) ‧ rebase conflict ‧ rebase branch rebase 61
  • 71. 4. Github ? 62
  • 73. =
  • 74. GitHub? ‧twitter ‧jQuery ‧facebook ‧YUI 3 ‧rackspace ‧mootools ‧digg ‧Ruby on Rails ‧Yahoo! ‧node.js ‧shopify ‧symfony ‧EMI ‧mongodb ‧six apart ‧Erlang 65
  • 75. Watch! Fork
  • 76. 67
  • 78. Patch ? ‧Fork Repository ‧Clone ‧Fix bugs Enhance features ‧Push ‧ Pull request 69
  • 79. Fork & Pull Requests 75% fork outside merge !! watch 25% outside contributions !! 70
  • 81. Wiki 72
  • 83. Download Source or Package 74
  • 84. Github pages http://pages.github.com/ ‧ your.github.com repository Github http://your.github.com ‧ gh-pages your_project Github http://your.github.com/your_project 75
  • 85. Github pages http://pages.github.com/ ‧ your.github.com repository Github http://your.github.com ‧ gh-pages your_project Github http://your.github.com/your_project Git ( Branch merge) 75
  • 86. 3-4. Git 76
  • 87. Push GitHub Reporitory ‧ Github ‧git remote add origin git@github.com:your_account/ sandbox.git ‧git push -u origin master ‧ git push ![rejected] git pull 77
  • 88. Pull ‧git pull origin master git pull git fetch branch branch merge ‧git pull --rebase rebase 78
  • 89. git pull --rebase merge http://ihower.tw/blog/archives/3843 79
  • 90. git pull --rebase merge http://ihower.tw/blog/archives/3843 branch master ! 79
  • 91. git pull merge? rebase? ‧ conflict merge feature branch ? ‧ conflict --rebase 80
  • 92. git pull merge? rebase? ‧ conflict merge feature branch ? ‧ conflict --rebase git flow branches merge ! 80
  • 93. Git Submodule ‧Git SVN ‧ ? SVN Externals? ‧ http://josephjiang.com/entry.php?id=342 ‧ ? http://josephjiang.com/entry.php?id=357 ‧ Ruby/Rails Develops XD Bundler dependencies 81
  • 94. ‧git tag ‧git archive ‧git bisect ‧git blame ‧git grep ‧git show ‧git reflog ( commits 90 ) ‧git gc 82
  • 95. 5. Git 83
  • 96. 1. Repositories ? 84
  • 97. Centralized Workflow Push Repository Branches ( ) 85
  • 98. Integration-Manager Workflow Open Source Push Repository request pull GitHub Fork Pull Request 86
  • 99. Dictator and Lieutenants Workflow Open Source Linux Kernel patch pull request 87
  • 100. 2. Repository Branches ? 88
  • 101. Git flow: branches http://nvie.com/posts/a-successful-git-branching-model/ http://ihower.tw/blog/archives/5140 89
  • 102. ‧master: production-ready ‧develop: 90
  • 103. (1) ‧Feature branches bugs develop merge develop develop ( merge rebase) 91
  • 104. (1) ‧Feature branches bugs develop merge develop develop ( merge rebase) branch!! 91
  • 105. (2) ‧Release branches release bugs develop merge master develop 92
  • 106. (3) ‧Hotfix branches release master master merge master develop 93
  • 107. : Feature branches : develop release branches : hotfix branches : master 94
  • 108. git-flow ‧git flow init ‧git flow feature finish feature_name ‧git flow feature publish feature_name ‧git flow feature track feature_name ‧git flow feature finish feature_name 95
  • 109. Branch-Owner Policy ‧ project leaders commit/merge develop branch ‧ release team master branch ‧ topic branches pull request code review merge develop ‧GitHub pull request 96
  • 110. Code Review 97
  • 111. Branch Diff 98
  • 112. the maintainer workflow for git itself http://www.kernel.org/pub/software/scm/git/docs/gitworkflows.html ‧master tracks the commits that should go into the next release ‧maint tracks the commits that should go into the next "maintenance release" ‧next is intended as a testing branch for topics being tested for stability for master. ‧pu (proposed updates branches) is an integration branch for things that are not quite ready for inclusion yet ‧topic branches for any nontrivial feature99
  • 113. Ruby on Rails workflow ‧ Rails 3.0.5 ‧master release 3.1 ‧stable branches 2-2-stable 2-3-stable bug fixes 3-0-stable bug fixes 100
  • 115. git-svn ‧ SubVersion Git Git ! ‧git svn clone http://url/svn/trunk/ project_name ‧(normal git operations) ‧git svn dcommit 102