1 of 29

Useful git

How to get more out of what you use anyway

2 of 29

Nick Terner

Developer who also does ops

Expert troubleshooter, startup generalist

@somenick

3 of 29

Agenda

  • Why?
  • What?
  • How?

4 of 29

Why?

5 of 29

SCM

6 of 29

Those who cannot learn from history are doomed to repeat it.

7 of 29

Those who cannot remember the past are condemned to repeat it.

-- George Santayana

8 of 29

Linus, Linux, Git

9 of 29

Use SCM!

10 of 29

What?

11 of 29

What is git?

  • Metadata
  • Communicate with your future self
  • Communicate with others
  • A search engine into the past
  • Primitives for collaboration processes

12 of 29

RTFM

13 of 29

Commit Messages

Describe the purpose of what you did - the ‘Why’��Example:�� fix TLS security�� # OR EVEN�� improve crypto params for TLS�� # BUT NOT�� replace MD5 with SHA256�

14 of 29

Commit Messages

DO:

Two considerations for what (and how) to put in

  • what would you like to know the first time you lay eyes on the code, if you didn't write it?
  • would it be helpful in release notes?

�There are exceptions, but if hear anything new today, YOU'RE NOT an EXCEPTION

DON’T:

Generally, keyword like:

  • 'Updated'
  • 'Replace'
  • 'Edited'

indicate that you're not providing actual information

Do not edit files on Github

No Info Included

15 of 29

Maintenance Commits

  • Refactors
  • Comments
  • Cleanups
  • whitespace and formatting

  1. be specific about what you touch
  2. one thing per commit - particularly when renaming/moving files

16 of 29

Commit Messages: removing junk

  • Remove stuff you don't use, code gets stale
  • Err on the side of removing stuff, but…
  • Document what went away, why, and what replaced it - use both the commit message and the code comments where appropriate
  • Don’t worry about losing stuff. SCMs are intended to keep history, and git is good in keeping it searchable and discoverable
  • For the smaller, localized (class, function) changes there's a tendency to comment-out. Use sound judgement; also that's what code reviews are for

17 of 29

Infrastructure as Code

  • If it's part of a feature it's part of the commit!
  • Cooperation and CRs are a must
  • Single Source of Truth

18 of 29

Code Reviews and Communication

Do both and be good at it

E.g.:

https://www.objc.io/issues/22-scale/dropbox/

19 of 29

How?

20 of 29

Very basics

checking out somebody else's branch...��Once Alice pushes her 'feature' branch, origin/feature will appear in the next�fetch for Bob, who can then simply do::�� git checkout feature_branch�

21 of 29

Branch Namespaces

origin/<user>/NAME� origin/topic/NAME� origin/old/NAME� origin/shared/NAME�

origin/pulls/PR# - github��bitbucket has had more granular ACLs for a while

22 of 29

Interfaces

  • CLI
  • IDE integrations
  • Git GUIs

���

23 of 29

Work Flows

  • git-flow
  • gerrit
  • phabricator / arc(anicst)

24 of 29

Rebase / Merge

Rebase:

  • Clean, explorable tree
  • No merger bottlenecks; developer entirely responsible
  • Easy cherry-picking

Merge:

  • Less learning curve
  • Used to be the only way for GitHub PRs
  • Easier back-porting flows and tracking

Maintaining multiple concurrent releases is a hassle with either

https://blog.spreedly.com/2014/06/24/merge-pull-request-considered-harmful/

25 of 29

Rebase during dev

  • Commit often, make pretty later
  • Usually you own the feature branch
  • Use !fixup and !squash commits with rebase -i --auto-squash

26 of 29

GUI

  • SmartGit
  • Github desktop
  • SourceTree
  • Git gui + gitk

27 of 29

Interesting Features

Commands:

  • git alias
  • git grep
  • git diff master...HEAD
  • git config:
    • colors
    • merge/rebase/other policies
    • repo/global
  • git stash
  • git rebase -i --autosquash: !fixup and !squash
  • git blame
  • git log: graphs, filters/
  • git push --force-with-lease
  • git bisect

  • Hooks
  • repo transformations
  • .gitignore
  • .gitattributes
    • /CHANGELOG.rst merge=union�

https://github.com/tiimgreen/github-cheat-sheet

28 of 29

Takeaways

  • Invest
  • Tailor to your usecase:
    • Flows
    • Tooling
  • Challenge yourself and adapt

29 of 29

Looking for projects

Thank You