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

Git, GitHub, Etc

Git, GitHub, Etc

How git and GitHub work, behind the scenes. Aka what I do in my day job.

Andy Delcambre

April 19, 2014
Tweet

More Decks by Andy Delcambre

Other Decks in Programming

Transcript

  1. Git, GitHub, Etc
    Andy Delcambre

    View Slide

  2. View Slide

  3. View Slide

  4. PLANET ARGON

    View Slide

  5. View Slide

  6. View Slide

  7. View Slide

  8. View Slide

  9. DIRECTED
    ACYCLIC
    GRAPH

    View Slide

  10. yt $ git init
    Initialized empty Git repository in /private/tmp/demo/.git/
    yt $ echo "My sweet repo" > README
    yt ✗ $ git add README
    yt ✗ $ git status
    # On branch master
    #
    # Initial commit
    #
    # Changes to be committed:
    # (use "git rm --cached ..." to unstage)
    #
    # new file: README
    #
    yt ✗ $ git commit -m "Add a README"
    [master (root-commit) 8a720fa] Add a README
    1 file changed, 1 insertion(+)
    create mode 100644 README
    yt $ git log
    commit 8a720fa06710948f2ab79dd3e213ef745b6000c5
    Author: Andy Delcambre
    Date: Mon Apr 14 15:41:34 2014 -0700
    !
    Add a README

    View Slide

  11. 8a720fa
    HEAD, master
    Refs
    Commit

    View Slide

  12. yt $ echo "It's so awesome" >> README
    yt ✗ $ git add README
    yt ✗ $ git commit -m "Update README"
    [master ede0fc8] Update README
    1 file changed, 1 insertion(+)
    yt $ git log --graph --decorate --pretty=oneline
    * ede0fc8 (HEAD, master) Update README
    * 8a720fa Add a README%

    View Slide

  13. Commit
    8a720fa
    ede0fc8
    HEAD, master
    Refs
    Commit

    View Slide

  14. yt $ git cat-file -p ede0fc8
    tree 493fc85c806ebd9e49395561d2f9c98a5d9ebdce
    parent 8a720fa06710948f2ab79dd3e213ef745b6000c5
    author Andy Delcambre 1397516385 -0700
    committer Andy Delcambre 1397516385 -0700
    !
    Update README

    View Slide

  15. Commit ede0fc8
    8a720fa
    493fc85
    Parent
    Tree

    View Slide

  16. yt $ git cat-file -p 493fc85
    100644 blob 17ca828132ebdc5347f4c5c20484b9a33fffb294 README
    !

    View Slide

  17. Tree 493fc85
    17ca828 Blob (README)

    View Slide

  18. yt $ git cat-file -p 17ca828
    My sweet repo
    It's so awesome

    View Slide

  19. GitHub

    View Slide

  20. Secret:

    View Slide

  21. Hosting a Git repo is
    Secret:

    View Slide

  22. Hosting a Git repo is
    Secret:
    EASY

    View Slide

  23. enzo $ git init --bare demo.git
    Initialized empty Git repo in /home/adelcambre/git/demo.git/
    !
    yt $ git remote add origin [email protected]:git/demo.git
    yt $ git push origin master
    Counting objects: 6, done.
    Delta compression using up to 8 threads.
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (6/6), 473 bytes, done.
    Total 6 (delta 0), reused 6 (delta 0)
    To [email protected]:git/demo.git
    * [new branch] master -> master
    !
    yt $ git clone [email protected]:git/demo.git
    Cloning into 'demo'...
    remote: Counting objects: 6, done.
    remote: Compressing objects: 100% (2/2), done.
    remote: Total 6 (delta 0), reused 0 (delta 0)
    Receiving objects: 100% (6/6), done.

    View Slide

  24. View Slide

  25. yt $ git remote add -f origin [email protected]:adelcambre/demo.git
    Updating origin
    From github.com:adelcambre/demo
    * [new branch] master -> origin/master
    !
    yt $ git push origin master
    Counting objects: 6, done.
    Delta compression using up to 8 threads.
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (6/6), 473 bytes, done.
    Total 6 (delta 0), reused 6 (delta 0)
    To https://github.com/adelcambre/demo.git
    * [new branch] master -> master

    View Slide

  26. View Slide

  27. View Slide

  28. GitHub
    Flow

    View Slide

  29. Make a branch

    View Slide

  30. Add Commits

    View Slide

  31. Open a Pull
    Request

    View Slide

  32. Discuss &
    Code Review

    View Slide

  33. Merge and
    deploy

    View Slide

  34. View Slide

  35. Not so Secret:

    View Slide

  36. Hosting a *lot* of Git repos is
    Not so Secret:

    View Slide

  37. Hosting a *lot* of Git repos is
    Not so Secret:
    HARD

    View Slide

  38. > 7 million
    repositories

    View Slide

  39. 1.5 million
    pushes

    View Slide

  40. 100 million
    pulls & clones

    View Slide

  41. 27
    fileservers

    View Slide

  42. 100 TB of
    online storage

    View Slide

  43. View Slide

  44. Grit

    View Slide

  45. 1st Commit
    GitHub

    View Slide

  46. 1st Commit
    GitHub
    1st Commit
    Grit

    View Slide

  47. Ruby
    wrapper around
    Git

    View Slide

  48. repo = Grit::Repo.new(“grit.git”)
    !
    repo.commits
    # => [#"e80bbd2ce67651aa18e57fb0b43618ad4baf7750">,
    #"91169e1f5fa4de2eaea3f176461f5dc784796769">,
    #"038af8c329ef7c1bae4568b98bd5c58510465493">,
    #"40d3057d09a7a4d61059bca9dca5ae698de58cbe">,
    #"4ea50f4754937bf19461af58ce3b3d24c77311d9">]

    View Slide

  49. This works for
    everything!
    !
    (locally)

    View Slide

  50. 27
    fileservers

    View Slide

  51. Smoke
    “Grit in the cloud”

    View Slide

  52. The
    Internet
    Chimney
    fs102
    fs103
    fs104
    fs105

    fe102
    fe103
    fe104
    fe105

    View Slide

  53. The
    Internet
    Chimney
    fs102
    fs103
    fs104
    fs105

    fe102
    fe103
    fe104
    fe105

    View Slide

  54. The
    Internet
    Chimney
    fs102
    fs103
    fs104
    fs105

    fe102
    fe103
    fe104
    fe105

    View Slide

  55. The
    Internet
    Chimney
    fs102
    fs103
    fs104
    fs105

    fe102
    fe103
    fe104
    fe105

    View Slide

  56. The
    Internet
    Chimney
    fs102
    fs103
    fs104
    fs105

    fe102
    fe103
    fe104
    fe105

    BERTRPC

    View Slide

  57. module Smoke
    def self.install!
    ::Grit.send(:remove_const,
    :Git)
    !
    ::Grit.const_set(:Git,
    Smoke::Git)
    end
    end

    View Slide

  58. repo.ls_tree("HEAD").each do |
    entry|
    if entry.blob?
    repo.load_blob(entry.oid)
    end
    end

    View Slide

  59. Death by
    Round Trip

    View Slide

  60. A condensed
    (and probably wrong)
    history of git

    View Slide

  61. Bitkeeper

    View Slide

  62. Git

    View Slide

  63. Shared library?

    View Slide

  64. libgit2

    View Slide

  65. JGit

    View Slide

  66. libgit2
    http://github.com/libgit2/libgit2

    View Slide

  67. Rugged
    http://github.com/libgit2/rugged

    View Slide

  68. Ruby
    wrapper around
    libgit2

    View Slide

  69. repo =
    Rugged::Repository.new("rugged.git")
    !
    repo.last_commit
    # => #0277b7df0fea08d5f3fc7177e47527fc24d96a0e>

    View Slide

  70. View Slide

  71. GitRPC
    The New Hotness
    aka

    View Slide

  72. Like Smoke,
    But Better

    View Slide

  73. Caching

    View Slide

  74. Pluggable
    Wire Protocols

    View Slide

  75. Encoding
    Aware

    View Slide

  76. This is
    My Job

    View Slide

  77. education.github.com

    View Slide

  78. Questions!
    Git for Computer Scientists
    http://eagain.net/articles/git-for-computer-scientists/
    My mom told me git doesn’t scale
    https://vimeo.com/64716825
    GitHub Flow
    https://guides.github.com/introduction/flow/index.html
    How GitHub uses GitHub to build Github
    http://zachholman.com/talk/how-github-uses-github-to-build-github/

    View Slide