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

Mastering Git and GitHub (ConFoo 2014)

Ben Straub
February 28, 2014

Mastering Git and GitHub (ConFoo 2014)

Git and GitHub are great tools for making software. Are you making the best use of them? Are you still doing work that robots can do for you?

Are you scared of rebase and filter-branch? Do Emoji and mentions vex you? Are you looking to move your team to the next level?

This talk is for you. Learn how to let Git and GitHub help you make better software.

Ben Straub

February 28, 2014
Tweet

More Decks by Ben Straub

Other Decks in Programming

Transcript

  1. $ git cat-file -t d7abd6 blob $ git cat-file -p

    d7abd6 <!DOCTYPE html> <!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]--> <!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]--> <!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html lang="en"><!--<![endif]--> <head> <meta charset="utf-8"> <title>{% if page.title %}{{ page.title }} - {% endif %}{{ si Blob
  2. $ git cat-file -t d7abd6 blob $ git cat-file -p

    d7abd6 <!DOCTYPE html> <!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]--> <!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]--> <!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html lang="en"><!--<![endif]--> <head> <meta charset="utf-8"> <title>{% if page.title %}{{ page.title }} - {% endif %}{{ si Blob
  3. $ git cat-file -t d7abd6 blob $ git cat-file -p

    d7abd6 <!DOCTYPE html> <!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]--> <!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]--> <!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html lang="en"><!--<![endif]--> <head> <meta charset="utf-8"> <title>{% if page.title %}{{ page.title }} - {% endif %}{{ si Blob
  4. $ git cat-file -t d7abd6 blob $ git cat-file -p

    d7abd6 <!DOCTYPE html> <!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]--> <!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]--> <!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html lang="en"><!--<![endif]--> <head> <meta charset="utf-8"> <title>{% if page.title %}{{ page.title }} - {% endif %}{{ si Blob
  5. $ git cat-file -t 8f5b65 tree $ git cat-file -p

    8f5b65 100644 blob 08b8e3400a81a79aeb42878171449b773ab493c0 after_foot 100644 blob 11517b315de6d7bc7550cc74ae413f1e6dafce19 archive_po 100644 blob 8ad5afd4581caa7458658325aeec9f8de875b988 article.ht 040000 tree 5c2166adaa57c909182a45b995dfb750c22c8810 asides 040000 tree 52deb7c58d46aa09208c0b863fbecee81a2e3dad custom 100644 blob eb308779fa09eadd8575b1acea2801f16ef1d839 disqus.htm 100644 blob 74f91307278c092bca1e862337cb8d2b1ac14d94 facebook_l 100644 blob 3a8c7687474e513b196b50f5634c6decd14ed484 footer.htm Tree
  6. Commit $ git cat-file -t e365b187 commit $ git cat-file

    -p e365b187 tree 58c796e7717809c2ca2217fc5424fdebdbc121b1 parent d4291dfddfae86cfacec789133861098cebc67d4 author Ben Straub <[email protected]> 1380719530 -0700 committer Ben Straub <[email protected]> 1380719530 -0700 ! Fix typo, remove false statement
  7. Tag Annotation $ git cat-file -t 849a5e34a tag $ git

    cat-file -p 849a5e34a object a65fedf39aefe402d3bb6e24df4d4f5fe4547750 type commit tag hard_tag tagger Ben Straub <[email protected]> Fri May 11 11:47:58 2012 ! Tag on tag
  8. * * | * | | * | | *

    | | * | | |\ | |/ / |/| | | | | * | | | * | | | * | | |/ | |/| | * | | |\ \ | |/ / |/| / | |/ * | | * | * |/ * * Refs are Easy
  9. * * | * | | * | | *

    | | * | | |\ | |/ / |/| | | | | * | | | * | | | * | | |/ | |/| | * | | |\ \ | |/ / |/| / | |/ * | | * | * |/ * * Refs are Easy
  10. Symbolic Refs • branch -> commit • HEAD -> branch

    -> commit • tag -> commit • tag -> annotation -> commit • tag -> blob • HEAD -> branch -> tag -> annotation1 -> annotation2 -> blob • WAT
  11. Moving Things Around • Sandbox -> Index: git add •

    Index -> History: git commit • History -> Index/Sandbox: git checkout
  12. Reset 1. Move HEAD
 (Stop here if --soft) 2. Make

    the index look like HEAD
 (Stop here if --mixed, which is the default) 3.Make the sandbox look like the index
 (Stop here if --hard)
  13. $ ./new_test.sh BAD THINGS $ git lga * 394fe77 (HEAD,

    master) MOAR DOTS * 155cfdc Great justice! * 2e36522 Some innocent change * bf4a9fd Fixed configuration * 713d64c Fixed bug #718 * f4fb4ef Work on feature #72 * 2b241ed Initial commit $ git bisect start $ git bisect good 2b241 $ git bisect bad Bisecting: 2 revisions left to test after this (roughly 2 step
  14. $ ./new_test.sh BAD THINGS $ git lga * 394fe77 (HEAD,

    master) MOAR DOTS * 155cfdc Great justice! * 2e36522 Some innocent change * bf4a9fd Fixed configuration * 713d64c Fixed bug #718 * f4fb4ef Work on feature #72 * 2b241ed Initial commit $ git bisect start $ git bisect good 2b241 $ git bisect bad Bisecting: 2 revisions left to test after this (roughly 2 step
  15. $ ./new_test.sh BAD THINGS $ git lga * 394fe77 (HEAD,

    master) MOAR DOTS * 155cfdc Great justice! * 2e36522 Some innocent change * bf4a9fd Fixed configuration * 713d64c Fixed bug #718 * f4fb4ef Work on feature #72 * 2b241ed Initial commit $ git bisect start $ git bisect good 2b241 $ git bisect bad Bisecting: 2 revisions left to test after this (roughly 2 step
  16. $ git lga * 394fe77 (HEAD, master) MOAR DOTS *

    155cfdc Great justice! * 2e36522 Some innocent change * bf4a9fd Fixed configuration * 713d64c Fixed bug #718 * f4fb4ef Work on feature #72 * 2b241ed Initial commit $ git bisect start $ git bisect good 2b241 $ git bisect bad Bisecting: 2 revisions left to test after this (roughly 2 step [bf4a9fdc7ca066fd132f79e8607d7fda81bc9ac7] Fixed configuration $ git lga * 394fe77 (master, refs/bisect/bad) MOAR DOTS * 155cfdc Great justice! * 2e36522 Some innocent change
  17. $ git bisect start $ git bisect good 2b241 $

    git bisect bad Bisecting: 2 revisions left to test after this (roughly 2 step [bf4a9fdc7ca066fd132f79e8607d7fda81bc9ac7] Fixed configuration $ git lga * 394fe77 (master, refs/bisect/bad) MOAR DOTS * 155cfdc Great justice! * 2e36522 Some innocent change * bf4a9fd (HEAD) Fixed configuration * 713d64c Fixed bug #718 * f4fb4ef Work on feature #72 * 2b241ed (refs/bisect/good-2b241ed06235b4ccbdf7dabae47b5c9f58 $ ./new_test.sh ALL CLEAR $ git bisect good Bisecting: 0 revisions left to test after this (roughly 1 step
  18. $ git bisect bad Bisecting: 2 revisions left to test

    after this (roughly 2 step [bf4a9fdc7ca066fd132f79e8607d7fda81bc9ac7] Fixed configuration $ git lga * 394fe77 (master, refs/bisect/bad) MOAR DOTS * 155cfdc Great justice! * 2e36522 Some innocent change * bf4a9fd (HEAD) Fixed configuration * 713d64c Fixed bug #718 * f4fb4ef Work on feature #72 * 2b241ed (refs/bisect/good-2b241ed06235b4ccbdf7dabae47b5c9f58 $ ./new_test.sh ALL CLEAR $ git bisect good Bisecting: 0 revisions left to test after this (roughly 1 step [155cfdc11389c013609c75f5d3dd4e834f0c7f39] Great justice! $ git lga
  19. $ git lga * 394fe77 (master, refs/bisect/bad) MOAR DOTS *

    155cfdc Great justice! * 2e36522 Some innocent change * bf4a9fd (HEAD) Fixed configuration * 713d64c Fixed bug #718 * f4fb4ef Work on feature #72 * 2b241ed (refs/bisect/good-2b241ed06235b4ccbdf7dabae47b5c9f58 $ ./new_test.sh ALL CLEAR $ git bisect good Bisecting: 0 revisions left to test after this (roughly 1 step [155cfdc11389c013609c75f5d3dd4e834f0c7f39] Great justice! $ git lga * 394fe77 (master, refs/bisect/bad) MOAR DOTS * 155cfdc (HEAD) Great justice! * 2e36522 Some innocent change
  20. $ ./new_test.sh ALL CLEAR $ git bisect good Bisecting: 0

    revisions left to test after this (roughly 1 step [155cfdc11389c013609c75f5d3dd4e834f0c7f39] Great justice! $ git lga * 394fe77 (master, refs/bisect/bad) MOAR DOTS * 155cfdc (HEAD) Great justice! * 2e36522 Some innocent change * bf4a9fd (refs/bisect/good-bf4a9fdc7ca066fd132f79e8607d7fda81 * 713d64c Fixed bug #718 * f4fb4ef Work on feature #72 * 2b241ed (refs/bisect/good-2b241ed06235b4ccbdf7dabae47b5c9f58 $ ./new_test.sh BAD THINGS $ git bisect bad Bisecting: 0 revisions left to test after this (roughly 0 step
  21. $ git lga * 394fe77 (master, refs/bisect/bad) MOAR DOTS *

    155cfdc (HEAD) Great justice! * 2e36522 Some innocent change * bf4a9fd (refs/bisect/good-bf4a9fdc7ca066fd132f79e8607d7fda81 * 713d64c Fixed bug #718 * f4fb4ef Work on feature #72 * 2b241ed (refs/bisect/good-2b241ed06235b4ccbdf7dabae47b5c9f58 $ ./new_test.sh BAD THINGS $ git bisect bad Bisecting: 0 revisions left to test after this (roughly 0 step [2e3652251ca60b394dd6dd58b35aad2c68341b81] Some innocent chang $ ./new_test.sh BAD THINGS $ git bisect bad 2e3652251ca60b394dd6dd58b35aad2c68341b81 is the first bad comm
  22. Bisecting: 0 revisions left to test after this (roughly 0

    step [2e3652251ca60b394dd6dd58b35aad2c68341b81] Some innocent chang $ ./new_test.sh BAD THINGS $ git bisect bad 2e3652251ca60b394dd6dd58b35aad2c68341b81 is the first bad comm commit 2e3652251ca60b394dd6dd58b35aad2c68341b81 Author: Me <[email protected]> Date: Sat Sep 8 21:07:23 2012 -0700 ! Some innocent change ! :100644 100644 cffc75085d348cd4f418fc4d4257df03eb8c3c15 4d95ce $ git show commit 2e3652251ca60b394dd6dd58b35aad2c68341b81 Author: Me <[email protected]> Date: Sat Sep 8 21:07:23 2012 -0700
  23. Some innocent change ! diff --git a/critical.txt b/critical.txt index cffc750..4d95ced

    100644 --- a/critical.txt +++ b/critical.txt @@ -2,5 +2,6 @@ GOOD GOOD GOOD GOOD +EVIL MUAHAHAHAHA GOOD GOOD $ git lga * 394fe77 (master) MOAR DOTS * 155cfdc Great justice! * 2e36522 (HEAD, refs/bisect/bad) Some innocent change
  24. GOOD GOOD +EVIL MUAHAHAHAHA GOOD GOOD $ git lga *

    394fe77 (master) MOAR DOTS * 155cfdc Great justice! * 2e36522 (HEAD, refs/bisect/bad) Some innocent change * bf4a9fd (refs/bisect/good-bf4a9fdc7ca066fd132f79e8607d7fda81 * 713d64c Fixed bug #718 * f4fb4ef Work on feature #72 * 2b241ed (refs/bisect/good-2b241ed06235b4ccbdf7dabae47b5c9f58 $ git bisect reset Previous HEAD position was 2e36522... Some innocent change Switched to branch 'master' $ git lga
  25. GOOD GOOD $ git lga * 394fe77 (master) MOAR DOTS

    * 155cfdc Great justice! * 2e36522 (HEAD, refs/bisect/bad) Some innocent change * bf4a9fd (refs/bisect/good-bf4a9fdc7ca066fd132f79e8607d7fda81 * 713d64c Fixed bug #718 * f4fb4ef Work on feature #72 * 2b241ed (refs/bisect/good-2b241ed06235b4ccbdf7dabae47b5c9f58 $ git bisect reset Previous HEAD position was 2e36522... Some innocent change Switched to branch 'master' $ git lga * 394fe77 (HEAD, master) MOAR DOTS * 155cfdc Great justice! * 2e36522 Some innocent change
  26. * f4fb4ef Work on feature #72 * 2b241ed (refs/bisect/good-2b241ed06235b4ccbdf7dabae47b5c9f58 $

    git bisect reset Previous HEAD position was 2e36522... Some innocent change Switched to branch 'master' $ git lga * 394fe77 (HEAD, master) MOAR DOTS * 155cfdc Great justice! * 2e36522 Some innocent change * bf4a9fd Fixed configuration * 713d64c Fixed bug #718 * f4fb4ef Work on feature #72 * 2b241ed Initial commit
  27. $ ./new_test.sh BAD THINGS $ git bisect start $ git

    bisect good 2b241 $ git bisect bad Bisecting: 2 revisions left to test after this (roughly 2 step [bf4a9fdc7ca066fd132f79e8607d7fda81bc9ac7] Fixed configuration $ git bisect run ./new_test.sh running ./new_test.sh ALL CLEAR Bisecting: 0 revisions left to test after this (roughly 1 step [155cfdc11389c013609c75f5d3dd4e834f0c7f39] Great justice! running ./new_test.sh BAD THINGS
  28. $ ./new_test.sh BAD THINGS $ git bisect start $ git

    bisect good 2b241 $ git bisect bad Bisecting: 2 revisions left to test after this (roughly 2 step [bf4a9fdc7ca066fd132f79e8607d7fda81bc9ac7] Fixed configuration $ git bisect run ./new_test.sh running ./new_test.sh ALL CLEAR Bisecting: 0 revisions left to test after this (roughly 1 step [155cfdc11389c013609c75f5d3dd4e834f0c7f39] Great justice! running ./new_test.sh BAD THINGS
  29. $ ./new_test.sh BAD THINGS $ git bisect start $ git

    bisect good 2b241 $ git bisect bad Bisecting: 2 revisions left to test after this (roughly 2 step [bf4a9fdc7ca066fd132f79e8607d7fda81bc9ac7] Fixed configuration $ git bisect run ./new_test.sh running ./new_test.sh ALL CLEAR Bisecting: 0 revisions left to test after this (roughly 1 step [155cfdc11389c013609c75f5d3dd4e834f0c7f39] Great justice! running ./new_test.sh BAD THINGS
  30. running ./new_test.sh BAD THINGS Bisecting: 0 revisions left to test

    after this (roughly 0 step [2e3652251ca60b394dd6dd58b35aad2c68341b81] Some innocent chang running ./new_test.sh BAD THINGS 2e3652251ca60b394dd6dd58b35aad2c68341b81 is the first bad comm commit 2e3652251ca60b394dd6dd58b35aad2c68341b81 Author: Me <[email protected]> Date: Sat Sep 8 21:07:23 2012 -0700 ! Some innocent change ! :100644 100644 cffc75085d348cd4f418fc4d4257df03eb8c3c15 4d95ce bisect run success $ !
  31. var rewriteHistoryOptions = new RewriteHistoryOptions { CommitTreeRewriter = c =>

    TreeDefinition.From(c).Remove("README"), CommitHeaderRewriter = c => CommitRewriteInfo.From(c, message: "HEYOOOO"), }; repo.Refs.RewriteHistory(rewriteHistoryOptions, repo.Head.Commits); Parlez-vous C#?
  32. !

  33. !

  34. !

  35. !

  36. !

  37. !

  38. $