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

Git & GitHub & OpenSource (LavaJUG)

Git & GitHub & OpenSource (LavaJUG)

Vous n'en avez peut-être pas conscience mais beaucoup de technologies sont Open Source, c'est-à-dire que des gens (et des entreprises) prennent du temps pour collaborer ensemble sur des projets ouverts.

Grâce à Git (un outil de gestion de versions) et surtout à GitHub (une plateforme collaborative faisant la promotion de l'Open Source et s'appuyant sur Git), l'Open Source s'est démocratisé et tout le monde peut contribuer à un monde meilleur.

Dans cette présentation, vous entendrez parler de Git avec des astuces pour travailler efficacement. Je vous parlerai de GitHub (et GitLab) pour collaborer sur des projets existants et/ou nouveaux, que vous soyez une grande société, une startup ou simplement une personne voulant apporter sa pierre à l'édifice. Je vous donnerai des clés pour mettre le pied à l'étrier et vous faire comprendre que, vraiment, tout le monde peut contribuer et que c'est une bonne chose.

Nous discuterons de l'Open Source en entreprise et comment reverser des contributions à la communauté : apprendre à donner plutôt que seulement prendre.

Pour terminer, j'évoquerai mes 4 dernières années en tant que "mainteneur" de projets Open Source, avec ce qu'il faut faire et ne pas faire, ainsi que différents exemples.

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 26, 2015
Tweet

More Decks by William Durand

Other Decks in Programming

Transcript

  1. git checkout -- /path/to/file
    4 . 4

    View full-size slide

  2. PULL FETCH MERGE
    git pull --rebase
    4 . 7

    View full-size slide

  3. git pull --rebase=preserve
    pull.rebase=preserve
    4 . 9

    View full-size slide

  4. git config --global help.autocorrect 1
    git lol
    WARNING: You called a Git command named 'lol', which does not exist.
    Continuing under the assumption that you meant 'log'
    in 0.1 seconds automatically...
    commit 2feb149c8e76d12848f7535a8eb4d51b1c225776
    Author: William Durand
    Date: Mon Nov 16 14:54:53 2015 +0100
    add badges
    ...
    5 . 2

    View full-size slide

  5. git co
    commit config
    5 . 3

    View full-size slide

  6. GIT ARCHIVE
    git archive --format zip -o snapshot.zip HEAD
    git archive --format tar --prefix myapp/ | (cd /tmp && tar xf -)
    5 . 4

    View full-size slide

  7. git config --global rerere.enabled true
    git merge master
    Auto-merging index.html
    CONFLICT (content): Merge conflict in index.html
    Recorded preimage for 'index.html'
    Automatic merge failed; fix conflicts and then commit the result.
    git commit --no-edit
    Recorded resolution for 'index.html'
    [old-branch abcd123] Merge branch 'master' into old-branch
    git merge master
    Auto-merging index.html
    CONFLICT (content): Merge conflict in index.html
    Resolved 'index.html' using previous resolution.
    5 . 5

    View full-size slide

  8. GIT BISECT
    git bisect start
    git bisect good abcd123
    git bisect bad [badd123]
    # The script should end with a non-zero return status when it fails
    git bisect run mvn clean test
    5 . 6

    View full-size slide

  9. git stash pop
    git stash -u 'current state'
    git stash apply
    6 . 2

    View full-size slide

  10. git rebase -i HEAD~
    pick d1ed4e4 Fix typo
    pick b49cb42 Update for lavajug
    pick e35510f Add new images
    # Rebase 5f167bb..e35510f onto 5f167bb (3 command(s))
    #
    # 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
    6 . 3

    View full-size slide

  11. git pull --rebase origin master
    6 . 4

    View full-size slide

  12. 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,?]?
    6 . 5

    View full-size slide

  13. git commit --amend
    git commit --amend -m 'Fix undefined variable j
    Fix #123'
    6 . 6

    View full-size slide

  14. merge cherry-pick rebase
    git checkout -
    Switched to branch 'master'
    git checkout -
    Switched to branch 'feat-undefined-variable'
    6 . 7

    View full-size slide

  15. git branch --no-merged
    develop
    feat-another-feature
    feat-my-feature
    fix-undefined-variable
    git branch --merged
    * master
    6 . 8

    View full-size slide

  16. git format-patch master --stdout > fix-undefined-variable.patch
    From: William Durand
    Date: Thu, 13 Nov 2015 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
    7 . 2

    View full-size slide

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

    View full-size slide

  18. git apply --check fix-undefined-variable.patch
    7 . 4

    View full-size slide

  19. patch -p1
    git am --signoff < fix-undefined-variable.patch
    Applying: Fix undefined variable
    commit 4c20f8d517b99638f5379f3f0894ad076d2b6a5b
    Author: William Durand
    Date: Thu Nov 13 10:22:17 2015 +0100
    Fix undefined variable
    Signed-off-by: William Durand
    7 . 5

    View full-size slide

  20. .PATCH
    https://github.com/your/repo/commit/e0af340837978f80d8cd144a4475.patch
    8 . 16

    View full-size slide

  21. curl https://github.com/your/repo/commit/.patch |git am
    Applying: Fix undefined variable
    8 . 17

    View full-size slide

  22. .DIFF
    https://github.com/your/repo/commit/e0af340837978f80d8cd144a4475.diff
    8 . 18

    View full-size slide

  23. HUB
    alias git=hub
    9 . 1

    View full-size slide

  24. git clone random/repo
    # git clone git://github.com/random/repo.git
    git clone repo
    # git clone git://github.com/YOUR/repo.git
    9 . 2

    View full-size slide

  25. git browse
    # open https://github.com/random/repo
    git browse -- issues
    # open https://github.com/random/repo/issues
    9 . 3

    View full-size slide

  26. git fetch ubermuda
    # git remote add ubermuda git://github.com/ubermuda/repo.git
    # git fetch ubermuda
    9 . 4

    View full-size slide

  27. 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
    9 . 5

    View full-size slide

  28. git am -3 https://github.com/your/repo/pull/123
    9 . 6

    View full-size slide

  29. 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
    9 . 7

    View full-size slide

  30. git fork, git pull-request, merge, ci-status, etc.
    9 . 8

    View full-size slide

  31. git checkout -b feature-branch
    13 . 4

    View full-size slide

  32. CONTRIBUTING
    13 . 7

    View full-size slide

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

    View full-size slide


  34. Fix #123
    13 . 10

    View full-size slide

  35. 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
    13 . 12

    View full-size slide

  36. README
    15 . 6

    View full-size slide

  37. project-x
    =========
    project-x is a better way to achieve this and that, by leveraging the new
    API, bla bla bla.
    ## Usage
    ...
    ## Installation
    ...
    ## Requirements
    ...
    ## Contributing
    See CONTRIBUTING file.
    15 . 7

    View full-size slide

  38. ## Running the Tests
    ...
    ## Credits
    ...
    ## Contributor Code of Conduct
    Please note that this project is released with a [Contributor Code of
    Conduct](http://contributor-covenant.org/). By participating in this project
    you agree to abide by its terms. See CODE_OF_CONDUCT file.
    ## License
    project-x is released under the MIT License. See the bundled LICENSE file for
    details.
    15 . 8

    View full-size slide

  39. CONTRIBUTING
    15 . 9

    View full-size slide

  40. CODE_OF_CONDUCT
    15 . 11

    View full-size slide

  41. MAJOR.MINOR.PATCH
    16 . 2

    View full-size slide

  42. git commit -m "Prepare X.Y.Z release"
    git tag vX.Y.Z
    gem build
    Z++
    git commit -m "Bump version to X.Y.Z+1-dev"
    git push origin master --tags
    gem push
    16 . 4

    View full-size slide