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

Git masterclass

Git masterclass

Slides for a git tutorial given at BT.

Watch the talk at http://youtu.be/L7_iMewv5vQ

Download the exercises from https://bitbucket.org/kerryb/git-masterclass/get/5a1a41e6869e.zip

Kerry Buckley

March 09, 2015
Tweet

More Decks by Kerry Buckley

Other Decks in Technology

Transcript

  1. Kerry  Buckley  –  9  March  2015

  2. Topics

  3. Background Topics

  4. Background The basics Topics

  5. Background The basics Precision staging Topics

  6. Background The basics Precision staging Branches Topics

  7. Background The basics Precision staging Branches Tags Topics

  8. Background The basics Precision staging Branches Tags Internals Topics

  9. Background The basics Precision staging Branches Tags Internals Merge &

    rebase Topics
  10. Background The basics Precision staging Branches Tags Internals Merge &

    rebase Distributed git Topics
  11. Background The basics Precision staging Branches Tags Internals Merge &

    rebase Distributed git Patches & email Topics
  12. Background The basics Precision staging Branches Tags Internals Merge &

    rebase Distributed git Patches & email Team workflows Topics
  13. Background The basics Precision staging Branches Tags Internals Merge &

    rebase Distributed git Patches & email Team workflows Hooks Topics
  14. Background The basics Precision staging Branches Tags Internals Merge &

    rebase Distributed git Patches & email Team workflows Hooks Rewriting history Topics
  15. Background The basics Precision staging Branches Tags Internals Merge &

    rebase Distributed git Patches & email Team workflows Hooks Rewriting history Working with svn Topics
  16. Background The basics Precision staging Branches Tags Internals Merge &

    rebase Distributed git Patches & email Team workflows Hooks Rewriting history Working with svn Fixing mistakes Topics
  17. Part I: Background In which we look at some fundamental

    concepts, and learn to ignore most of git’s multitude of commands
  18. Alice’s  computer Version  DB Version  3 Version  2 Version  1

    File
  19. Bob’s  computer Server Alice’s  computer Version  DB Version  3 Version

     2 Version  1 File File
  20. Alice’s  computer Version  DB Version  3 Version  2 Version  1

    File
  21. Alice’s  computer Version  DB Version  3 Version  2 Version  1

    File
  22. Alice’s  computer Version  DB Version  3 Version  2 Version  1

    File Bob’s  computer Version  DB Version  3 Version  2 Version  1 File Server Version  DB Version  3 Version  2 Version  1
  23. Alice’s  computer Version  DB Version  3 Version  2 Version  1

    File Bob’s  computer Version  DB Version  3 Version  2 Version  1 File Server Version  DB Version  3 Version  2 Version  1
  24. Alice’s  computer Version  DB Version  3 Version  2 Version  1

    File Index   (staging  area)
  25. add add‑‑interactive am annotate apply archimport archive bisect bisect‑‑helper blame

    branch bundle cat‑file check‑attr check‑ignore check‑mailmap check‑ref‑format checkout checkout‑index cherry cherry‑pick citool clean clone column commit commit‑tree config count‑objects credential credential‑cache credential‑cache‑‑daemon credential‑store cvsexportcommit cvsimport cvsserver daemon describe diff diff‑files diff‑index diff‑tree difftool difftool‑‑helper fast‑export fast‑import fetch fetch‑pack filter‑branch fmt‑merge‑msg for‑each‑ref format‑patch fsck fsck‑objects gc get‑tar‑commit‑id grep gui gui‑‑askpass hash‑object help http‑backend http‑fetch http‑push index‑pack init init‑db instaweb interpret‑trailers log ls‑files ls‑remote ls‑tree mailinfo mailsplit merge merge‑base merge‑file merge‑index merge‑octopus merge‑one‑file merge‑ours merge‑recursive merge‑resolve merge‑subtree merge‑tree mergetool mktag mktree mv name‑rev notes p4 pack‑objects pack‑redundant pack‑refs patch‑id prune prune‑packed pull push quiltimport read‑tree rebase receive‑pack reflog relink remote remote‑ext remote‑fd remote‑ftp remote‑ftps remote‑http remote‑https remote‑testsvn repack replace request‑pull rerere reset rev‑list rev‑parse revert rm send‑email send‑pack sh‑i18n‑‑envsubst shell shortlog show show‑branch show‑index show‑ref stage stash status stripspace submodule svn symbolic‑ref tag unpack‑file unpack‑objects update‑index update‑ref update‑server‑info upload‑archive upload‑pack var verify‑commit verify‑pack verify‑tag web‑‑browse whatchanged write‑tree h"ps:/ /www.flickr.com/photos/abirkill/3494123087
  26. h"ps:/ /www.flickr.com/photos/loop_oh/6277684962 h"ps:/ /www.flickr.com/photos/abirkill/3494123087

  27. add add‑‑interactive am annotate apply archimport archive bisect bisect‑‑helper blame

    branch bundle cat‑file check‑attr check‑ignore check‑mailmap check‑ref‑format checkout checkout‑index cherry cherry‑pick citool clean clone column commit commit‑tree config count‑objects credential credential‑cache credential‑cache‑‑daemon credential‑store cvsexportcommit cvsimport cvsserver daemon describe diff diff‑files diff‑index diff‑tree difftool difftool‑‑helper fast‑export fast‑import fetch fetch‑pack filter‑branch fmt‑merge‑msg for‑each‑ref format‑patch fsck fsck‑objects gc get‑tar‑commit‑id grep gui gui‑‑askpass hash‑object help http‑backend http‑fetch http‑push index‑pack init init‑db instaweb interpret‑trailers log ls‑files ls‑remote ls‑tree mailinfo mailsplit merge merge‑base merge‑file merge‑index merge‑octopus merge‑one‑file merge‑ours merge‑recursive merge‑resolve merge‑subtree merge‑tree mergetool mktag mktree mv name‑rev notes p4 pack‑objects pack‑redundant pack‑refs patch‑id prune prune‑packed pull push quiltimport read‑tree rebase receive‑pack reflog relink remote remote‑ext remote‑fd remote‑ftp remote‑ftps remote‑http remote‑https remote‑testsvn repack replace request‑pull rerere reset rev‑list rev‑parse revert rm send‑email send‑pack sh‑i18n‑‑envsubst shell shortlog show show‑branch show‑index show‑ref stage stash status stripspace submodule svn symbolic‑ref tag unpack‑file unpack‑objects update‑index update‑ref update‑server‑info upload‑archive upload‑pack var verify‑commit verify‑pack verify‑tag web‑‑browse whatchanged write‑tree
  28. add add‑‑interactive am annotate apply archimport archive bisect bisect‑‑helper blame

    branch bundle cat‑file check‑attr check‑ignore check‑mailmap check‑ref‑format checkout checkout‑index cherry cherry‑pick citool clean clone column commit commit‑tree config count‑objects credential credential‑cache credential‑cache‑‑daemon credential‑store cvsexportcommit cvsimport cvsserver daemon describe diff diff‑files diff‑index diff‑tree difftool difftool‑‑helper fast‑export fast‑import fetch fetch‑pack filter‑branch fmt‑merge‑msg for‑each‑ref format‑patch fsck fsck‑objects gc get‑tar‑commit‑id grep gui gui‑‑askpass hash‑object help http‑backend http‑fetch http‑push index‑pack init init‑db instaweb interpret‑trailers log ls‑files ls‑remote ls‑tree mailinfo mailsplit merge merge‑base merge‑file merge‑index merge‑octopus merge‑one‑file merge‑ours merge‑recursive merge‑resolve merge‑subtree merge‑tree mergetool mktag mktree mv name‑rev notes p4 pack‑objects pack‑redundant pack‑refs patch‑id prune prune‑packed pull push quiltimport read‑tree rebase receive‑pack reflog relink remote remote‑ext remote‑fd remote‑ftp remote‑ftps remote‑http remote‑https remote‑testsvn repack replace request‑pull rerere reset rev‑list rev‑parse revert rm send‑email send‑pack sh‑i18n‑‑envsubst shell shortlog show show‑branch show‑index show‑ref stage stash status stripspace submodule svn symbolic‑ref tag unpack‑file unpack‑objects update‑index update‑ref update‑server‑info upload‑archive upload‑pack var verify‑commit verify‑pack verify‑tag web‑‑browse whatchanged write‑tree
  29. Part II: The Basics In which we create a repository,

    add a few files to it, and track some changes
  30. Create a new repository

  31. Initialized empty Git repository in /Users/kerry/masterclass/.git/ Create a new repository

    $ git init
  32. Add a new file

  33. On branch master Initial commit Untracked files: (use "git add

    <file>..." to include in what will be committed) foo.txt nothing added to commit but untracked files present (use "git add" to track) Add a new file $ git status
  34. Add a new file

  35. Add a new file $ git add foo.txt

  36. On branch master Initial commit Changes to be committed: (use

    "git rm --cached <file>..." to unstage) new file: foo.txt Add a new file $ git add foo.txt $ git status
  37. Add a new file

  38. [master (root-commit) 80ab5d4] Add a file with some placeholder text

    1 file changed, 6 insertions(+) create mode 100644 foo.txt Add a new file $ git commit -m"Add a file with some placeholder text"
  39. Commit a change

  40. On branch master Changes not staged for commit: (use "git

    add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: foo.txt no changes added to commit (use "git add" and/or "git commit -a") Commit a change $ git status
  41. Commit a change

  42. diff --git a/foo.txt b/foo.txt index e1bc2ab..d66717b 100644 --- a/foo.txt +++

    b/foo.txt @@ -1,6 +1,6 @@ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis -nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. +expelliarmus wingardium leviosa expecto patronum imperio crucio avada kedavra Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum Commit a change $ git diff
  43. Commit a change

  44. Commit a change $ git add foo.txt

  45. On branch master Changes to be committed: (use "git reset

    HEAD <file>..." to unstage) modified: foo.txt Commit a change $ git add foo.txt $ git status
  46. Commit a change

  47. Commit a change $ git commit -m"Insert some magic into

    the text"
  48. [master 9e2546a] Insert some magic into the text 1 file

    changed, 1 insertion(+), 1 deletion(-) Commit a change $ git commit -m"Insert some magic into the text"
  49. Alice’s  computer Version  DB Version  3 Version  2 Version  1

    File Index   (staging  area) add rm mv commit
  50. Viewing history

  51. commit 9e2546aef0232daf56635b6319bcf69f788bd5ba Author: Kerry Buckley <kerryjbuckley@gmail.com> Date: 42 seconds ago

    Insert some magic into the text commit 80ab5d44f47c0c2dbbf8ade76d4f85889295d8a4 Author: Kerry Buckley <kerryjbuckley@gmail.com> Date: 10 minutes ago Add a file with some placeholder text Viewing history $ git log
  52. Viewing a commit

  53. commit 9e2546aef0232daf56635b6319bcf69f788bd5ba Author: Kerry Buckley <kerryjbuckley@gmail.com> Date: 2 hours ago

    Insert some magic into the text diff --git a/foo.txt b/foo.txt index e1bc2ab..d66717b 100644 --- a/foo.txt +++ b/foo.txt @@ -1,6 +1,6 @@ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis -nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. +expelliarmus wingardium leviosa expecto patronum imperio crucio avada kedavra Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum Viewing a commit $ git show 9e2546aef0232daf56635b6319bcf69f788bd5ba
  54. Viewing a commit

  55. commit 9e2546aef0232daf56635b6319bcf69f788bd5ba Author: Kerry Buckley <kerryjbuckley@gmail.com> Date: 2 hours ago

    Insert some magic into the text foo.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) Viewing a commit $ git show --stat 9e2546aef0232daf56635b6319bcf69f788bd5ba
  56. Viewing a commit

  57. commit 9e2546aef0232daf56635b6319bcf69f788bd5ba Author: Kerry Buckley <kerryjbuckley@gmail.com> Date: 2 hours ago

    Insert some magic into the text 1 file changed, 1 insertion(+), 1 deletion(-) Viewing a commit $ git show --shortstat 9e2546aef0232daf56635b6319bcf69f788bd5ba
  58. Diff (working dir ↔ staged)

  59. diff --git a/foo.txt b/foo.txt index e1bc2ab..d66717b 100644 --- a/foo.txt +++

    b/foo.txt @@ -1,6 +1,6 @@ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis -nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. +expelliarmus wingardium leviosa expecto patronum imperio crucio avada kedavra Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum Diff (working dir ↔ staged) $ git diff
  60. Diff (working dir ↔ staged)

  61. foo.txt | 2 +- 1 file changed, 1 insertion(+), 1

    deletion(-) Diff (working dir ↔ staged) $ git diff —stat
  62. Diff (arbitrary references)

  63. diff --git a/foo.txt b/foo.txt index e1bc2ab..d66717b 100644 --- a/foo.txt +++

    b/foo.txt @@ -1,6 +1,6 @@ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis -nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. +expelliarmus wingardium leviosa expecto patronum imperio crucio avada kedavra Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum Diff (arbitrary references) $ git diff 80ab5d4 9e2546a
  64. The pickaxe

  65. The pickaxe $ git log -S expelliarmus

  66. commit 9e2546aef0232daf56635b6319bcf69f788bd5ba Author: Kerry Buckley <kerryjbuckley@gmail.com> Date: 5 minutes ago

    Insert some magic into the text The pickaxe $ git log -S expelliarmus
  67. Who did what?

  68. Who did what? $ git blame foo.txt

  69. ^80ab5d4 (Kerry Buckley 2015-03-08 09:45:43 +0000 1) Lorem ipsum dolor

    sit amet ^80ab5d4 (Kerry Buckley 2015-03-08 09:45:43 +0000 2) incididunt ut labore et do 9e2546ae (Kerry Buckley 2015-03-08 09:54:31 +0000 3) expelliarmus wingardium le ^80ab5d4 (Kerry Buckley 2015-03-08 09:45:43 +0000 4) Duis aute irure dolor in r ^80ab5d4 (Kerry Buckley 2015-03-08 09:45:43 +0000 5) fugiat nulla pariatur. Ex ^80ab5d4 (Kerry Buckley 2015-03-08 09:45:43 +0000 6) culpa qui officia deserunt Who did what? $ git blame foo.txt
  70. Add note about good messages Add a note explaining how

    people should format commit messages. Bad commit messages can cause a number of problems: * Truncation of long lines when using git log, and other commands that understand commit commit subject/body separation * Badly-formatted emails from git format-patch * Rejection of pull requests by pedantic maintainers Good commit messages
  71. Add note about good messages Add a note explaining how

    people should format commit messages. Bad commit messages can cause a number of problems: * Truncation of long lines when using git log, and other commands that understand commit commit subject/body separation * Badly-formatted emails from git format-patch * Rejection of pull requests by pedantic maintainers Good commit messages Summary  (up  to  ~50  chars)
  72. Add note about good messages Add a note explaining how

    people should format commit messages. Bad commit messages can cause a number of problems: * Truncation of long lines when using git log, and other commands that understand commit commit subject/body separation * Badly-formatted emails from git format-patch * Rejection of pull requests by pedantic maintainers Good commit messages Impera5ve  mode  (‘add’,  not  ‘added’)
  73. Add note about good messages Add a note explaining how

    people should format commit messages. Bad commit messages can cause a number of problems: * Truncation of long lines when using git log, and other commands that understand commit commit subject/body separation * Badly-formatted emails from git format-patch * Rejection of pull requests by pedantic maintainers Good commit messages Blank  line
  74. Add note about good messages Add a note explaining how

    people should format commit messages. Bad commit messages can cause a number of problems: * Truncation of long lines when using git log, and other commands that understand commit commit subject/body separation * Badly-formatted emails from git format-patch * Rejection of pull requests by pedantic maintainers Good commit messages More  info,  if  necessary  –  wrap  at  72  chars
  75. Exercise time! ©  Freepik  h"p:/ /www.flaBcon.com,  CC  BY  3.0

  76. Part III: Precision staging In which ‘git add’ turns out

    to be not as clumsy or random as a blaster. An elegant weapon, for a more civilized age.
  77. Adding in patch mode

  78. diff --git a/foo.txt b/foo.txt index d66717b..de5974e 100644 --- a/foo.txt +++

    b/foo.txt @@ -1,6 +1,11 @@ +This is a file full of nonsense. + Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis expelliarmus wingardium leviosa expecto patronum imperio crucio avada kedavra Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum + +Pop-up Austin mustache Tumblr Kickstarter next level scenester, typewriter +pour-over. Bespoke gentrify vegan, authentic beard fixie locavore tofu actually. Adding in patch mode $ git diff
  79. Adding in patch mode

  80. diff --git a/foo.txt b/foo.txt index d66717b..de5974e 100644 --- a/foo.txt +++

    b/foo.txt @@ -1,6 +1,11 @@ +This is a file full of nonsense. + Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis expelliarmus wingardium leviosa expecto patronum imperio crucio avada kedavra Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum + +Pop-up Austin mustache Tumblr Kickstarter next level scenester, typewriter +pour-over. Bespoke gentrify vegan, authentic beard fixie locavore tofu actually. Stage this hunk [y,n,q,a,d,/,s,e,?]? Adding in patch mode $ git add -p foo.txt
  81. Adding in patch mode

  82. Split into 2 hunks. @@ -1,6 +1,8 @@ +This is

    a file full of nonsense. + Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis expelliarmus wingardium leviosa expecto patronum imperio crucio avada kedavra Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum Stage this hunk [y,n,q,a,d,/,j,J,g,e,?]? Adding in patch mode Stage this hunk [y,n,q,a,d,/,s,e,?]? s
  83. Adding in patch mode

  84. @@ -1,6 +3,9 @@ Lorem ipsum dolor sit amet, consectetur

    adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis expelliarmus wingardium leviosa expecto patronum imperio crucio avada kedavra Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum + +Pop-up Austin mustache Tumblr Kickstarter next level scenester, typewriter +pour-over. Bespoke gentrify vegan, authentic beard fixie locavore tofu actually. Stage this hunk [y,n,q,a,d,/,j,J,g,e,?]? Adding in patch mode Stage this hunk [y,n,q,a,d,/,s,e,?]? y
  85. Adding in patch mode

  86. Adding in patch mode Stage this hunk [y,n,q,a,d,/,s,e,?]? n

  87. On branch master Changes to be committed: (use "git reset

    HEAD <file>..." to unstage) modified: foo.txt Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: foo.txt Adding in patch mode Stage this hunk [y,n,q,a,d,/,s,e,?]? n $ git status
  88. Adding in interactive mode

  89. On branch master Changes not staged for commit: (use "git

    add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: foo.txt Untracked files: (use "git add <file>..." to include in what will be committed) bar.txt no changes added to commit (use "git add" and/or "git commit -a") Adding in interactive mode $ git status
  90. Adding in interactive mode

  91. staged unstaged path 1: unchanged +5/-0 foo.txt *** Commands ***

    1: status 2: update 3: revert 4: add untracked 5: patch 6: diff 7: quit 8: help What now> Adding in interactive mode $ git add -i
  92. Adding in interactive mode $ git add -i staged unstaged

    path 1: unchanged +5/-0 foo.txt *** Commands *** 1: status 2: update 3: revert 4: add untracked 5: patch 6: diff 7: quit 8: help What now> a 1: bar.txt Add untracked>>
  93. Adding in interactive mode $ git add -i staged unstaged

    path 1: unchanged +5/-0 foo.txt *** Commands *** 1: status 2: update 3: revert 4: add untracked 5: patch 6: diff 7: quit 8: help What now> a 1: bar.txt Add untracked>> 1 * 1: bar.txt Add untracked>>
  94. Adding in interactive mode $ git add -i staged unstaged

    path 1: unchanged +5/-0 foo.txt *** Commands *** 1: status 2: update 3: revert 4: add untracked 5: patch 6: diff 7: quit 8: help What now> a 1: bar.txt Add untracked>> 1 * 1: bar.txt Add untracked>> added one path *** Commands *** 1: status 2: update 3: revert 4: add untracked 5: patch 6: diff 7: quit 8: help What now>
  95. Adding in interactive mode

  96. staged unstaged path 1: +0/-0 nothing bar.txt 2: unchanged +5/-0

    foo.txt *** Commands *** 1: status 2: update 3: revert 4: add untracked 5: patch 6: diff 7: quit 8: help What now> Adding in interactive mode What now> s
  97. Adding in interactive mode What now> s staged unstaged path

    1: +0/-0 nothing bar.txt 2: unchanged +5/-0 foo.txt *** Commands *** 1: status 2: update 3: revert 4: add untracked 5: patch 6: diff 7: quit 8: help What now> p staged unstaged path 1: unchanged +5/-0 foo.txt Patch update>>
  98. Adding in interactive mode What now> s staged unstaged path

    1: +0/-0 nothing bar.txt 2: unchanged +5/-0 foo.txt *** Commands *** 1: status 2: update 3: revert 4: add untracked 5: patch 6: diff 7: quit 8: help What now> p staged unstaged path 1: unchanged +5/-0 foo.txt Patch update>> 1 staged unstaged path * 1: unchanged +5/-0 foo.txt Patch update>>
  99. Adding in interactive mode

  100. diff --git a/foo.txt b/foo.txt index d66717b..de5974e 100644 --- a/foo.txt +++

    b/foo.txt @@ -1,6 +1,11 @@ +This is a file full of nonsense. + Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis expelliarmus wingardium leviosa expecto patronum imperio crucio avada kedavra Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum + +Pop-up Austin mustache Tumblr Kickstarter next level scenester, typewriter +pour-over. Bespoke gentrify vegan, authentic beard fixie locavore tofu actually. Stage this hunk [y,n,q,a,d,/,s,e,?]? Adding in interactive mode Patch update>>
  101. Adding in interactive mode

  102. Split into 2 hunks. @@ -1,6 +1,8 @@ +This is

    a file full of nonsense. + Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis expelliarmus wingardium leviosa expecto patronum imperio crucio avada kedavra Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum Stage this hunk [y,n,q,a,d,/,s,e,?]? Adding in interactive mode Stage this hunk [y,n,q,a,d,/,s,e,?]? s
  103. Adding in interactive mode

  104. @@ -1,6 +3,9 @@ Lorem ipsum dolor sit amet, consectetur

    adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis expelliarmus wingardium leviosa expecto patronum imperio crucio avada kedavra Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum + +Pop-up Austin mustache Tumblr Kickstarter next level scenester, typewriter +pour-over. Bespoke gentrify vegan, authentic beard fixie locavore tofu actually. Stage this hunk [y,n,q,a,d,/,s,e,?]? Adding in interactive mode Stage this hunk [y,n,q,a,d,/,s,e,?]? y
  105. Adding in interactive mode Stage this hunk [y,n,q,a,d,/,s,e,?]? y @@

    -1,6 +3,9 @@ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis expelliarmus wingardium leviosa expecto patronum imperio crucio avada kedavra Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum + +Pop-up Austin mustache Tumblr Kickstarter next level scenester, typewriter +pour-over. Bespoke gentrify vegan, authentic beard fixie locavore tofu actually. Stage this hunk [y,n,q,a,d,/,s,e,?]? n *** Commands *** 1: status 2: update 3: revert 4: add untracked 5: patch 6: diff 7: quit 8: help What now>
  106. Adding in interactive mode

  107. staged unstaged path 1: +0/-0 nothing bar.txt 2: +2/-0 +3/-0

    foo.txt *** Commands *** 1: status 2: update 3: revert 4: add untracked 5: patch 6: diff 7: quit 8: help What now> Adding in interactive mode What now> s
  108. Adding in interactive mode What now> s staged unstaged path

    1: +0/-0 nothing bar.txt 2: +2/-0 +3/-0 foo.txt *** Commands *** 1: status 2: update 3: revert 4: add untracked 5: patch 6: diff 7: quit 8: help What now> q Bye.
  109. Adding in interactive mode

  110. On branch master Changes to be committed: (use "git reset

    HEAD <file>..." to unstage) new file: bar.txt modified: foo.txt Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: foo.txt Adding in interactive mode $ git status
  111. Exercise time! ©  Freepik  h"p:/ /www.flaBcon.com,  CC  BY  3.0

  112. Part IV: Branches In which things start to get a

    little more complicated
  113. None
  114. Create a branch

  115. Switched to a new branch 'my-new-branch' Create a branch $

    git checkout -b my-new-branch
  116. Branch from a specific point

  117. Switched to a new branch 'my-new-branch' Branch from a specific

    point $ git checkout -b my-new-branch 80ab5d
  118. Switched to a new branch 'my-new-branch' Branch from a specific

    point $ git checkout -b my-new-branch 80ab5d Anything  ‘commit-­‐ish’
  119. Referring to commits

  120. Referring to commits Full or partial SHA

  121. Referring to commits Full or partial SHA 9e2546aef0232daf56635b6319bcf69f788bd5ba

  122. Referring to commits Full or partial SHA 9e2546aef0232daf56635b6319bcf69f788bd5ba 9e2546a

  123. Referring to commits Full or partial SHA 9e2546aef0232daf56635b6319bcf69f788bd5ba 9e2546a 9e25

  124. Referring to commits

  125. Referring to commits Branch, tag, or current head

  126. Referring to commits Branch, tag, or current head master

  127. Referring to commits Branch, tag, or current head master my-branch

  128. Referring to commits Branch, tag, or current head master my-branch

    release-1
  129. Referring to commits Branch, tag, or current head master my-branch

    release-1 HEAD
  130. Referring to commits

  131. Referring to commits Ancestors of other commits

  132. Referring to commits Ancestors of other commits HEAD~

  133. Referring to commits Ancestors of other commits HEAD~ master~~~

  134. Referring to commits Ancestors of other commits HEAD~ master~~~ master~3

  135. Referring to commits Ancestors of other commits HEAD~ master~~~ master~3

    9e2546a^
  136. Referring to commits Ancestors of other commits HEAD~ master~~~ master~3

    9e2546a^ 9e2546a^2
  137. Referring to commits Ancestors of other commits HEAD~ master~~~ master~3

    9e2546a^ 9e2546a^2 9e2546a^2~3
  138. Delete a branch

  139. error: The branch 'my-new-branch' is not fully merged. If you

    are sure you want to delete it, run 'git branch -D my-new-branch'. Delete a branch $ git branch -d my-new-branch
  140. error: The branch 'my-new-branch' is not fully merged. If you

    are sure you want to delete it, run 'git branch -D my-new-branch'. Delete a branch $ git branch -d my-new-branch Deleted branch my-new-branch (was 69a5438). $ git branch -D my-new-branch
  141. Exercise time! ©  Freepik  h"p:/ /www.flaBcon.com,  CC  BY  3.0

  142. Part V: Tags In which we wander around our repository,

    pointing at things
  143. Create, move and delete a tag

  144. Create, move and delete a tag $ git tag my-tag

  145. Create, move and delete a tag $ git tag my-tag

    fatal: tag 'my-tag' already exists $ git tag my-tag 80ab5d4
  146. Create, move and delete a tag $ git tag my-tag

    fatal: tag 'my-tag' already exists $ git tag my-tag 80ab5d4 Updated tag 'my-tag' (was 9e2546a) $ git tag -f my-tag 80ab5d4
  147. Create, move and delete a tag $ git tag my-tag

    fatal: tag 'my-tag' already exists $ git tag my-tag 80ab5d4 Updated tag 'my-tag' (was 9e2546a) $ git tag -f my-tag 80ab5d4 Deleted tag 'my-tag' (was 80ab5d4) $ git tag -d my-tag
  148. Exercise time! ©  Freepik  h"p:/ /www.flaBcon.com,  CC  BY  3.0

  149. Part VI: Internals In which we discover how git stores

    files, and are surprised how simple it all is
  150. .git ├── HEAD ├── config ├── description ├── hooks │

    ├── applypatch-msg.sample │ ├── ... │ └── update.sample ├── info │ └── exclude ├── objects │ ├── info │ └── pack └── refs ├── heads └── tags
  151. .git ├── HEAD ├── config ├── description ├── hooks │

    ├── applypatch-msg.sample │ ├── ... │ └── update.sample ├── info │ └── exclude ├── objects │ ├── info │ └── pack └── refs ├── heads └── tags
  152. None
  153. None
  154. h"ps:/ /www.flickr.com/photos/rjw1/2192520114

  155. Garbage collection

  156. Counting objects: 17, done. Delta compression using up to 4

    threads. Compressing objects: 100% (12/12), done. Writing objects: 100% (17/17), done. Total 17 (delta 8), reused 0 (delta 0) Garbage collection $ git gc
  157. Counting objects: 17, done. Delta compression using up to 4

    threads. Compressing objects: 100% (12/12), done. Writing objects: 100% (17/17), done. Total 17 (delta 8), reused 0 (delta 0) Garbage collection $ git gc .git/objects/pack/ ├── pack-3fcf895c12fffd5f7003b5f83f5f721495287349.idx └── pack-3fcf895c12fffd5f7003b5f83f5f721495287349.pack $ tree .git/objects/pack/
  158. Exercise time! ©  Freepik  h"p:/ /www.flaBcon.com,  CC  BY  3.0

  159. Part VII: Merge & Rebase Which is generally where the

    trouble starts
  160. A B E F master branch C D

  161. A B E F master branch git checkout master C

    D
  162. A B E F master branch git checkout master git

    merge branch C D
  163. A B E F master branch C D G

  164. A B E F master branch C D G

  165. A B E F master C D G

  166. A B C D master branch

  167. A B C D master branch git checkout master

  168. A B C D master branch git checkout master git

    merge branch
  169. A B C D master branch

  170. A B C D master branch

  171. A B C D master branch

  172. A B C D master branch git checkout master

  173. A B C D master branch git checkout master git

    merge --squash branch
  174. A B C D master branch E

  175. A B C D master branch

  176. A B C D master branch git checkout master

  177. A B C D master branch git checkout master git

    merge --no-ff branch
  178. A B C D master branch E

  179. A B E F master branch C D

  180. A B E F master branch git checkout branch C

    D
  181. A B E F master branch git checkout branch git

    rebase master C D
  182. A B E F master branch C D

  183. A B E F master branch C D E' F'

  184. A B E F master branch C D E' F'

  185. A B master branch C D E' F'

  186. A B master branch C D E' F' git checkout

    master
  187. A B master branch C D E' F' git checkout

    master git merge --ff-only branch
  188. A B master branch C D E' F'

  189. A B E F master branch C D

  190. A B E F master branch git checkout master C

    D
  191. A B E F master branch git checkout master git

    cherry-pick E C D
  192. A B E F master branch C D E'

  193. Exercise time! ©  Freepik  h"p:/ /www.flaBcon.com,  CC  BY  3.0

  194. Part VIII: Distributed git In which we remember that distribution

    was supposed to be the whole point, and wonder why it took so long to get there
  195. Clone a repository

  196. Cloning into 'rspec'... remote: Counting objects: 807, done. remote: Total

    807 (delta 0), reused 0 (delta 0), pack-reused 807 Receiving objects: 100% (807/807), 96.04 KiB | 20.00 KiB/s, done. Resolving deltas: 100% (308/308), done. Checking connectivity... done. Clone a repository $ git clone git@github.com:rspec/rspec.git
  197. Clone a repository

  198. Clone a repository $ git branch -a

  199. * master remotes/origin/2-0-stable remotes/origin/2-14-maintenance remotes/origin/2-99-maintenance remotes/origin/3-0-maintenance remotes/origin/3-1-maintenance remotes/origin/3-2-maintenance remotes/origin/HEAD ->

    origin/master remotes/origin/experimental remotes/origin/master Clone a repository $ git branch -a
  200. Local  machine Server master   branch my-­‐feature   branch clone

  201. Local  machine Server master   branch my-­‐feature   branch

  202. origin Local  machine Server master   branch my-­‐feature   branch

  203. origin Local  machine Server master   branch my-­‐feature   branch

    origin/master   remote  branch origin/my-­‐feature   remote  branch
  204. origin Local  machine Server master   branch my-­‐feature   branch

    master   branch origin/master   remote  branch origin/my-­‐feature   remote  branch
  205. origin Local  machine Working   copy Server master   branch

    my-­‐feature   branch master   branch origin/master   remote  branch origin/my-­‐feature   remote  branch
  206. Local  machine master   branch Working   copy Server master

      branch my-­‐feature   branch origin/master   remote  branch origin/my-­‐feature   remote  branch fetch
  207. Local  machine master   branch Working   copy Server master

      branch my-­‐feature   branch origin/master   remote  branch origin/my-­‐feature   remote  branch pull
  208. Local  machine master   branch Working   copy my-­‐feature  

    branch Server master   branch my-­‐feature   branch origin/master   remote  branch origin/my-­‐feature   remote  branch push
  209. Exercise time! ©  Freepik  h"p:/ /www.flaBcon.com,  CC  BY  3.0

  210. Part IX: Patches & email For when you don’t have

    direct access to the remote repository
  211. Mailing patches

  212. 9e2546a (HEAD, master) Insert some magic into the text 80ab5d4

    (origin/master) Add a file with some placeholder text Mailing patches $ git log --graph —pretty=format:'%h – %d %s'
  213. 9e2546a (HEAD, master) Insert some magic into the text 80ab5d4

    (origin/master) Add a file with some placeholder text Mailing patches $ git log --graph —pretty=format:'%h – %d %s' 0001-Insert-some-magic-into-the-text.patch $ git format-patch origin/master
  214. Mailing patches

  215. From 9e2546aef0232daf56635b6319bcf69f788bd5ba Mon Sep 17 00:00:00 2001 From: Kerry Buckley

    <kerryjbuckley@gmail.com> Date: Sun, 8 Mar 2015 09:54:31 +0000 Subject: [PATCH] Insert some magic into the text --- foo.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/foo.txt b/foo.txt index e1bc2ab..d66717b 100644 --- a/foo.txt +++ b/foo.txt @@ -1,6 +1,6 @@ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis -nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. +expelliarmus wingardium leviosa expecto patronum imperio crucio avada kedavra Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum -- 2.3.1 Mailing patches
  216. Applying patches

  217. Applying: Insert some magic into the text Applying patches $

    git am 0001-Insert-some-magic-into-the-text.patch
  218. Exercise time! ©  Freepik  h"p:/ /www.flaBcon.com,  CC  BY  3.0

  219. Part X: Team Workflows In which we look for the

    best approach to managing shared code, and find that there’s no one true way
  220. Sharing changes

  221. Sharing changes Direct push/pull between repos

  222. Sharing changes Direct push/pull between repos Maintainer hierarchy

  223. Sharing changes Direct push/pull between repos Maintainer hierarchy Emailed patches

  224. Sharing changes Direct push/pull between repos Maintainer hierarchy Emailed patches

    Central repo (GitHub, GitLab etc)
  225. Sharing changes Direct push/pull between repos Maintainer hierarchy Emailed patches

    Central repo (GitHub, GitLab etc) Shared repo with commit access
  226. Sharing changes Direct push/pull between repos Maintainer hierarchy Emailed patches

    Central repo (GitHub, GitLab etc) Shared repo with commit access Forks and pull requests
  227. History on master

  228. History on master Linear history

  229. History on master Linear history All commits straight to master

  230. History on master Linear history All commits straight to master

    Branch, rebase & merge
  231. History on master Linear history All commits straight to master

    Branch, rebase & merge Branch with merge bubble
  232. Part XI: Hooks By which time the audience is starting

    to tire of these subtitles
  233. .git ├── ... ├── hooks │ ├── applypatch-msg.sample │ ├──

    commit-msg.sample │ ├── post-update.sample │ ├── pre-applypatch.sample │ ├── pre-commit.sample │ ├── pre-push.sample │ ├── pre-rebase.sample │ ├── prepare-commit-msg.sample │ └── update.sample └── ...
  234. pre-commit prepare-commit-msg commit-msg post-commit Commit hooks

  235. pre-rebase post-merge pre-push Merge & rebase hooks

  236. applypatch-msg pre-applypatch post-applypatch Patch hooks

  237. pre-receive update post-receive Server-side hooks

  238. post-checkout post-rewrite pre-auto-gc Other hooks

  239. Exercise time! ©  Freepik  h"p:/ /www.flaBcon.com,  CC  BY  3.0

  240. Part XII: Rewriting History In which the past turns out

    to be more malleable than expected
  241. None
  242. History-changing commands

  243. git reset --hard History-changing commands

  244. git reset --hard git commit --amend History-changing commands

  245. git reset --hard git commit --amend git rebase History-changing commands

  246. git reset --hard git commit --amend git rebase git rebase

    -i History-changing commands
  247. Interactive rebase

  248. pick 9e2546a Insert some magic into the text pick cfb3546

    Add introductory line pick 2985b57 Add some hipster ipsum # Rebase 80ab5d4..2985b57 onto 80ab5d4 ( 3 TODO item(s)) # # 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 # # These lines can be re-ordered; they are executed from top to bottom. # # If you remove a line here THAT COMMIT WILL BE LOST. # # However, if you remove everything, the rebase will be aborted. # # Note that empty commits are commented out Interactive rebase $ git rebase -i 80ab5d4
  249. Pushing rewritten history

  250. To /Users/kerry/masterclass ! [rejected] master -> master (non-fast-forward) error: failed

    to push some refs to '/Users/kerry/masterclass' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. Pushing rewritten history $ git push
  251. Pushing rewritten history

  252. Counting objects: 3, done. Delta compression using up to 4

    threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 458 bytes | 0 bytes/s, done. Total 3 (delta 1), reused 0 (delta 0) To /Users/kerry/masterclass + 2985b57...055e9f6 master -> master (forced update) Pushing rewritten history $ git push -f
  253. Exercise time! ©  Freepik  h"p:/ /www.flaBcon.com,  CC  BY  3.0

  254. Part XIII: Working with svn In which we use git

    locally with legacy projects, to avoid having to touch subversion with our bare hands
  255. Cloning an svn repo

  256. Initialized empty Git repository in /Users/kerry/foo/.git/ Using higher level of

    URL: file:///Users/kerry/svn/foo => file:///Users/kerry/ svn r1 = 845504bcb16ce2004479227776b937dcab69bf23 (refs/remotes/origin/trunk) A foo.txt r2 = 16c802a2578ea71c3d96eb70cc6c5ed247883f50 (refs/remotes/origin/trunk) M foo.txt r3 = 6b3d13ce78571566341a3f1d797062afcca47adf (refs/remotes/origin/trunk) Checked out HEAD: file:///Users/kerry/svn/foo/trunk r3 Cloning an svn repo $ git svn clone -s file:///Users/kerry/svn/foo
  257. Cloning an svn repo

  258. commit 6b3d13ce78571566341a3f1d797062afcca47adf Author: kerry <kerry@e0cd7379-fbe6-420c-9387-2eba09531e83> Date: 4 minutes ago Insert

    some magic into the text git-svn-id: file:///Users/kerry/svn/foo/trunk@3 e0cd7379-fbe6-420c-9387-2eba09531e83 commit 16c802a2578ea71c3d96eb70cc6c5ed247883f50 Author: kerry <kerry@e0cd7379-fbe6-420c-9387-2eba09531e83> Date: 5 minutes ago Add a file with some placeholder text git-svn-id: file:///Users/kerry/svn/foo/trunk@2 e0cd7379-fbe6-420c-9387-2eba09531e83 Cloning an svn repo $ git log
  259. Pulling remote changes

  260. M foo.txt r4 = 6f2ed53c4d52fdbc0b1bc29b5b377518fd2db797 (refs/remotes/origin/trunk) First, rewinding head to

    replay your work on top of it... Applying: Add some hipster ipsum Using index info to reconstruct a base tree... M foo.txt Falling back to patching base and 3-way merge... Auto-merging foo.txt Pulling remote changes $ git svn rebase
  261. Committing changes

  262. Committing to file:///Users/kerry/svn/foo/trunk ... M foo.txt Committed r5 M foo.txt

    r5 = af3a4e909657b619b1665bc38a224ded7ff82e07 (refs/remotes/origin/trunk) No changes between 000f0660457584cccbcac635f876c7ee56ba3846 and refs/remotes/ origin/trunk Resetting to the latest refs/remotes/origin/trunk Committing changes $ git svn dcommit
  263. Part XIV: Fixing Mistakes In which we discover that although

    git allows you to shoot yourself in the foot, it also provides bullet-proof socks
  264. hPp:/ /jus5nhileman.info/git-­‐prePy/

  265. None
  266. Fixing mistakes

  267. Fixing mistakes Reset to last commit

  268. Fixing mistakes Reset to last commit git reset --hard

  269. Fixing mistakes Reset to last commit git reset --hard Forgot

    to commit something
  270. Fixing mistakes Reset to last commit git reset --hard Forgot

    to commit something git commit --amend
  271. Fixing mistakes Reset to last commit git reset --hard Forgot

    to commit something git commit --amend Redo last commit
  272. Fixing mistakes Reset to last commit git reset --hard Forgot

    to commit something git commit --amend Redo last commit git reset HEAD~
  273. Fixing mistakes

  274. Fixing mistakes Put changes aside temporarily

  275. Fixing mistakes Put changes aside temporarily git stash

  276. Fixing mistakes Put changes aside temporarily git stash Reapply stashed

    changes
  277. Fixing mistakes Put changes aside temporarily git stash Reapply stashed

    changes git stash pop
  278. Fixing mistakes Put changes aside temporarily git stash Reapply stashed

    changes git stash pop Find out when something broke
  279. Fixing mistakes Put changes aside temporarily git stash Reapply stashed

    changes git stash pop Find out when something broke git bisect
  280. Fixing mistakes

  281. Fixing mistakes Rearrange committed changes

  282. Fixing mistakes Rearrange committed changes git rebase -i

  283. Fixing mistakes Rearrange committed changes git rebase -i Undo a

    pushed commit
  284. Fixing mistakes Rearrange committed changes git rebase -i Undo a

    pushed commit git revert
  285. Fixing mistakes Rearrange committed changes git rebase -i Undo a

    pushed commit git revert Lost history
  286. Fixing mistakes Rearrange committed changes git rebase -i Undo a

    pushed commit git revert Lost history git reflog
  287. Exercise time! h"p:/ /www.rhoenradturnen.org/

  288. The end. Any questions?