Save 37% off PRO during our Black Friday Sale! »

Introduction to Git + Using Git with WordPress

6ea15b18e25b00e1af953e489439d540?s=47 Ryan McCue
November 13, 2012

Introduction to Git + Using Git with WordPress

An introduction to Git basics, building up to more advanced topics. Also includes information on using Git to develop WordPress slides.

6ea15b18e25b00e1af953e489439d540?s=128

Ryan McCue

November 13, 2012
Tweet

Transcript

  1. + = awesome Ryan McCue @rmccue

  2. three sections

  3. 1) git basics 2) efficient git 3) git + WordPress

  4. 1) git basics 2) efficient git 3) git + WordPress

    + WordPress community summit
  5. command line?

  6. None
  7. None
  8. I am going to lie to you Warning:

  9. this might hurt your head Warning:

  10. this might hurt your head Warning: let me know!

  11. 1) git basics 2) efficient git 3) git + WordPress

  12. what is git?

  13. git manages history

  14. git manages history your files

  15. your files my-theme/ index.php style.css

  16. your files my-theme/ index.php style.css style.css.old

  17. your files my-theme/ index.php style.css style.css.old style.css.bak style.css.bak.bak style.css.whatdidido style.css.help

    style.css.helphelp.help style.css.nooooo
  18. git!

  19. your files my-theme/ index.php style.css

  20. “working directory”

  21. $ git init

  22. working my-theme/ index.php style.css committed my-theme/

  23. working my-theme/ index.php style.css committed my-theme/ ?

  24. $ git commit -a

  25. $ git commit -a I’ll come back to this

  26. working my-theme/ index.php style.css committed my-theme/ index.php style.css commit -a

  27. working my-theme/ index.php style.css committed my-theme/ index.php style.css commit -a

    ?
  28. $ git checkout <file>

  29. working my-theme/ index.php style.css committed my-theme/ index.php style.css commit -a

    checkout
  30. edit part of the theme? what if I only

  31. “staging area”

  32. working committed staging my-theme/ my-theme/ my-theme/ index.php style.css ? ?

  33. $ git add <file>

  34. $ git checkout <file>

  35. working committed staging my-theme/ index.php style.css my-theme/ my-theme/ index.php style.css

    add checkout
  36. working committed staging my-theme/ index.php style.css my-theme/ my-theme/ index.php style.css

    add checkout ? ?
  37. $ git commit

  38. $ git reset

  39. working committed staging my-theme/ index.php style.css my-theme/ index.php style.css my-theme/

    index.php style.css add checkout commit reset
  40. working committed staging my-theme/ index.php style.css my-theme/ index.php style.css my-theme/

    index.php style.css add checkout commit reset commit -a reset --hard
  41. $ git commit -a

  42. $ cd mytheme/ $ git init Initialized empty Git repository

    in …/mytheme/.git/ $ vim index.php $ vim style.css $ git add index.php $ git add style.css $ git commit –m ‘Initial commit’ [master (root-commit) e6d6f02] Initial commit 0 files changed, 200 insertions(+), 0 deletions(-) create mode 100644 index.php create mode 100644 style.css
  43. $ vim style.css $ git add style.css $ git commit

    –m ‘Improve styling for links’ [master dda31a3] Improve styling for links 1 files changed, 20 insertions(+), 2 deletions(-)
  44. sharing is caring

  45. None
  46. your commits my-theme/ index.php style.css GitHub my-theme/ index.php style.css

  47. your commits my-theme/ index.php style.css GitHub my-theme/ index.php style.css ?

    ?
  48. $ git push -u origin master

  49. $ git push -u origin master

  50. $ git push -u origin master

  51. $ git push

  52. your commits my-theme/ index.php style.css GitHub my-theme/ index.php style.css push

    ?
  53. $ git pull

  54. your commits my-theme/ index.php style.css GitHub my-theme/ index.php style.css push

    pull
  55. questions?

  56. 1) git basics 2) efficient git 3) git + WordPress

  57. edit part of the theme? what if I only

  58. edit part of the file? what if I only

  59. $ git add -p

  60. $ git add -p = awesome

  61. $ git checkout -p add reset

  62. $ vim style.css $ git add style.css $ git add

    -p
  63. $ git add -p diff --git a/wp-admin/includes/class-wp-upgrader.php b/wp-admin/includes/class-wp-upgrader.php index ef8fb5f..f77c645

    100644 --- a/wp-admin/includes/class-wp-upgrader.php +++ b/wp-admin/includes/class-wp-upgrader.php @@ -107,6 +107,10 @@ class WP_Upgrader { function download_package($package) { + $reply = apply_filters('upgrader_pre_download', false, $package, $this); + if ( false !== $reply ) + return $reply; + if ( ! preg_match('!^(http|https|ftp)://!i', $package) && file_exists($package) ) //Local file or remote? return $package; //must be a local file.. Stage this hunk [y,n,q,a,d,/,e,?]?
  64. Stage this hunk [y,n,q,a,d,/,e,?]? ? y - stage this hunk

    n - do not stage this hunk q - quit; do not stage this hunk nor any of the remaining ones a - stage this hunk and all later hunks in the file d - do not stage this hunk nor any of the later hunks in the file g - select a hunk to go to / - search for a hunk matching the given regex j - leave this hunk undecided, see next undecided hunk J - leave this hunk undecided, see next hunk k - leave this hunk undecided, see previous undecided hunk K - leave this hunk undecided, see previous hunk s - split the current hunk into smaller hunks e - manually edit the current hunk ? - print help
  65. branches

  66. groups of changes

  67. master

  68. master my-theme/ index.php style.css new-stuff my-theme/ index.php style.css

  69. master my-theme/ index.php style.css new-stuff my-theme/ index.php style.css ? ?

  70. $ git branch <name> $ git checkout <name>

  71. $ git checkout –b <name>

  72. $ git merge <name>

  73. master my-theme/ index.php style.css new-stuff my-theme/ index.php style.css branch merge

  74. master new-stuff git checkout -b new-stuff

  75. master new-stuff

  76. master new-stuff git merge master

  77. master new-stuff

  78. master new-stuff git checkout master git merge new-stuff

  79. push/pull

  80. master new-stuff

  81. master new-stuff GitHub you

  82. $ git clone <remote>

  83. $ git clone git@github.com:example/example.git

  84. GitHub you me

  85. GitHub you me

  86. GitHub you me

  87. $ git push To git@github.com:example/example.git ! [rejected] master -> master

    (non-fast-forward) error: failed to push some refs to 'git@github.com:example/example.git' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (e.g. 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details.
  88. GitHub you me

  89. $ git push -u origin master

  90. $ git remote add origin git@github.com:example/example.git

  91. pull requests

  92. pull requests = awesome

  93. None
  94. None
  95. None
  96. None
  97. internal use too!

  98. tips & tricks

  99. $ git log commit eee30254c2ba314ad7fe3bc493095af421118c27 Author: Ryan McCue <me@ryanmccue.info> Date:

    Fri Oct 26 00:01:26 2012 +1000 Check unknown status codes too commit 7ce9e116792697955ba32be9e18d67d37513f80b Author: Ryan McCue <me@ryanmccue.info> Date: Thu Oct 25 23:52:19 2012 +1000 Test new status headers These were previously added while in draft status, but not tested. This adds testing for those, in addition to updating the link to the new related RFC. commit 083843d9dbd4eeb0fc24fe35479d472f6bea4ff9 Merge: 3f508b0 23c2087 Author: Ryan McCue <me+github@ryanmccue.info> Date: Thu Oct 25 06:39:30 2012 -0700 Merge pull request #23 from rmccue/multiple Add ability to send multiple requests at once
  100. $ git log --stat commit eee30254c2ba314ad7fe3bc493095af421118c27 Author: Ryan McCue <me@ryanmccue.info>

    Date: Fri Oct 26 00:01:26 2012 +1000 Check unknown status codes too tests/Transport/Base.php | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-) commit 7ce9e116792697955ba32be9e18d67d37513f80b Author: Ryan McCue <me@ryanmccue.info> Date: Thu Oct 25 23:52:19 2012 +1000 Test new status headers These were previously added while in draft status, but not tested. This adds testing for those, in addition to updating the link to the new related RFC. library/Requests/Exception/HTTP/428.php | 4 ++-- library/Requests/Exception/HTTP/431.php | 4 ++-- library/Requests/Exception/HTTP/511.php | 4 ++-- tests/Transport/Base.php | 4 ++++ 4 files changed, 10 insertions(+), 6 deletions(-)
  101. $ git pull remote: Counting objects: 677, done. remote: Compressing

    objects: 100% (168/168), done. Receiving objects: remote: Total 583 (delta 489), reused 505 (delta 412) Receiving objects: 100% (583/583), 125.00 KiB | 107 KiB/s, done. Resolving deltas: 100% (489/489), completed with 85 local objects. From https://github.com/WordPress/WordPress c67a081..78f0c0a master -> origin/master Updating c67a081..78f0c0a Fast-forward wp-admin/admin-ajax.php | 2 +- wp-admin/css/colors-classic.min.css | 2 +- wp-admin/css/colors-fresh.min.css | 2 +- wp-admin/css/wp-admin-rtl.css | 18 +- wp-admin/css/wp-admin-rtl.min.css | 2 +- wp-admin/css/wp-admin.css | 35 +- wp-admin/css/wp-admin.min.css | 2 +- wp-admin/custom-background.php | 21 +- wp-admin/custom-header.php | 36 +-
  102. $ git pull remote: Counting objects: 677, done. remote: Compressing

    objects: 100% (168/168), done. Receiving objects: remote: Total 583 (delta 489), reused 505 (delta 412) Receiving objects: 100% (583/583), 125.00 KiB | 107 KiB/s, done. Resolving deltas: 100% (489/489), completed with 85 local objects. From https://github.com/WordPress/WordPress c67a081..78f0c0a master -> origin/master Updating c67a081..78f0c0a Fast-forward wp-admin/admin-ajax.php | 2 +- wp-admin/css/colors-classic.min.css | 2 +- wp-admin/css/colors-fresh.min.css | 2 +- wp-admin/css/wp-admin-rtl.css | 18 +- wp-admin/css/wp-admin-rtl.min.css | 2 +- wp-admin/css/wp-admin.css | 35 +- wp-admin/css/wp-admin.min.css | 2 +- wp-admin/custom-background.php | 21 +- wp-admin/custom-header.php | 36 +-
  103. $ git log c67a081..78f0c0a commit 78f0c0a9dffb01c8d369f860f189beb9210de6b9 Author: Andrew Nacin <wp@andrewnacin.com>

    Date: Mon Nov 12 07:47:41 2012 +0000 Revert [22421]. see #6821. see #22308. see #22419. git-svn-id: http://core.svn.wordpress.org/trunk@22549 1a063a9b-81f0-0310-95a commit 1ec12cccb9d12fdbde7c6592266fb875555c39f3 Author: Daryl Koopersmith <dkoopersmith@gmail.com> Date: Mon Nov 12 06:02:03 2012 +0000 Media: Allow successive embed URLs. see [22547], #21390. git-svn-id: http://core.svn.wordpress.org/trunk@22548 1a063a9b-81f0-0310-95a commit 2d87f983adfc75587f544ab742619b380d9a8cdb Author: Daryl Koopersmith <dkoopersmith@gmail.com> Date: Mon Nov 12 05:57:12 2012 +0000
  104. questions?

  105. 1) git basics 2) efficient git 3) git + WordPress

  106. Skeleton github.com/markjaquith/WordPress-Skeleton

  107. None
  108. submodules (like svn externals)

  109. submodules ≠ awesome

  110. submodules ≠ awesome try Tower?

  111. keep it simple

  112. site/ wp-admin/ wp-content/ wp-includes/ ...

  113. $ git init Initialized empty Git repository in …/site/.git/ $

    git add * $ git commit -m ‘Initial commit’ [master (root-commit) eadd213] Initial commit 2 files changed, 35 insertions(+), 0 deletions(-) create mode 100644 .gitignore create mode 100644 .gitmodules
  114. site/wp-content/plugins/bbpress/

  115. $ git add wp-content/plugins/bbpress/* $ git commit -m ‘Add bbPress’

    [master 26b47c0] Add bbPress 200 files changed, 62840 insertions(+), 0 deletions(-) create mode 100644 wp-content/plugins/bbpress/bbp-admin/bbp-actions.php create mode 100644 wp-content/plugins/bbpress/bbp-admin/bbp-admin.php create mode 100644 wp-content/plugins/bbpress/bbp-admin/bbp-converter.php create mode 100644 wp-content/plugins/bbpress/bbp-admin/bbp-forums.php create mode 100644 wp-content/plugins/bbpress/bbp-admin/bbp-functions.php create mode 100644 wp-content/plugins/bbpress/bbp-admin/bbp-metaboxes.php create mode 100644 wp-content/plugins/bbpress/bbp-admin/bbp-parser.php create mode 100644 wp-content/plugins/bbpress/bbp-admin/bbp-replies.php create mode 100644 wp-content/plugins/bbpress/bbp-admin/bbp-settings.php create mode 100644 wp-content/plugins/bbpress/bbp-admin/bbp-tools.php create mode 100644 wp-content/plugins/bbpress/bbp-admin/bbp-topics.php create mode 100644 wp-content/plugins/bbpress/bbp-admin/bbp-users.php create mode 100644 wp-content/plugins/bbpress/bbp-admin/converters/Example.php create mode 100644 wp-content/plugins/bbpress/bbp-admin/converters/Invision.php create mode 100644 wp-content/plugins/bbpress/bbp-admin/converters/bbPress1.php create mode 100644 wp-content/plugins/bbpress/bbp-admin/converters/index.php create mode 100644 wp-content/plugins/bbpress/bbp-admin/converters/phpBB.php
  116. $ git remote add origin git@github.com:rmccue/test-site.git $ git push -u

    origin master Counting objects: 1268, done. Writing objects: 91% (1154/1268), 4.16 MiB | 13 KiB/s Compressing objects: 100% (1248/1248), done. Writing objects: 100% (1268/1268), 4.90 MiB | 15 KiB/s, done. Total 1268 (delta 128), reused 0 (delta 0) To git@github.com:rmccue/test-site.git * [new branch] master -> master Branch master set up to track remote branch master from origin.
  117. WP Australia github.com/BronsonQuick/wpaustralia

  118. None
  119. Wrong

  120. Wrong (sorry Bronson)

  121. try it anyway!

  122. I am going to lie to you Warning:

  123. one last thing

  124. None
  125. that’s it

  126. questions? http://journal.ryanmccue.info/185 http://windows.github.com/ http://mac.github.com/ http://www.git-tower.com/ http://try.github.com/ http://github.com/markjaquith/WordPress-Skeleton http://github.com/BronsonQuick/wpaustralia Ryan McCue

    http://ryanmccue.info/ @rmccue