Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Git

1,128 views

Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Git

  1. 1. Fundamentals of GitUsage and InternalsJimmy Thrasher <jimmy@brownbirdlabs.com> @jimmythrasher
  2. 2. git(n) - a contemptible person, often a fool
  3. 3. Philosophy
  4. 4. Basic Usage, Pass I
  5. 5. Initialize the repo
  6. 6. Initialize the repo$ mkdir arithmetic; cd arithmetic
  7. 7. Initialize the repo$ mkdir arithmetic; cd arithmetic$ git init
  8. 8. Initialize the repo$ mkdir arithmetic; cd arithmetic$ git initInitialized empty Git repository in <path>/arithmetic/.git/
  9. 9. Generate some code $ cat > arithmetic.rb def plus(a, b); a + b; end ^D
  10. 10. Stage the changes
  11. 11. Stage the changes$ git add .
  12. 12. Stage the changes$ git add .$ git status
  13. 13. Stage the changes$ git add .$ git status# On branch master## Initial commit## Changes to be committed:# (use "git rm --cached <file>..." to unstage)## new file: arithmetic.rb#
  14. 14. Commit!
  15. 15. Commit!$ git commit -m "First post"
  16. 16. Commit!$ git commit -m "First post"[master (root-commit) 0ca3306] First post 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 arithmetic.rb
  17. 17. 20 GOTO 10
  18. 18. Basic Usage, Pass II
  19. 19. $ mkdir arithmetic; cd arithmetic$ git initInitialized empty Git repository in <path>/arithmetic/.git/
  20. 20. $ ls -l .git
  21. 21. $ ls -l .gittotal 24-rw-r--r-- 1 jjthrash staff 23 Nov 6 21:05 HEAD-rw-r--r-- 1 jjthrash staff 111 Nov 6 21:05 config-rw-r--r-- 1 jjthrash staff 73 Nov 6 21:05 descriptiondrwxr-xr-x 12 jjthrash staff 408 Nov 6 21:05 hooksdrwxr-xr-x 3 jjthrash staff 102 Nov 6 21:05 infodrwxr-xr-x 4 jjthrash staff 136 Nov 6 21:05 objectsdrwxr-xr-x 4 jjthrash staff 136 Nov 6 21:05 refs
  22. 22. Generate some code $ cat > arithmetic.rb def plus(a, b); a + b; end ^D
  23. 23. $ git add .$ git status# On branch master## Initial commit## Changes to be committed:# (use "git rm --cached <file>..." to unstage)## new file: arithmetic.rb#
  24. 24. The Object Store
  25. 25. $ cat arithmetic.rb | git hash-object --stdin
  26. 26. $ cat arithmetic.rb | git hash-object --stdin171fe423f0146d107db5d5c94ba205d86549ff14
  27. 27. $ cat arithmetic.rb | git hash-object --stdin171fe423f0146d107db5d5c94ba205d86549ff14$ git cat-file -p 171fe423f0146d107db5d5c94ba205d86549ff14
  28. 28. $ cat arithmetic.rb | git hash-object --stdin171fe423f0146d107db5d5c94ba205d86549ff14$ git cat-file -p 171fe423f0146d107db5d5c94ba205d86549ff14def plus(a, b); a + b; end
  29. 29. $ cat arithmetic.rb | git hash-object --stdin171fe423f0146d107db5d5c94ba205d86549ff14$ git cat-file -p 171fe423f0146d107db5d5c94ba205d86549ff14def plus(a, b); a + b; end$ find .git/objects -type f
  30. 30. $ cat arithmetic.rb | git hash-object --stdin171fe423f0146d107db5d5c94ba205d86549ff14$ git cat-file -p 171fe423f0146d107db5d5c94ba205d86549ff14def plus(a, b); a + b; end$ find .git/objects -type f.git/objects/17/1fe423f0146d107db5d5c94ba205d86549ff14
  31. 31. $ cat .git/index
  32. 32. $ cat .git/indexarithmetic.rb?k>???#?m}?ϸk?S??`m?I??
  33. 33. $ git commit -m "First post"[master (root-commit) 0ca3306] First post 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 arithmetic.rb
  34. 34. More Object Store
  35. 35. More Object Store ©Scott Chacon, Fig 9-1 “Git Internals—Git Objects”
  36. 36. More Object Store
  37. 37. More Object Store ©Scott Chacon, Fig 9-3 “Git Internals—Git Objects”
  38. 38. $ git rev-parse HEAD
  39. 39. $ git rev-parse HEAD0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3
  40. 40. $ git rev-parse HEAD0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3$ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3
  41. 41. $ git rev-parse HEAD0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3$ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3tree a9974d0f707a302dfd82370c357e87e1df813658author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463-0500First post
  42. 42. $ git rev-parse HEAD0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3$ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3tree a9974d0f707a302dfd82370c357e87e1df813658author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463-0500First post$ git cat-file -p a9974d0f707a302dfd82370c357e87e1df813658
  43. 43. $ git rev-parse HEAD0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3$ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3tree a9974d0f707a302dfd82370c357e87e1df813658author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463-0500First post$ git cat-file -p a9974d0f707a302dfd82370c357e87e1df813658100644 blob 171fe423f0146d107db5d5c94ba205d86549ff14arithmetic.rb
  44. 44. $ git rev-parse HEAD0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3$ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3tree a9974d0f707a302dfd82370c357e87e1df813658author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463-0500First post$ git cat-file -p a9974d0f707a302dfd82370c357e87e1df813658100644 blob 171fe423f0146d107db5d5c94ba205d86549ff14arithmetic.rb$ cat arithmetic.rb | git hash-object --stdin
  45. 45. $ git rev-parse HEAD0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3$ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3tree a9974d0f707a302dfd82370c357e87e1df813658author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463-0500First post$ git cat-file -p a9974d0f707a302dfd82370c357e87e1df813658100644 blob 171fe423f0146d107db5d5c94ba205d86549ff14arithmetic.rb$ cat arithmetic.rb | git hash-object --stdin171fe423f0146d107db5d5c94ba205d86549ff14
  46. 46. $ find .git/objects -type f
  47. 47. $ find .git/objects -type f.git/objects/0c/a330690c2d1471ca4aa4c18c8fe3f53883f7a3.git/objects/17/1fe423f0146d107db5d5c94ba205d86549ff14.git/objects/a9/974d0f707a302dfd82370c357e87e1df813658
  48. 48. Recap
  49. 49. Refs
  50. 50. $ find .git/refs -type f
  51. 51. $ find .git/refs -type f.git/refs/heads/master
  52. 52. $ find .git/refs -type f.git/refs/heads/master$ cat .git/refs/heads/master
  53. 53. $ find .git/refs -type f.git/refs/heads/master$ cat .git/refs/heads/master0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3
  54. 54. $ find .git/refs -type f.git/refs/heads/master$ cat .git/refs/heads/master0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3$ git log
  55. 55. $ find .git/refs -type f.git/refs/heads/master$ cat .git/refs/heads/master0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3$ git logcommit 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 (HEAD, master)Author: Jimmy Thrasher <jimmy@jimmythrasher.com>Date: Tue Nov 6 21:14:23 2012 -0500 First post
  56. 56. $ find .git/refs -type f.git/refs/heads/master$ cat .git/refs/heads/master0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3$ git logcommit 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 (HEAD, master)Author: Jimmy Thrasher <jimmy@jimmythrasher.com>Date: Tue Nov 6 21:14:23 2012 -0500 First post$ cat .git/HEAD
  57. 57. $ find .git/refs -type f.git/refs/heads/master$ cat .git/refs/heads/master0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3$ git logcommit 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 (HEAD, master)Author: Jimmy Thrasher <jimmy@jimmythrasher.com>Date: Tue Nov 6 21:14:23 2012 -0500 First post$ cat .git/HEADref: refs/heads/master
  58. 58. Making History
  59. 59. Add another commit
  60. 60. Add another commit$ cat >> arithmetic.rb
  61. 61. Add another commit$ cat >> arithmetic.rbdef minus(a, b); a - b; end
  62. 62. Add another commit$ cat >> arithmetic.rbdef minus(a, b); a - b; end$ git add --patch
  63. 63. Add another commit$ cat >> arithmetic.rbdef minus(a, b); a - b; end$ git add --patchdiff --git a/arithmetic.rb b/arithmetic.rbindex 171fe42..5c66815 100644--- a/arithmetic.rb+++ b/arithmetic.rb@@ -1 +1,2 @@ def plus(a, b); a + b; end+def minus(a, b); a - b; endStage this hunk [y,n,q,a,d,/,e,?]? y
  64. 64. Add another commit$ cat >> arithmetic.rbdef minus(a, b); a - b; end$ git add --patchdiff --git a/arithmetic.rb b/arithmetic.rbindex 171fe42..5c66815 100644--- a/arithmetic.rb+++ b/arithmetic.rb@@ -1 +1,2 @@ def plus(a, b); a + b; end+def minus(a, b); a - b; endStage this hunk [y,n,q,a,d,/,e,?]? y$ git commit -m "Double the featureset"
  65. 65. Add another commit$ cat >> arithmetic.rbdef minus(a, b); a - b; end$ git add --patchdiff --git a/arithmetic.rb b/arithmetic.rbindex 171fe42..5c66815 100644--- a/arithmetic.rb+++ b/arithmetic.rb@@ -1 +1,2 @@ def plus(a, b); a + b; end+def minus(a, b); a - b; endStage this hunk [y,n,q,a,d,/,e,?]? y$ git commit -m "Double the featureset"[master d4655dd] Double the featureset 1 files changed, 1 insertions(+), 0 deletions(-)
  66. 66. $ # the commit$ git cat-file -p d4655ddec0830408c8a9eb2e97ff882254aa72ce
  67. 67. $ # the commit$ git cat-file -p d4655ddec0830408c8a9eb2e97ff882254aa72cetree adaa5519b385d57417efc1667a9ab9d86473e578parent 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222 -0500committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222-0500Double the featureset
  68. 68. $ # the commit$ git cat-file -p d4655ddec0830408c8a9eb2e97ff882254aa72cetree adaa5519b385d57417efc1667a9ab9d86473e578parent 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222 -0500committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222-0500Double the featureset$ # the tree$ git cat-file -p adaa5519b385d57417efc1667a9ab9d86473e578
  69. 69. $ # the commit$ git cat-file -p d4655ddec0830408c8a9eb2e97ff882254aa72cetree adaa5519b385d57417efc1667a9ab9d86473e578parent 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222 -0500committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222-0500Double the featureset$ # the tree$ git cat-file -p adaa5519b385d57417efc1667a9ab9d86473e578100644 blob 5c66815e4bccb85068bc884ea7963fd45347c212 arithmetic.rb
  70. 70. $ # the commit$ git cat-file -p d4655ddec0830408c8a9eb2e97ff882254aa72cetree adaa5519b385d57417efc1667a9ab9d86473e578parent 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222 -0500committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222-0500Double the featureset$ # the tree$ git cat-file -p adaa5519b385d57417efc1667a9ab9d86473e578100644 blob 5c66815e4bccb85068bc884ea7963fd45347c212 arithmetic.rb$ # the old commit$ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3
  71. 71. $ # the commit$ git cat-file -p d4655ddec0830408c8a9eb2e97ff882254aa72cetree adaa5519b385d57417efc1667a9ab9d86473e578parent 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222 -0500committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222-0500Double the featureset$ # the tree$ git cat-file -p adaa5519b385d57417efc1667a9ab9d86473e578100644 blob 5c66815e4bccb85068bc884ea7963fd45347c212 arithmetic.rb$ # the old commit$ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3tree a9974d0f707a302dfd82370c357e87e1df813658author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463-0500First post
  72. 72. $ # the commit$ git cat-file -p d4655ddec0830408c8a9eb2e97ff882254aa72cetree adaa5519b385d57417efc1667a9ab9d86473e578parent 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222 -0500committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222-0500Double the featureset$ # the tree$ git cat-file -p adaa5519b385d57417efc1667a9ab9d86473e578100644 blob 5c66815e4bccb85068bc884ea7963fd45347c212 arithmetic.rb$ # the old commit$ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3tree a9974d0f707a302dfd82370c357e87e1df813658author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463-0500First post$ # the old tree$ git cat-file -p a9974d0f707a302dfd82370c357e87e1df813658
  73. 73. $ # the commit$ git cat-file -p d4655ddec0830408c8a9eb2e97ff882254aa72cetree adaa5519b385d57417efc1667a9ab9d86473e578parent 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222 -0500committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222-0500Double the featureset$ # the tree$ git cat-file -p adaa5519b385d57417efc1667a9ab9d86473e578100644 blob 5c66815e4bccb85068bc884ea7963fd45347c212 arithmetic.rb$ # the old commit$ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3tree a9974d0f707a302dfd82370c357e87e1df813658author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463-0500First post$ # the old tree$ git cat-file -p a9974d0f707a302dfd82370c357e87e1df813658100644 blob 171fe423f0146d107db5d5c94ba205d86549ff14arithmetic.rb
  74. 74. Object Store©Scott Chacon, Fig 9-3 “Git Internals—Git Objects”
  75. 75. Branching and Merging
  76. 76. $ git cat-file -p HEAD
  77. 77. $ git cat-file -p HEADtree 6436ce8f07792aec3ec132fc4abb59d2a827cba7parent 772883c59078484dc8990ffbc509e249e22a6c84parent ff3ab8a25f623d4ceb3ea189090879dc67693cb5author Rafael Mendonça França <rafaelmfranca@gmail.com> 1352404208-0800committer Rafael Mendonça França <rafaelmfranca@gmail.com>1352404208 -0800Merge pull request #8115 from senny/7842_handle_trailing_slash_with_engineshandle trailing slash with engines (test case for #7842)
  78. 78. master (HEAD) C1
  79. 79. git checkout -b bug-142 master master C1bug-142 (HEAD)
  80. 80. #change code git commit -am “Fix problem with the widgets” C2 bug-142 (HEAD)master C1
  81. 81. git checkout master C2 bug-142master (HEAD) C1
  82. 82. # make more changes git commit -am “Moar changes!!1!”master (HEAD) C3 C2 bug-142 C1
  83. 83. git merge bug-142master (HEAD) C4 C3 C2 bug-142 C1
  84. 84. Rebasing
  85. 85. # got 2 branchesmaster (HEAD) C3 C2 bug-142 C1
  86. 86. git checkout bug-142master C3 C2 bug-142 (HEAD) C1
  87. 87. git rebase master C4 bug-142 (HEAD)master C3 C2 C1
  88. 88. What didn’t I cover?• Workflow recommendations• Remotes, tags, “tree-ish”• Working with other developers• GitHub Pull Requests• Handy tips and tricks• etc
  89. 89. I Recommend• Pro-Git, by Scott Chacon (free ebook)• Everything git-related by @tpope
  90. 90. Thank You!
  91. 91. Q&A

×