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

F59d2f1ed66b8d9c6ceebea5a748494b?s=128

William Durand

November 26, 2015
Tweet

Transcript

  1. 1

  2. 2 . 1

  3. 2 . 2

  4. 2 . 3

  5. 3

  6. 4 . 1

  7. 4 . 2

  8. 4 . 3

  9. git checkout <other-branch> -- /path/to/file 4 . 4

  10. 4 . 5

  11. 4 . 6

  12. PULL FETCH MERGE git pull --rebase <remote> <branch> 4 .

    7
  13. 4 . 8

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

  15. 4 . 10

  16. 5 . 1

  17. 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 <will+git@drnd.me> Date: Mon Nov 16 14:54:53 2015 +0100 add badges ... 5 . 2
  18. git co<tab><tab> commit config 5 . 3

  19. GIT ARCHIVE git archive --format zip -o snapshot.zip HEAD git

    archive --format tar --prefix myapp/ <commit> | (cd /tmp && tar xf -) 5 . 4
  20. 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
  21. 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
  22. 6 . 1

  23. git stash pop git stash -u 'current state' git stash

    apply 6 . 2
  24. git rebase -i HEAD~<number of commits> 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
  25. git pull --rebase origin master 6 . 4

  26. 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
  27. git commit --amend git commit --amend -m 'Fix undefined variable

    j Fix #123' 6 . 6
  28. merge cherry-pick rebase git checkout - Switched to branch 'master'

    git checkout - Switched to branch 'feat-undefined-variable' 6 . 7
  29. git branch --no-merged develop feat-another-feature feat-my-feature fix-undefined-variable git branch --merged

    * master 6 . 8
  30. 7 . 1

  31. git format-patch master --stdout > fix-undefined-variable.patch From: William Durand <will+git@drnd.me>

    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
  32. git apply --stat fix-undefined-variable.patch test.js | 2 +- 1 file

    changed, 1 insertion(+), 1 deletion(-) 7 . 3
  33. git apply --check fix-undefined-variable.patch 7 . 4

  34. patch -p1 git am --signoff < fix-undefined-variable.patch Applying: Fix undefined

    variable commit 4c20f8d517b99638f5379f3f0894ad076d2b6a5b Author: William Durand <will+git@drnd.me> Date: Thu Nov 13 10:22:17 2015 +0100 Fix undefined variable Signed-off-by: William Durand <will+git@drnd.me> 7 . 5
  35. 8 . 1

  36. 8 . 2

  37. 8 . 3

  38. 8 . 4

  39. 8 . 5

  40. 8 . 6

  41. 8 . 7

  42. 8 . 8

  43. 8 . 9

  44. 8 . 10

  45. 8 . 11

  46. 8 . 12

  47. 8 . 13

  48. 8 . 14

  49. T 8 . 15

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

  51. curl https://github.com/your/repo/commit/<SHA>.patch |git am Applying: Fix undefined variable 8 .

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

  53. HUB alias git=hub 9 . 1

  54. 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
  55. git browse # open https://github.com/random/repo git browse -- issues #

    open https://github.com/random/repo/issues 9 . 3
  56. git fetch ubermuda # git remote add ubermuda git://github.com/ubermuda/repo.git #

    git fetch ubermuda 9 . 4
  57. 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
  58. git am -3 https://github.com/your/repo/pull/123 9 . 6

  59. 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
  60. git fork, git pull-request, merge, ci-status, etc. 9 . 8

  61. 10 . 1

  62. 10 . 2

  63. 10 . 3

  64. 10 . 4

  65. ≈ 10 . 5

  66. 11 . 1

  67. 11 . 2

  68. 11 . 3

  69. 11 . 3

  70. 11 . 4

  71. 11 . 5

  72. 11 . 6

  73. 12 . 1

  74. 12 . 2

  75. 12 . 3

  76. 13 . 1

  77. 13 . 2

  78. 13 . 3

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

  80. 13 . 5

  81. 13 . 6

  82. 13 . 6

  83. CONTRIBUTING 13 . 7

  84. 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
  85. ≤ 13 . 9

  86. ≤ Fix #123 13 . 10

  87. 13 . 11

  88. 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
  89. 13 . 13

  90. 13 . 14

  91. 14 . 1

  92. 14 . 2

  93. 14 . 3

  94. 14 . 4

  95. 14 . 5

  96. 15 . 1

  97. 15 . 2

  98. 15 . 3

  99. 15 . 4

  100. 15 . 5

  101. README 15 . 6

  102. 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
  103. ## 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
  104. CONTRIBUTING 15 . 9

  105. 15 . 10

  106. CODE_OF_CONDUCT 15 . 11

  107. 15 . 12

  108. 15 . 13

  109. 15 . 14

  110. 15 . 15

  111. 15 . 16

  112. 15 . 17

  113. 15 . 18

  114. 15 . 19

  115. 15 . 20

  116. 15 . 21

  117. 16 . 1

  118. MAJOR.MINOR.PATCH 16 . 2

  119. 16 . 3

  120. 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
  121. 17 . 1

  122. 17 . 2

  123. 17 . 3

  124. 17 . 4

  125. 17 . 5

  126. 17 . 6

  127. 17 . 7

  128. 17 . 8

  129. 17 . 9

  130. 17 . 10

  131. 17 . 11

  132. 17 . 12

  133. 17 . 13

  134. 17 . 14

  135. 17 . 15

  136. 17 . 16

  137. 18 . 1

  138. 18 . 2

  139. 18 . 3

  140. 18 . 4

  141. 18 . 5

  142. 18 . 6

  143. 18 . 7

  144. 18 . 8

  145. 18 . 9

  146. 18 . 10

  147. 19

  148. 20