Working with Git

701 views

Published on

Talk given at AnDevCon Spring 2014 in Boston.

Published in: Software, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
701
On SlideShare
0
From Embeds
0
Number of Embeds
22
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Working with Git

  1. 1. Working with Git For the Android Developer slideshare.net/thillerson Tony Hillerson, AnDevCon Spring 2014
  2. 2. Presentation tackmobile.comPresentation tackmobile.com About Me • @thillerson, +thillerson • Partner, Developer at Tack Mobile
 (tackmobile.com), @tackmobile • Android, iOS, and Mobile Web • Rails, Node, maybe Elixir (one day)
  3. 3. Presentation tackmobile.comPresentation tackmobile.com What We’ll Cover Today • The Git Database • Configuration • Working with Multiple Repositories • ssh, submodules, subtrees • Advanced Querying • Git Flow for Delivering Releases
  4. 4. Presentation tackmobile.com The Git Database Get Acquainted
  5. 5. Presentation tackmobile.com .git • Each git repository has a database in the .git directory • HEAD, FETCH_HEAD, ORIG_HEAD • objects • refs • etc… hooks
  6. 6. Presentation tackmobile.com Poking Around • git show <commit> • Shows blob contents, tree info, commit/ref logs • git ls-tree • git rev-list
  7. 7. Presentation tackmobile.com Configuration Get Comfortable
  8. 8. Presentation tackmobile.com gitconfig locations Global /etc/gitconfig User ~/.gitconfig Local Project
 (not shared) .git/config git-scm.com/book/en/Customizing-Git-Git- Configuration
  9. 9. Presentation tackmobile.com Configure Colors • git config color.diff auto • [color]
 diff = auto
 status = auto
 branch = auto
 ui = true
  10. 10. Presentation tackmobile.com Configure Aliases • git config alias.co checkout • [alias]
 co = checkout
 cp = cherry-pick
 unstage = reset HEAD
 lop = log -p
  11. 11. Presentation tackmobile.com Terse Log • [alias]
 lol = log --pretty=format:'%Cred%h%Creset - %C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev- commit --graph —decorate • - Scott Chacon
  12. 12. Presentation tackmobile.com You Have Questions Get Answers
  13. 13. Presentation tackmobile.com When Was The First Commit? • Assuming “master” is the conventional “master”: • git log master --oneline | tail -n1
  14. 14. Presentation tackmobile.com When Did This Branch Branch? • git merge-base <branch> <parent> • probably… • git help merge-base
  15. 15. Presentation tackmobile.com Do I Have The Latest Changes? • git fetch - git must have the latest changes locally to tell you • git log develop..origin/develop • If no commits - yes, you have the latest • Tools like SourceTree will often do automatic fetches
  16. 16. Presentation tackmobile.com Do I Have Unpushed Changes? • The opposite! • git log origin/develop..develop
  17. 17. Presentation tackmobile.com What’s Upstream? • Upstream is the repository/branch from which changes come • ➜ git status # On branch develop
 # Your branch is behind 'origin/develop' by 2 commits, and can be fast-forwarded.
 # (use "git pull" to update your local branch)
 #
 nothing to commit, working directory clean
  18. 18. Presentation tackmobile.com Setting Upstream • In .gitconfig:
 [branch]
 autosetupmerge = always • git branch -u <remote> [branch]
  19. 19. Presentation tackmobile.com Checking All Branches • ➜ git branch -lvv * develop 24c4398 [origin/develop: behind 2]
 warning fixed.
 master 3cc12bb [origin/master: behind 3]
 Giving username an email keyboard for what seems to be the common use case. • Add -a to include remotes
  20. 20. Presentation tackmobile.com Is This Branch Merged? • Which branches contain a given commit? • git branch --contains <branch/commit> • ➜ git branch --contains develop * develop • ➜ git branch --contains master
 * develop
 master
  21. 21. Presentation tackmobile.com Where Did This Bug Come From? • git bisect! • Known Good Commit <|> Latest Buggy Commit • build and run • mark a commit good or bad • git walks forward or backward • repeat
  22. 22. Presentation tackmobile.com Where Did My Commit Go? • Have you lost a commit you know you made? • git reflog!
  23. 23. Presentation tackmobile.com Working With Multiple Repositories Get Integrated
  24. 24. Presentation tackmobile.com Local Repos • git clone <path> <new path> • git push origin <branch> • git pull origin <branch> WAT
  25. 25. Presentation tackmobile.com ssh • git clone ssh://user@host/path/.git • Push to origin • Pull from origin • Use when just starting out a private project?
  26. 26. Presentation tackmobile.com Multiple Remotes • git remote add <path> • git push otherremote branch • git pull otherremote branch • Why? other upstream repo, maybe a fork
  27. 27. Presentation tackmobile.com Submodules • A git repository tracked as part of the tree of another repository • Git (kind of) manages it • cd in -> get another git repo • Sort of a broken SVN external (the only thing I like better about SVN than git)
  28. 28. Presentation tackmobile.com Submodules: What are they good for? • Dependencies • That are under frequent development • That are not distributed as a jar or through maven
  29. 29. Presentation tackmobile.com Submodules: Why do they suck? • You have to be explicit about them; git won’t manage them for you • Devs on your team need to be educated • Have to jump through hoops to connect the repo back to its origin • Hard to share local changes
  30. 30. Presentation tackmobile.com Working with Submodules • git submodule add <repo> <local name> • .gitmodules • Keeps submodule at a explicit commit • ignore = dirty • git submodule deinit, git rm
  31. 31. Presentation tackmobile.com Submodules: Workflow • If you need to move the submodule’s commit • cd to submodule • move to the new commit • cd to parent • git add and commit • When you pull, add:
 git submodule update —install —recursive
  32. 32. Presentation tackmobile.com Submodule Examples • Utility Project
  33. 33. Presentation tackmobile.com Submodule tips • Avoid them. • If you need to use them, make sure your team understands them.
  34. 34. Presentation tackmobile.com Subtrees • Add repo contents directly to tree • http://blogs.atlassian.com/2013/05/ alternatives-to-git-submodule-git-subtree/
  35. 35. Presentation tackmobile.com Git Flow Getting Apps Shipped
  36. 36. Presentation tackmobile.com Git Flow • Conventions to follow • Tools to help you follow conventions • http://nvie.com/posts/a-successful-git- branching-model/
  37. 37. Presentation tackmobile.com Git Flow Conventions: Master Branch • The master branch is what is publicly available now • You don’t commit directly to master
  38. 38. Presentation tackmobile.com Git Flow Conventions: Develop Branch • A branch called “develop” is what will become the next version • Day to day work happens on develop • “Integration branch”
  39. 39. Presentation tackmobile.com Git Flow Conventions: Feature Branches • Long running development go on feature branches: “feature/foo” • Long running: “more than one commit” • Can be pushed to the server and shared • Branch from develop
  40. 40. Presentation tackmobile.com Git Flow Conventions: Hotfixes • OMG Problems in Production, create a hotfix: “hotfix/foo” • Branch from master (not develop)
  41. 41. Presentation tackmobile.com Git Flow Conventions: Releases • When a release is almost ready on develop, create a release branch: “release/2.0.4” • Branch from develop • Develop continues on for the next release • Small changes to release go on release branch
  42. 42. Presentation tackmobile.com Branch Lifecycle • Features • Start from develop • Finished and merged to develop • Releases • Start from develop • Finished and merged to master and develop
  43. 43. Presentation tackmobile.com Git Flow in Action: Features feature/somefeature master develop
  44. 44. Presentation tackmobile.com Git Flow in Action: Releases release/v1.0 master develop
  45. 45. Presentation tackmobile.com The Take Home • You know your way around .git • You can customize and configure git • You understand submodules and where they work (and don’t work) • You know how git flow can help when releasing apps with a team
  46. 46. Thank you! Working with Git for the Android Developer • Tony Hillerson • Questions? • We’re Hiring! careers@tackmobile.com • Excellent Team • Awesome Projects • Great Office

×