Your SlideShare is downloading. ×
Git for Android Developers
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Git for Android Developers


Published on

Slides for a presentation I gave at AnDevCon

Slides for a presentation I gave at AnDevCon

Published in: Technology

  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. Git For the Android Developer Tony Hillerson, AnDevCon Fall 2013 #AnDevCon @tackmobile @thillerson
  • 2. About Me • @thillerson, +thillerson • Developer at Tack Mobile
 (, @tackmobile • Android, iOS, and Mobile Web • Rails, Node, maybe Elixir (one day) Presentation
  • 3. Diving Right In Learning by Doing Image © Dennis Barnes
  • 4. git init or git clone changes git add git commit 86650c185 changes git add git commit 6facfd9f3 changes git add git commit b02ef5bf1 ... ∞ Presentation
  • 5. .gitignore • Can be nested deeply • Presentation
  • 6. Git Log - The Project’s History • What got committed? • Commit messages • Content • When? Who? Presentation
  • 7. Remotes • remote add • clone • fetch • pull • push Presentation
  • 8. Tagging git tag -a -m"Tagging v1.0" v1.0 c5083fa master fb4f5d9 c5083fa 3f43fa3 • Both “-v1.0” and c5083fa will point to c5083fa • Push this tag with `git push --tags` • Can be cryptologically signed Presentation
  • 9. Recap of Simple Commands • git init - Creates an empty Git repository • git add - Adds a file to the stage (“stages a file”) • git rm - Removes from version control • git commit - Commits the staged changes to the (local) repository • git log - A view of the history • git tag - Names a commit • .gitignore - tells git to ignore certain files Presentation
  • 10. Why Source Control? • For the solo developer? • Protection against mistakes • Freedom • • • ... to refactor ... to experiment For the development team? • All of the above, plus: • Parallel development • Merging different code branches Presentation
  • 11. Preliminaries Getting Git and Getting Set Up
  • 12. What’s a Git? A completely ignorant, childish person with no manners. - Linus Torvalds Presentation
  • 13. What’s a Git? Git is a free & open source, distributed version control system designed to handle everything from small to very large projects with speed and efficiency. - Presentation
  • 14. Getting Set Up on Mac • Homebrew • • brew install git MacPorts Presentation
  • 15. Getting Set Up on Windows • msysgit Presentation
  • 16. Getting Set Up on Linux • apt, etc - you probably know the drill Presentation
  • 17. Gooies! • SourceTree (Mac and Windows) • TortoiseGit (Windows) Presentation
  • 18. IDE Integration • Android Studio
 You’re All Set • Eclipse Presentation
  • 19. Reference • Git • ProGit • Insider Guide to Github Presentation
  • 20. The Command Line A Short Sermon Presentation
  • 21. The Guts of Git The Little Bits that Make Git Different
  • 22. What’s With all the Characters? • SHA1 Hash e.g.
 86650c185eda50c9f9d58e2fbdf8b7113e5dee54 • Uniquely identifies a commit • Secure - very unlikely that someone can tamper with content in a repository Presentation
  • 23. SHA-1 Hash Keys “ ... to have a probability of a SHA1-hash collision rise to 1/2, you need about 10^24 objects ... - Scott Chacon in Pro Git (paraphrased) Presentation
  • 24. In Git There Are Only... • Blobs • Trees • Commits Presentation
  • 25. Blobs • The contents of your files are stored as binary files in .git/objects • Git is efficient. It only stores the same content once. • Identified by a SHA-1 • Show blob contents with e.g.
 `git show c7fb9f5` Presentation
  • 26. Trees • Trees give structure to blobs • Trees are also stored in .git/objects • Identified by SHA-1 • View a tree with ls-tree, e.g.
 `git ls-tree HEAD` Presentation
  • 27. Commits • Identified by a SHA-1 • Points to one tree • Has a required message • May have one (or more) parent commit(s) • Show the reachable commits from a commit
 `git rev-list HEAD` Presentation
  • 28. Refs • Point to commits • .git/refs/heads - the latest commits in local branches • HEAD - the latest commit on the current branch Presentation
  • 29. Blobs Are Content b84ed8ed 579a3b1 Presentation e8d5cf6
  • 30. Trees Give Structure 9899d2c com/yourcompany/androidapp b84ed8ed 579a3b1 e8d5cf6 3ffb35b Presentation /anotherpackage trees can point to other trees
  • 31. Commits Point to Trees d414c3e 9899d2c com/yourcompany/androidapp “Fixed bug # 42” b84ed8ed 579a3b1 e8d5cf6 3ffb35b Presentation /anotherpackage
  • 32. Commits Have Parents 090c953 4 “Updated the main activity” d414c3e 3 “Fixed bug #42” 4493671 2 “Typed awesome code” c1d1f60 1 “Initial commit” Presentation
  • 33. Refs Point to Commits HEAD 090c953 4 “Updated the main activity” d414c3e 3 “Fixed bug #42” 4493671 2 “Typed awesome code” c1d1f60 1 “Initial commit” Presentation
  • 34. And That’s All You Need To Know About Git Presentation
  • 35. And That’s All You Need To Know About Git (Mostly) Presentation
  • 36. Day to Day Git “What would you say you *do* here?”
  • 37. Semantic Commits Make Commits Mean Something Presentation
  • 38. Semantic Commits • Git’s not just a big truck • Commits should each mean something Presentation
  • 39. Interactive Add - Building Semantic Commits • `git add` simply adds to the stage • `git commit -a` will commit all changes to tracked files (add and commit) • `git add -i` -- a command line tool to interactively add changes • Individual commits shouldn’t leave things broken • Try to commit some useful feature or bug fix all together Presentation
  • 40. Interactive Add - SourceTree Presentation
  • 41. Branching Like Hitting Save Before You Fight the Level Boss Presentation
  • 42. Branching • New branch: git checkout -b <name> • A branch is a named ref • merging • rebasing Presentation
  • 43. How To Think About Branching • Mainline • What do you want “master” to mean? • Topic Branches • Branching examples Presentation
  • 44. Topic Branches • Branching is about controlling feature sets • Make a new branch for a story • Make a new branch for a bug fix • Make a new branch to spike something Presentation
  • 45. Team Branching Strategies • What do you want “master” to mean? • Keep master deployable? • • one strategy for web software Use “master” as an integration branch? • Each developer uses topic branches and integrates to master • Make a branch for releases Presentation
  • 46. Branching git checkout -b add_login_activity master fb4f5d9 c5083fa add_login_activity 9aa8827 Presentation fe594ce ccb6f5e
  • 47. Branching: Merging git checkout master git merge add_login_activity master fb4f5d9 c5083fa 9aa8827 3f43fa3 fe594ce ccb6f5e add_login_activity 9aa8827 Presentation fe594ce ccb6f5e
  • 48. Branching: Rebasing master fb4f5d9 c5083fa 3f43fa3 add_login_activity before 9aa8827 fe594ce ccb6f5e master fb4f5d9 c5083fa 3f43fa3 add_login_activity after `git rebase master` Presentation 9aa8827 fe594ce ccb6f5e
  • 49. Branching: Rebasing • Better than merging in some ways... • Don’t use if you’ve pushed your branch to a remote • Can override with `git push -force` • … but don’t Presentation
  • 50. Git Pull --rebase • Also available: `git pull --rebase` • Helpful for avoiding merge commits • May cause problems if git can’t automatically merge • Presentation `git reset HEAD` and start over with normal `git pull`
  • 51. Git Stash Like a Little Repo In Your Repo Presentation
  • 52. git stash • remember: git help stash • Stash away changes in a safe place • A Workflow:
 Stash -> Fix & Commit -> Pop Stash Presentation
  • 53. Cherry Pick I’ll Take One Of Those... And One Of Those... Presentation
  • 54. Cherry Pick • When you need a commit’s changes • But not its history Presentation
  • 55. Cherry-pick git cherry-pick fe594ce A new commit with the changes from fe594ce master fb4f5d9 c5083fa 3f43fa3 add_login_activity 9aa8827 Presentation fe594ce ccb6f5e
  • 56. Whoops! Lots Of Ways To Fix It Presentation
  • 57. git checkout • `git checkout [filename]`
 remove unstaged changes Presentation
  • 58. git revert • Commits the reverse of a commit • The previous commit is still there • != svn revert Presentation
  • 59. git commit --amend • Oops! I misspelled something in the commit message • Oops! I did `git commit -a` and forgot to `git add` a file • Oops! I just committed a bug • USE ONLY BEFORE YOU SHARE CHANGES Presentation
  • 60. Interactive Rebase - Fixing History • git rebase -i [commit] • A list of all commits in the current order • Reorder • Fix a certain commit • Squash commits together • Delete commits • DON’T USE AFTER YOU’VE PUSHED Presentation
  • 61. git reset • `git reset [filename]` = opposite of `git add [filename]` • `git reset HEAD` = same as above - acts on all tracked changes • `git reset HEAD^` (also ^^, or ~1, ~42, etc.) = rollback commits to working tree • All examples of “mixed” reset Presentation
  • 62. git reset --soft [commit] 1. Moves HEAD to [commit] 2. Puts the “popped” contents on the index Presentation
  • 63. git reset [commit] (“mixed” - default) 1. Moves HEAD to [commit] 2. Puts the “popped” contents on the index 3. Moves the index’s changes to the working tree 4. Clears the index Presentation
  • 64. git reset --hard [commit] (DESTRUCTIVE!!!) 1. Moves HEAD to [commit] 2. Puts the “popped” contents on the index 3. Moves the index’s changes to the working tree 4. Clears the index 5. Makes the working copy look like the index Presentation
  • 65. git reset use cases • Back that last commit up (git reset HEAD^) • Don’t forget `commit --amend` • Oops, didn’t mean to commit that file • I meant that commit to be on a different branch! Presentation
  • 66. Git Flow A Popular Branching Model Presentation
  • 67. Git Flow • Conventions to follow • Tools to help you follow conventions • Presentation
  • 68. Git Flow Conventions: Master Branch • The master branch is what is publicly available now • You don’t commit directly to master Presentation
  • 69. 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” Presentation
  • 70. 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 Presentation
  • 71. Git Flow Conventions: Hotfixes • OMG Problems in Production, create a hotfix: “hotfix/foo” • Branch from master (not develop) Presentation
  • 72. 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 Presentation
  • 73. Branch Lifecycle • Features • • • Start from develop Finished and merged to develop Releases • Start from develop • Finished and merged to master and develop Presentation
  • 74. Git Flow in Action: Features master develop feature/somefeature Presentation
  • 75. Git Flow in Action: Releases master release/v1.0 develop Presentation
  • 76. The Take Home • SCM Is Important • No matter what kind of developer you are • Git is fundamentally different from the others • It’s not a database of patches • It’s a history of filesystem snapshots • It gives you freedom to innovate, make mistakes, and collaborate. Presentation
  • 77. Thank you! Git for the Android Developer • Tony Hillerson • Questions? • We’re Hiring! • Excellent Team • Awesome Projects • Great Office