More Git and GitHub Secrets

More Git and GitHub Secrets

This talk covers both Git and GitHub: different tricks I've picked up after three years at GitHub, helpful advice on common gripes I've seen in support tickets and tweets, and just general nifty things that make you a faster, more capable technologist.

78b475797a14c84799063c7cd073962f?s=128

Zach Holman

July 24, 2013
Tweet

Transcript

  1. secrets Git GitHub &

  2. None
  3. git branch -D local-branch git push origin :local-branch

  4. Much like James Cameron’s Avatar™, Git doesn’t make any goddamn

    sense
  5. This talk throws a ton of stuff at you

  6. This talk throws a ton of stuff at you (Not

    unlike James Cameron’s Avatar™, btw)
  7. Learn the bits that make you more productive

  8. None
  9. secrets Git GitHub &

  10. merge strategies

  11. strategy defaults: one head: recursive multiple heads: octopus merge strategies

  12. merge strategies git merge master -s strategy

  13. git merge master -s ours merge strategies

  14. git merge master -s ours “Give me master, but my

    final state should match my current branch” merge strategies
  15. git merge master -s ours Great for when your long-running

    branch will supersede master merge strategies
  16. git merge master \ -s recursive merge strategies

  17. git merge master \ -s recursive -X patience merge strategies

    Be er line matching for logical groups
  18. merge strategies — patience { :a => :b }

  19. { :a => :b } { :c => :d }

    merge strategies — patience
  20. { :a => :b +} + +{ + :c =>

    :d } merge strategies — patience
  21. { :a => :b } +{ + :c => :d

    +} merge strategies — patience
  22. git merge master \ -s recursive -X patience merge strategies

    Can also set as a global option
  23. merge strategies › man git-merge # look at “Merge Strategies”

  24. The second-order-diff trick

  25. the second-order-diff trick Tom Moertel ( cl.ly/QNaG )

  26. the second-order-diff trick Goal: transform strings with a regex in

    project
  27. the second-order-diff trick Approach: re-run git diff and git reset

    until the regex is correct
  28. the second-order-diff trick Problem: it sucks to review the diff

    each time
  29. the second-order-diff trick Solution: stash, then diff against stash{0}

  30. the second-order-diff trick › git status # clean

  31. the second-order-diff trick › ./run-regex-script

  32. the second-order-diff trick › git diff # review and check

    output
  33. the second-order-diff trick › git stash # stash your reviewed

    diff
  34. the second-order-diff trick › ./run-regex-script

  35. the second-order-diff trick › git diff stash{0} # only incremental

    changes
  36. the second-order-diff trick Find and replace in projects without worrying

  37. emoji diffs

  38. emoji diffs Yeah this is important

  39. emoji diffs Git diffs unicode poorly:

  40. emoji diffs

  41. emoji diffs Git uses less as its pager

  42. emoji diffs git --no-pager diff

  43. emoji diffs

  44. emoji diffs

  45. emoji diffs

  46. emoji diffs

  47. git stripspace

  48. git stripspace Fixes horrible coworkers and contributors

  49. git stripspace Strips trailing whitespace, collapses newlines, adds a final

    newline
  50. git stripspace git stripspace < file

  51. git stripspace echo “hi \n” | git stripspace

  52. git stripspace Run this in your editor a er file

    saves
  53. git diff --check

  54. git diff --check Fixes horrible you.

  55. run.sh:1: trailing whitespace. +echo “hi” . git diff --check

  56. run.sh:1: space before tab in indent. + ls -la git

    diff --check
  57. git diff --cached

  58. git diff --cached git diff only diffs unstaged changes

  59. git diff --cached Shows staged (but uncommi ed) changes

  60. HOT, HOT, TRIVIA BREAK

  61. Which of these commit messages actually happened on GitHub?

  62. 1. A reasoned argument, citing sources 2. A 500MB db

    dump
  63. 1. A reasoned argument, citing sources 2. A 500MB db

    dump
  64. “Why is my repository slow?”

  65. git merge --abort

  66. git merge --abort Aborts a conflicted merge

  67. git merge --abort Resets your tree

  68. git merge -m “message”

  69. git merge -m Like commit -m but populates the merge

    commit
  70. git merge --no-commit

  71. git merge --no-commit Merges without a commit message

  72. git status --ignored

  73. git status --ignored Shows the status of everything you’re ignoring

  74. --assume-unchanged

  75. --assume-unchanged Temporarily ignore a file

  76. --assume-unchanged git update-index \ --assume-unchanged \ path_to_file

  77. --assume-unchanged git update-index \ --no-assume-unchanged \ path_to_file

  78. proper messages

  79. proper messages Linus has thoughts on your commit messages

  80. proper messages git commit -m “fixes shit”

  81. proper messages git commit -m “fixes shit” is not what

    he had in mind
  82. proper messages A good commit has:

  83. proper messages Short summary (title) A longer description of the

    change follows.
  84. proper messages Short summary (title) < 50c

  85. proper messages Short summary (title) A longer description of the

    change follows. < 50c
  86. proper messages Short summary (title) A longer description of the

    change follows. < 50c wrap at 72c
  87. proper messages

  88. proper messages git-commit helps you write perfect messages

  89. proper messages

  90. proper messages 50c

  91. proper messages

  92. proper messages wraps at 72c

  93. proper messages Assumes your $EDITOR is vim

  94. proper messages export EDITOR=vim

  95. proper messages Assumes you have syntax highlighting on

  96. proper messages syntax on ~/.vimrc

  97. proper messages Assumes you have plugin indenting on

  98. proper messages filetype indent plugin on ~/.vimrc

  99. secrets Git GitHub &

  100. canonical URLs

  101. None
  102. None
  103. y press

  104. press y

  105. y This page won’t change, even if the branch does

  106. curlable public keys

  107. h ps:/ / /holman.keys

  108. Plaintext, non-authed access to public keys /user.keys

  109. Programmatically add SSH keys /user.keys

  110. fetching pulls

  111. fetching pulls Accepting a Pull Request: Add a remote, fetch

    branch, merge
  112. fetching pulls Lots of boring commands

  113. fetching pulls GitHub stores all Pull Requests in your repository

  114. fetching pulls This means we can track code even if

    the fork is deleted
  115. fetching pulls You can abuse this, too!

  116. fetching pulls git fetch origin pull/id/head:name

  117. fetching pulls git fetch origin pull/12/head:pr

  118. fetching pulls git fetch origin pull/12/head:pr fetches Pull Request #12

    into a branch named “pr”
  119. fetching pulls Automate this within helper scripts or an alias

  120. live updates

  121. None
  122. None
  123. None
  124. None
  125. HOT, HOT, TRIVIA BREAK

  126. Most frequent Emoji used on GitHub:

  127. #5 :clap:

  128. #4 :+1:

  129. #3 :-1:

  130. #2 :sparkles:

  131. #1 :shipit:

  132. quick quotes

  133. quick quotes Markdown uses . for blockquotes >

  134. quick quotes

  135. quick quotes r Highlight and press .

  136. quick quotes

  137. quick quotes

  138. browse stars

  139. h p:/ / /stars / brianmario

  140. None
  141. web flow

  142. web flow You can do a lot without leaving the

    browser
  143. web flow Documentation, prose, quick fixes, switching away from nosql

  144. web flow

  145. web flow

  146. web flow

  147. web flow

  148. web flow

  149. web flow

  150. web flow Frees you from git clone

  151. issue autocomplete

  152. issue autocomplete Type , get a search #

  153. None
  154. None
  155. None
  156. None
  157. repo redirects

  158. repo redirects Rename your repository and GitHub will redirect old

    URLs
  159. in-repo licensing

  160. None
  161. in-repo licensing You can add licenses to existing repos, too

  162. in-repo licensing

  163. in-repo licensing

  164. in-repo licensing (also works for .gitignore)

  165. file finder

  166. file finder Type , find in project t

  167. file finder

  168. task lists

  169. task lists Use issues and pulls as todo lists

  170. task lists - [ ] Use NoSQL - [ ]

    Use today's trendiest language - [ ] Do what our VC tells us - [ ] Comment on Hacker News - [ ] Profit
  171. task lists

  172. task lists

  173. task lists - [x] Use NoSQL - [x] Use today's

    trendiest language - [x] Do what our VC tells us - [x] Comment on Hacker News - [ ] Profit
  174. task lists

  175. fork URLs

  176. fork URLs

  177. None
  178. fork URLs h ps:/ / /user / repo / fork

  179. None
  180. fork URLs README links

  181. fork URLs

  182. Remember:

  183. Git is probably terrible

  184. But it’s also neato

  185. Thanks!