Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

Open Source

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

® GitHub

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

Integrated Issue Tracking

Slide 9

Slide 9 text

Integrated Issue Tracking

Slide 10

Slide 10 text

Syntax Highlighting

Slide 11

Slide 11 text

Collaborative Code Review

Slide 12

Slide 12 text

Collaborative Code Review

Slide 13

Slide 13 text

Pull Request = Code + Issue + Code Comments

Slide 14

Slide 14 text

GitHub Pages

Slide 15

Slide 15 text

Release Management

Slide 16

Slide 16 text

Compare View

Slide 17

Slide 17 text

GitHub Tip #1

Slide 18

Slide 18 text

t File Finder

Slide 19

Slide 19 text

How To Contribute?

Slide 20

Slide 20 text

Everyone can contribute.

Slide 21

Slide 21 text

Fork The Repository

Slide 22

Slide 22 text

Create A Branch git checkout -b feature-branch

Slide 23

Slide 23 text

Eat, Sleep, Code, Repeat.

Slide 24

Slide 24 text

Submit A Pull Request But, how?

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

Rebase Your Branch

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

Push & Create

Slide 30

Slide 30 text

Profit!

Slide 31

Slide 31 text

What Happens Then?

Slide 32

Slide 32 text

An Open Source maintainer will look at your work.

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

Dealing With Releases

Slide 35

Slide 35 text

Semantic Versioning MAJOR.MINOR.PATCH Å semver.org

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

hub git + hub = github alias git=hub

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

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!

Slide 43

Slide 43 text

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

Slide 44

Slide 44 text

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

Slide 45

Slide 45 text

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

Slide 46

Slide 46 text

Dealing With PATCH & DIFF

Slide 47

Slide 47 text

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

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

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

Slide 50

Slide 50 text

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!

Slide 51

Slide 51 text

GitHub Tip #2

Slide 52

Slide 52 text

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

Slide 53

Slide 53 text

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

Slide 54

Slide 54 text

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

Slide 55

Slide 55 text

Dealing With Everything Else

Slide 56

Slide 56 text

Fixing The Code Is Not Enough

Slide 57

Slide 57 text

Full‑Time Hobby

Slide 58

Slide 58 text

Just do it.

Slide 59

Slide 59 text

Provide Support

Slide 60

Slide 60 text

... Everywhere

Slide 61

Slide 61 text

Create Things That People Actually Use (& Like)

Slide 62

Slide 62 text

Inspire Others

Slide 63

Slide 63 text

Makes People Feel Good

Slide 64

Slide 64 text

Receive Overwhelming Feedback

Slide 65

Slide 65 text

... & Gifts

Slide 66

Slide 66 text

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

Slide 67

Slide 67 text

Bonus: (My) Useful Git Commands

Slide 68

Slide 68 text

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,?]?

Slide 69

Slide 69 text

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

Slide 70

Slide 70 text

Fast Pull & Rebase git pull --rebase origin master

Slide 71

Slide 71 text

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

Slide 72

Slide 72 text

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

Slide 73

Slide 73 text

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