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

Introduction to Git + Using Git with WordPress

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.

Ryan McCue

November 13, 2012
Tweet

More Decks by Ryan McCue

Other Decks in Programming

Transcript

  1. +
    = awesome
    Ryan McCue
    @rmccue

    View full-size slide

  2. three sections

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  5. command line?

    View full-size slide

  6. I am going to
    lie to you
    Warning:

    View full-size slide

  7. this might hurt
    your head
    Warning:

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  10. what is git?

    View full-size slide

  11. git manages history

    View full-size slide

  12. git manages history
    your files

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  15. 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

    View full-size slide

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

    View full-size slide

  17. “working directory”

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  20. $ git commit -a

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  24. $ git checkout

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  27. “staging area”

    View full-size slide

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

    View full-size slide

  29. $ git checkout

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  32. $ git commit

    View full-size slide

  33. 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

    View full-size slide

  34. 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

    View full-size slide

  35. $ git commit -a

    View full-size slide

  36. $ 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

    View full-size slide

  37. $ 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(-)

    View full-size slide

  38. sharing is caring

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  41. $ git push -u origin master

    View full-size slide

  42. $ git push -u origin master

    View full-size slide

  43. $ git push -u origin master

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  49. $ git add -p

    View full-size slide

  50. $ git add -p
    = awesome

    View full-size slide

  51. $ git checkout -p
    add
    reset

    View full-size slide

  52. $ vim style.css
    $ git add style.css
    $ git add -p

    View full-size slide

  53. $ 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,?]?

    View full-size slide

  54. 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

    View full-size slide

  55. groups of changes

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  58. $ git branch
    $ git checkout

    View full-size slide

  59. $ git checkout –b

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  62. master new-stuff

    View full-size slide

  63. master new-stuff
    git merge master

    View full-size slide

  64. master new-stuff

    View full-size slide

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

    View full-size slide

  66. master new-stuff

    View full-size slide

  67. master new-stuff
    GitHub you

    View full-size slide

  68. $ git clone [email protected]:example/example.git

    View full-size slide

  69. GitHub
    you me

    View full-size slide

  70. GitHub
    you me

    View full-size slide

  71. GitHub
    you me

    View full-size slide

  72. $ git push
    To [email protected]:example/example.git
    ! [rejected] master -> master (non-fast-forward)
    error: failed to push some refs to '[email protected]: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.

    View full-size slide

  73. GitHub
    you me

    View full-size slide

  74. $ git push -u origin master

    View full-size slide

  75. $ git remote add origin [email protected]:example/example.git

    View full-size slide

  76. pull requests

    View full-size slide

  77. pull requests
    = awesome

    View full-size slide

  78. internal use too!

    View full-size slide

  79. tips & tricks

    View full-size slide

  80. $ git log
    commit eee30254c2ba314ad7fe3bc493095af421118c27
    Author: Ryan McCue
    Date: Fri Oct 26 00:01:26 2012 +1000
    Check unknown status codes too
    commit 7ce9e116792697955ba32be9e18d67d37513f80b
    Author: Ryan McCue
    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
    Date: Thu Oct 25 06:39:30 2012 -0700
    Merge pull request #23 from rmccue/multiple
    Add ability to send multiple requests at once

    View full-size slide

  81. $ git log --stat
    commit eee30254c2ba314ad7fe3bc493095af421118c27
    Author: Ryan McCue
    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
    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(-)

    View full-size slide

  82. $ 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 +-

    View full-size slide

  83. $ 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 +-

    View full-size slide

  84. $ git log c67a081..78f0c0a
    commit 78f0c0a9dffb01c8d369f860f189beb9210de6b9
    Author: Andrew Nacin
    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
    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
    Date: Mon Nov 12 05:57:12 2012 +0000

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  87. submodules
    (like svn externals)

    View full-size slide

  88. submodules
    ≠ awesome

    View full-size slide

  89. submodules
    ≠ awesome
    try Tower?

    View full-size slide

  90. keep it simple

    View full-size slide

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

    View full-size slide

  92. $ 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

    View full-size slide

  93. site/wp-content/plugins/bbpress/

    View full-size slide

  94. $ 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

    View full-size slide

  95. $ git remote add origin [email protected]: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 [email protected]:rmccue/test-site.git
    * [new branch] master -> master
    Branch master set up to track remote branch master from origin.

    View full-size slide

  96. WP Australia
    github.com/BronsonQuick/wpaustralia

    View full-size slide

  97. Wrong (sorry Bronson)

    View full-size slide

  98. try it anyway!

    View full-size slide

  99. I am going to
    lie to you
    Warning:

    View full-size slide

  100. one last thing

    View full-size slide

  101. 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

    View full-size slide