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

Git & GitHub & Open Source (Clermont'ech Workshop Git)

Git & GitHub & Open Source (Clermont'ech Workshop Git)

In this talk, you will learn how to use Git and GitHub in an efficient manner, but also how to manage Open Source projects, and what it actually means.

Online slides: http://slides.williamdurand.fr/git-and-github-and-open-source/
Sources: https://github.com/willdurand-slides/git-and-github-and-open-source

William Durand

November 15, 2014
Tweet

More Decks by William Durand

Other Decks in Technology

Transcript

  1. Git & GitHub & Open Source
    William Durand ‑ November 15th, 2014

    View Slide

  2. Open Source

    View Slide

  3. In production and development, Open Source as a
    development model promotes a universal access via a
    free license to a product's design or blueprint [...].
    http://en.wikipedia.org/wiki/Open_source

    View Slide

  4. Open‑source software is very often developed
    in a public, collaborative manner.

    View Slide

  5. ® GitHub

    View Slide

  6. View Slide

  7. GitHub is the largest code host on the planet
    with over 17.1 million repositories.

    View Slide

  8. Integrated Issue Tracking

    View Slide

  9. Integrated Issue Tracking

    View Slide

  10. Syntax Highlighting

    View Slide

  11. Collaborative Code Review

    View Slide

  12. Collaborative Code Review

    View Slide

  13. Pull Request = Code + Issue + Code Comments

    View Slide

  14. GitHub Pages

    View Slide

  15. Release Management

    View Slide

  16. Compare View

    View Slide

  17. GitHub Tip #1

    View Slide

  18. t File Finder

    View Slide

  19. How To Contribute?

    View Slide

  20. Everyone can contribute.

    View Slide

  21. Fork The Repository

    View Slide

  22. Create A Branch
    git checkout -b feature-branch

    View Slide

  23. Eat, Sleep, Code, Repeat.

    View Slide

  24. Submit A Pull Request
    But, how?

    View Slide

  25. Look At The
    CONTRIBUTING
    File
    (If it does not exist, contribute by adding it!)

    View Slide

  26. Write Good Commit Messages
    Capitalized, short (50 chars or less) summary
    More detailed explanatory text, if necessary. Wrap it to about 72
    characters or so. In some contexts, the first line is treated as the
    subject of an email and the rest of the text as the body. The blank
    line separating the summary from the body is critical (unless you omit
    the body entirely); tools like rebase can get confused if you run the
    two together.
    Write your commit message in the imperative: "Fix bug" and not "Fixed bug"
    or "Fixes bug." This convention matches up with commit messages generated
    by commands like git merge and git revert.
    Further paragraphs come after blank lines.
    Å A Note About Git Commit Messages

    View Slide

  27. Rebase Your Branch

    View Slide

  28. Squash Your Commits
    git rebase -i HEAD~2
    pick 5335450 add test
    pick 4c20f8d Fix undefined variable
    # Rebase 35124cb..4c20f8d onto 35124cb
    #
    # 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
    Å Squashing commits with rebase

    View Slide

  29. Push & Create

    View Slide

  30. Profit!

    View Slide

  31. What Happens Then?

    View Slide

  32. An Open Source maintainer will look at your work.

    View Slide

  33. Pull Request Review
    Understand the goal of the PR
    Try to reproduce the issue
    Try the fix
    Test the new feature
    Think about edge cases
    Write documentation if not provided

    View Slide

  34. Dealing With Releases

    View Slide

  35. Semantic Versioning
    MAJOR.MINOR.PATCH
    Å semver.org

    View Slide

  36. Changelog
    A change log is a file which contains a curated, ordered
    list of notable changes for each version of a project.
    Å keepachangelog.com

    View Slide

  37. Release Process
    1. Run test suite(s)
    2. Update documentation, changelog, version
    3. git commit -m "Prepare X.Y.Z release"
    4. git tag vX.Y.Z
    5. Build artifact (gem build, etc.)
    6. Update version number (Z++)
    7. git commit -m "Bump version to X.Y.Z+1-dev"
    8. git push origin master --tags
    9. Publish artifact (gem push, etc.)
    10. Publish a GitHub release

    View Slide

  38. hub
    git + hub = github
    alias git=hub

    View Slide

  39. Clone
    git clone random/repo
    # git clone git://github.com/random/repo.git
    git clone repo
    # git clone git://github.com/YOUR/repo.git

    View Slide

  40. Browse
    git browse
    # open https://github.com/random/repo
    git browse -- issues
    # open https://github.com/random/repo/issues

    View Slide

  41. Easy Fetch
    git fetch ubermuda
    # git remote add ubermuda git://github.com/ubermuda/repo.git
    # git fetch ubermuda

    View Slide

  42. Checkout
    git checkout https://github.com/your/repo/pull/123
    # git remote add contributor git://github.com/contributor/repo.git
    # git fetch contributor
    # git checkout -b contributor-branch contributor/branch
    Best way to [work on|review|test] a Pull Request so far!

    View Slide

  43. Apply Commits
    git am -3 https://github.com/your/repo/pull/123

    View Slide

  44. Cherry‑Pick
    git cherry-pick https://github.com/random/repo/commit/SHA
    # git remote random git://github.com/random/repo.git
    # git fetch random
    # git cherry-pick SHA

    View Slide

  45. More!
    git fork, git pull-request, merge, ci-status, etc.
    Å hub.github.com

    View Slide

  46. Dealing With
    PATCH & DIFF

    View Slide

  47. Creating A Patch
    git format-patch master --stdout > fix-undefined-variable.patch
    From: William Durand
    Date: Thu, 13 Nov 2014 10:22:17 +0100
    Subject: [PATCH] Fix undefined variable
    ---
    test.js | 2 +-
    1 file changed, 1 insertion(+), 1 deletion(-)
    diff --git a/test.js b/test.js
    index 760e4eb..60ac996 100644
    --- a/test.js
    +++ b/test.js
    @@ -1,5 +1,5 @@
    (function () {
    - var i;
    + var i, j;
    i = 0;
    j = i;
    --
    2.1.2

    View Slide

  48. Changes Overview
    git apply --stat fix-undefined-variable.patch
    test.js | 2 +-
    1 file changed, 1 insertion(+), 1 deletion(-)

    View Slide

  49. Test The Patch
    git apply --check fix-undefined-variable.patch
    No output == ›

    View Slide

  50. Then, Apply
    git am --signoff < fix-undefined-variable.patch
    Applying: Fix undefined variable
    commit 4c20f8d517b99638f5379f3f0894ad076d2b6a5b
    Author: William Durand
    Date: Thu Nov 13 10:22:17 2014 +0100
    Fix undefined variable
    Signed-off-by: William Durand
    BTW, patch -p1 works too!

    View Slide

  51. GitHub Tip #2

    View Slide

  52. .patch
    https://github.com/your/repo/commit/e0af340837978f80d8cd144a4475.patch

    View Slide

  53. Applying A Commit As A Patch
    curl https://github.com/your/repo/commit/.patch |git am
    Applying: Fix undefined variable

    View Slide

  54. .diff
    https://github.com/your/repo/commit/e0af340837978f80d8cd144a4475.diff

    View Slide

  55. Dealing With
    Everything Else

    View Slide

  56. Fixing The Code Is Not Enough

    View Slide

  57. Full‑Time Hobby

    View Slide

  58. Just do it.

    View Slide

  59. Provide Support

    View Slide

  60. ... Everywhere

    View Slide

  61. Create Things That People
    Actually Use (& Like)

    View Slide

  62. Inspire Others

    View Slide

  63. Makes People Feel Good

    View Slide

  64. Receive Overwhelming Feedback

    View Slide

  65. ... & Gifts

    View Slide

  66. Thank You.
    Questions?
    ¾
    ®
    ¬
    williamdurand.fr
    github.com/willdurand
    twitter.com/couac

    View Slide

  67. Bonus: (My) Useful
    Git Commands

    View Slide

  68. Atomic Commits
    git add -p
    diff --git a/test.js b/test.js
    index 60ac996..2a57310 100644
    --- a/test.js
    +++ b/test.js
    @@ -1,6 +1,5 @@
    (function () {
    - var i, j;
    + var i = 0, j;
    - i = 0;
    - j = i;
    + j = 1;
    })();
    Stage this hunk [y,n,q,a,d,/,s,e,?]? s
    Split into 2 hunks.
    @@ -1,3 +1,3 @@
    (function () {
    - var i, j;
    + var i = 0, j;
    Stage this hunk [y,n,q,a,d,/,j,J,g,e,?]?

    View Slide

  69. Amending A Commit
    git commit --amend -m 'Fix undefined variable j
    Fix #123'

    View Slide

  70. Fast Pull & Rebase
    git pull --rebase origin master

    View Slide

  71. Go Back
    git checkout -
    Switched to branch 'master'
    git checkout -
    Switched to branch 'feat-undefined-variable'

    View Slide

  72. (Un)Merged Branch
    git branch --no-merged
    develop
    feat-another-feature
    feat-my-feature
    fix-undefined-variable
    git branch --merged
    * master

    View Slide

  73. Links
    http://williamdurand.fr/2013/11/20/on‑creating‑pull‑requests/
    http://gitready.com/advanced/2009/02/10/squashing‑commits‑with‑rebase.html
    http://git‑scm.com/book/en/v2/Git‑Branching‑Rebasing
    http://tbaggery.com/2008/04/19/a‑note‑about‑git‑commit‑messages.html

    View Slide