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

Practical git(lab)

Practical git(lab)

Git best practices, tips & tricks. Talk given to my teammates at Ideaknow.

Tweet

Transcript

  1. Practical git(lab) no theory today, I promise!

  2. Best practices Tips & tricks Rebase & you Terminal hackery

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

    that branches are homeomorphic endofunctors mapping submanifolds of a Hilbert space ❞ -- The Internet
  4. ❝ SourceTree sucks ❞ -- Me

  5. Best practices Good

  6. commit commit often write good commit messages do not commit

    unrelated changes together
  7. commit commit often write good commit messages do not commit

    unrelated changes together
  8. branches anything in master is deployable anything in develop will

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

    be delivered in the next release * feature-branches is where we should commit
  10. * Well, unless the client calls in the last minute

    to demand ask you politely to drop a feature because they fucked up had some issues on their side. Something that never happens. Ever. Nope. branches
  11. 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
  12. .gitignore know and use .gitignore committed files cannot be ignored

    (well, not easily) https://github.com/github/gitignore
  13. git pull God kills a kitten every time you do

    this: Merge branch 'develop_15.5' of gitlab.ideaknow.com:sab-3-0/bsmobil- translations into develop_15.5
  14. None
  15. 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:
  16. git pull do it for the kittens if you need

    to solve conflicts when pushing/ pulling, you are doing something wrong
  17. merge 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 learn (both ways) fun
  18. merge request revelation

  19. merge 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” “”
  20. merge request be the first to review your own code

    learn to criticise and to be criticised your work != you open a merge request at any time, even to discuss an upcoming feature
  21. clean history

  22. Tips & tricks

  23. How do I… …search all of git history for a

    string? git log --all -G <string>
  24. How do I… …find the commit that broke my project?

    git bisect start git bisect good git bisect bad
  25. How do I… …save current changes for later use without

    committing because you need to do something urgent? 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… …revert a pushed change? git revert <commit

    sha>
  31. How do I… …copy an existing commit (from another branch

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

    multiple commits? git add -p <file>
  33. How do I… …clean remote branches? git remote prune origin

    git push origin --delete <branch_name> …delete a remote branch?
  34. How do I… … remove untracked files and directories? git

    clean -d -f ⚠
  35. How do I… … show changes introduced by a commit?

    git show <commit sha> … show changes introduced by a merge commit? git show -m <commit sha>
  36. How do I… … find who the fuck wrote this

    aberration? git blame path/to/aberration
  37. Rebase & you

  38. … rypress.com/tutorials/git/rebasing.html?

  39. Terminal hackery

  40. autocompletion & prompt brew install bash-completion brew install git

  41. better git log git config --global alias.lg "log --color --graph

    -- pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
  42. alias! `wo` credits: https://twitter.com/_supermarin

  43. Questions?

  44. Thanks!