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

Practical Git(Hub)

Practical Git(Hub)

Git basics, best practices, tips & tricks. Talk given to my teammates at Kerad Games.

[email protected]

February 17, 2016
Tweet

Other Decks in Programming

Transcript

  1. ❝ git gets easier once you get the basic idea

    that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space ❞ -- The Internet
  2. Git is… …a distributed revision control and source code management

    system. … not an evolution of SVN. … not easy.
  3. add am apply archimport archive bisect blame branch bundle cat-file

    check-attr check-ignore check-mailmap check-ref- format checkout checkout- index cherry cherry-pick citool clean clone commit commit-tree config count-objects cvsexportcomm it cvsimport cvsserver daemon describe diff diff-files diff-index diff-tree difftool fast-export fast-import fetch fetch-pack filter-branch fmt-merge-msg for-each-ref format-patch fsck gc get-tar- commit-id grep gui hash-object help http-backend http-fetch http-push imap-send index-pack init instaweb log ls-files ls-remote ls-tree mailinfo mailsplit merge merge-base merge-file merge-index merge-one- file merge-tree mergetool mktag mktree mv name-rev notes pack-objects pack- redundant pack-refs parse-remote patch-id prune prune-packed pull push quiltimport read-tree rebase receive-pack reflog relink remote repack replace request-pull rerere reset rev-list rev-parse revert rm send-email send-pack shell shortlog show show-branch show-index show-ref stash status stripspace submodule svn symbolic-ref tag unpack-file unpack- objects update-index update-ref update- server-info upload- archive upload-pack var verify-pack verify-tag whatchanged write-tree
  4. add am apply archimport archive bisect blame branch bundle cat-file

    check-attr check-ignore check-mailmap check-ref- format checkout checkout- index cherry cherry-pick citool clean clone commit commit-tree config count-objects cvsexportcomm it cvsimport cvsserver daemon describe diff diff-files diff-index diff-tree difftool fast-export fast-import fetch fetch-pack filter-branch fmt-merge-msg for-each-ref format-patch fsck gc get-tar- commit-id grep gui hash-object help http-backend http-fetch http-push imap-send index-pack init instaweb log ls-files ls-remote ls-tree mailinfo mailsplit merge merge-base merge-file merge-index merge-one- file merge-tree mergetool mktag mktree mv name-rev notes pack-objects pack- redundant pack-refs parse-remote patch-id prune prune-packed pull push quiltimport read-tree rebase receive-pack reflog relink remote repack replace request-pull rerere reset rev-list rev-parse revert rm send-email send-pack shell shortlog show show-branch show-index show-ref stash status stripspace submodule svn symbolic-ref tag unpack-file unpack- objects update-index update-ref update- server-info upload- archive upload-pack var verify-pack verify-tag whatchanged write-tree
  5. Making changes …or how add, commit, checkout works HEAD Index

    Working Directory checkout add commit reset
  6. Grouping changes …or how to use branches via checkout, branch,

    merge A develop feature HEAD git branch feature
  7. Grouping changes …or how to use branches via checkout, branch,

    merge A develop feature HEAD git branch feature git checkout feature
  8. Grouping changes …or how to use branches via checkout, branch,

    merge A develop feature HEAD git branch feature git checkout feature git add & git commit B
  9. Grouping changes …or how to use branches via checkout, branch,

    merge A develop feature HEAD git branch feature git checkout feature git add & git commit git add & git commit B C
  10. Grouping changes …or how to use branches via checkout, branch,

    merge A develop feature HEAD git branch feature git checkout feature git add & git commit git add & git commit … B C D E
  11. Grouping changes …or how to use branches via checkout, branch,

    merge A develop feature HEAD git branch feature git checkout feature git add & git commit git add & git commit … git checkout develop B C D E
  12. Grouping changes …or how to use branches via checkout, branch,

    merge A develop feature HEAD git branch feature git checkout feature git add & git commit git add & git commit … git checkout develop git merge feature B C D E F
  13. branches anything in master is deployable anything in develop will

    be delivered in the next release * feature-branches is where we should commit
  14. branches anything in master is deployable anything in develop will

    be delivered in the next release feature-branches is where we should commit
  15. branches It’s ok to have different branch schemes, depends on

    client, project, technology… a common workflow > no workflow at all keep it simple or people won’t follow the scheme
  16. .gitignore know and use .gitignore committed files cannot be ignored

    (well, not easily) https://github.com/github/gitignore take a look at git config and .gitattributes as well
  17. git pull God kills a kitten every time you do

    this: Merge branch 'foobar' of github.com:keradgames/goldenmanager-ios into foobar
  18. git pull git pull is considered harmful git fetch origin

    git rebase origin/develop git config --global pull.ff only when changes can’t be applied fast-forward:
  19. git pull do it for the kittens if you need

    to solve conflicts when pulling, you are doing something wrong
  20. pull request why? we all make errors find logic bugs

    high quality code enforce readable code style enforce good commit history let people know what you are working on (even discuss future features) learn (both ways) fun
  21. pull request useful messages: “Can we make this more readable?”

    “What would be a better name for this method?” “This needs to be refactored into smaller methods” “Why did you choose this approach?” “”
  22. Historical revisionism A B C D E develop feature git

    checkout feature git rebase develop
  23. Rebasing dangers … or when not to use rebase. Don’t

    rebase public history. Think before rebasing long & old branches.
  24. How do I… …find the commit that broke my project?

    git bisect start git bisect bad git bisect good <rev> # Bisecting: N revisions left to test after this (roughly log2(N) steps) git bisect run
  25. How do I… …save current changes for later use without

    committing because you need to do something else? git stash git stash list git stash pop git stash apply
  26. How do I… …revert a non-staged change? git checkout --

    path/to/file/to/revert git checkout -- . …revert all non-staged changes (and nothing else)? ⚠ ⚠
  27. How do I… …revert a staged change? git reset path/to/file/to/revert

    git reset …revert all staged changes (and nothing else)?
  28. How do I… …revert all staged and non-staged changes? (i.e.:

    all non-committed changes) git reset --hard ⚠
  29. How do I… …revert the last non-pushed commit? git reset

    HEAD^ …revert/modify a previous non-pushed commit? git rebase -i <parent commit>
  30. How do I… …copy an existing commit (from another branch

    or another point in history) ? git cherry-pick <commit SHA>
  31. How do I… …split changes in a single file into

    multiple commits? git add -p <file> # for each hunk: y, n, s, e … git add -i
  32. How do I… …clean remote branches? git remote prune origin

    git config --global remote.origin.prune true git push origin --delete <branch_name> …delete a remote branch?
  33. How do I… … see changes introduced by a commit?

    git show <commit sha|tag|branch> … see changes introduced by a merge commit? git show -m <commit SHA>
  34. How do I… … find who fucked up modified lines

    42 to 84 of this file? git blame -L 42,84 path/to/file