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

Git and Github: Tips and tricks

0826c9e6449c9a08230ac6d40a3cde4d?s=47 Wendy Liu
November 26, 2013

Git and Github: Tips and tricks

Presentation for HackMcGill. Intro to Git/Github plus various tips and tricks, all in one.

0826c9e6449c9a08230ac6d40a3cde4d?s=128

Wendy Liu

November 26, 2013
Tweet

Transcript

  1. HackMcGill :: January 29, 2014 tips & tricks and :

  2. about me - Wendy Liu - 4th year Math &

    CS - 3 years experience with Git - 137-day Github commit streak - dellsystem on Twitter, Github, IRC
  3. what is git?

  4. what is git? version control system!

  5. svn/perforce: local vs. remote comparison to other systems

  6. svn/perforce: local vs. remote hg/bzr: faster, more control comparison to

    other systems
  7. svn/perforce: local vs. remote hg/bzr: faster, more control cvs/rcs: no

    comparison comparison to other systems
  8. backup_dec_1_2012.zip backup_dec_8_2012.zip backup_dec_15_2012.zip backup_dec_22_2012.zip backup_dec_29_2012.zip backup_jan_5_2012.zip backup_jan_12_2012.zip backup_jan_19_2012.zip backup_jan_26_2012.zip

  9. report_v1.doc report_v2.doc report_v3.doc report_v4.doc

  10. keeps track of changes enter git.

  11. keeps track of changes extremely flexible enter git.

  12. keeps track of changes extremely flexible developed by linus torvalds

    enter git.
  13. keeps track of changes extremely flexible developed by linus torvalds

    completely free to use (and open source!) enter git.
  14. keeps track of changes extremely flexible developed by linus torvalds

    completely free to use (and open source!) primarily command-line enter git.
  15. website what is github?

  16. website collaborative coding, via git what is github?

  17. website collaborative coding, via git (mostly) free to use what

    is github?
  18. website collaborative coding, via git (mostly) free to use major

    part of developer ecosystem (esp. OSS) what is github?
  19. why git?

  20. why git? diffs

  21. why git? diffs backups

  22. why git? diffs backups collaboration

  23. what git can do for you versioning easy collaboration blame

    tracking down bugs safe experimentation statistics
  24. what github can do for you issue-tracking even easier collaboration

    remote backups access your files from anywhere graphical, easy-to-use UI
  25. now: how git works

  26. repository directory on filesystem just metadata (changes) manual grouping of

    changes
  27. commit group of logically-related changes 1 or more files (add/delete/modify)

  28. staging index CHANGES I WANT IN MY NEXT COMMIT ALL

    THE OTHER CHANGES
  29. git commit -m 'test' CHANGES I WANT IN MY NEXT

    COMMIT ALL THE OTHER CHANGES a new commit, with message 'test'
  30. CHANGES I WANT IN MY NEXT COMMIT ALL THE OTHER

    CHANGES the commit with message 'test' (nothing here yet)
  31. your computer REMOTE REPOSITORIES LOCAL REPOSITORY some server another server

    github
  32. now: git tips

  33. rebasing git rebase -i [start commit] reorder, reword, edit, squash

    commits
  34. amending git commit --amend staged changes become part of previous

    commit
  35. force pushing git push origin master -f useful after amending/rebasing

  36. multiple remotes git remote add origin [url] git remote add

    upstream [different URL] useful when pulling from other developers
  37. patch git add --patch stage one chunk at a time

  38. diffing git diff (unstaged) git diff --cached (staged) git diff

    --check (whitespace errors)
  39. colours git config --global color.ui auto

  40. fix your whitespace git stripspace git apply --whitespace=fix

  41. good commit messages Fix bug (50 chars max, capitalised, imperative)

    Longer description explaining what the commit does. Wrap at 72 characters. Don't forget the blank line. bit.ly/gitcommit
  42. bisect git bisect (or, "when did this bug first appear?")

  43. ignoring .gitignore (untracked files) git update-index --assume-unchanged (tracked files) git

    status --ignored
  44. better pulls git pull vs git fetch & git merge

  45. aliases git s = git status git add = git

    add --patch git ds = git diff --staged git amend = git commit --amend git say = git commit -m git un = reset --soft HEAD^1
  46. fixing merge conflicts 1. Don't panic 2. git status 3.

    Look for the <<< 4. Stage & commit
  47. moving files git mv [source] [destination] instead of: mv [source]

    [destination] git rm [source] git add [destination]
  48. sensitive data help.github.com/articles/remove-sensitive-data

  49. selective staging git add --update (only tracked files) git add

    --all (all files)
  50. view configuration git config --list

  51. pushing to remotes git push origin master git push origin

    localbranch:remotebranch git push origin :remotebranch (deletes it)
  52. branch tracking git push origin master -u git push origin

    local:remote -u
  53. stashing edits git stash git stash apply git stash pop

    (applies, then removes from stack)
  54. fixing mistakes git checkout (undo edits) git reset --soft (keeps

    edits) git reset --hard (loses edits)
  55. merge strategies git merge --strategy=[strategy] strategies: recursive (default), ours, theirs,

    etc
  56. now: github tips

  57. keyboard shortcuts press ? to bring up the help

  58. issues in commits "Fix #54" -> closes issue #54 from

    the commit "For #54" -> links to #54 from commit, & vice versa
  59. all from your browser edit, commit, send a pull request

    ... all without leaving your browser
  60. blame who introduced this line, and when, and why

  61. file rendering markup, geoson, csv, and more

  62. integration with travis continuous integration (automated testing)

  63. thanks! git-scm.com/book help.github.com