Git for the Android Developer


Published on

Whether you work alone or in a team, some sort of source control management is essential to you as a developer for things like keeping a history of your code, dealing with integrating code, managing releases and making your development workflow through different features painless. If you're coming from something like CVS or SVN, the open-source Git version control system will turn what you know of SCM on its head. In this presentation from AnDevCon 2011, EffectiveUI’s Tony Hillerson explains why Git is different, and what that difference means to you as an Android developer.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Git for the Android Developer

  1. 1. GitFor the Android DeveloperAnDevCon 2011 : Tony Hillerson#AnDevCon #effectiveui
  2. 2. About Me• Worked with Android and Git for a few years now• O’Reilly Screencaster: Developing Android Applications • •• Tech Reviewer:
  3. 3. PreliminariesGetting Git and Getting Set Up
  4. 4. What’s a Git? A completely ignorant, childish person with no manners. - Linus Torvalds
  5. 5. 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. -
  6. 6. Getting Set Up on Mac• Homebrew -• MacPorts -
  7. 7. Getting Set Up on Windows• msysgit -• Cygwin -
  8. 8. Getting Set Up on Linux• apt, etc - you probably know the drill
  9. 9. Gooies!• Git Tower - M• Brother Bard’s GitX fork -Mac A C• Tortoise Git - WMac I N
  10. 10. Eclipse Integration•
  11. 11. Reference• Git -• ProGit - - Scott Chacon• Insider Guide to Github - v-scgithub/insider-guide-to-github - Scott Chacon
  12. 12. Note• Code may be in backticks: `git <command>` • Don’t input the backticks
  13. 13. The Command LineA Short Sermon
  14. 14. Seven Use CasesWhere Git will Make your Life Easier
  15. 15. Project HistoryGit will Make your Life Easier
  16. 16. 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
  17. 17. Simple Commands• `git init`- Creates an empty Git repository• .gitignore - tells git to ignore certain files• `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`• `git add -i` Interactive Add
  18. 18. git git or cloneinit git 86650c185eda50c9f9d58e2fbdf8b7113e5dee54 git commit changes add git git commit 6facfd9f34173f4fb024196996e948a87c85eb56 changes add git git commit b02ef5bf190e28ba24eab3ffab6133181cb5b5ef changes add ... ∞Simple Workflow
  19. 19. .gitignore• Can be nested deeply• • Use it! Contribute!
  20. 20. Git Log - The Project’s History• What got committed?• Commit messages• Content• When? Who?
  21. 21. What’s With all the Characters?86650c185eda50c9f9d58e2fbdf8b7113e5dee54• SHA1 Hash• Uniquely identifies a commit• Secure - very unlikely that someone can tamper with content in a repository “... 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)
  22. 22. Interactive Add - Building 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
  23. 23. Getting Out of TroubleGit will Make your Life Easier
  24. 24. Advanced Commands• blame• checkout• commit -a• reset• stash• commit --amend• revert
  25. 25. git blame• remember: git help blame• Who broke the build??? etc...
  26. 26. git checkout, commit -a, reset• remember: git help reset• `git commit -a` = commit bypassing `git add`• `git checkout <filename>` = remove all unstaged changes• `git reset <filename>` = opposite of `git add <filename>`• `git reset HEAD` = same as above - acts on all changes• `git reset HEAD^` (also ^^, or ~1, ~42, etc.) = rollback commits to working tree• `git reset --soft` = rollback commit to stage
  27. 27. git stash• remember: git help stash• Stash away changes in a safe place
  28. 28. 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
  29. 29. git revert• Commits the reverse of a commit• The previous commit is still there• != svn revert
  30. 30. CollaborationGit will Make your Life Easier
  31. 31. Remotes• remote add• push• clone• pull• fetch
  32. 32. Strategies• Star• Peer to Peer• Blessed Repository• Hierarchical
  33. 33. Committer Committer Committer “The Committer Server” Committer CommitterStar
  34. 34. • ssh://user@computer:path/to/repo.git• http Peer• Gitosis• Gitolite Peer PeerPeer to N Peers
  35. 35. Dictator ... etc. Maintains a “blessed repository” Lieutenant LieutenantDeveloper Developer Developer DeveloperHierarchical (Linux model)
  36. 36. Topical DevelopmentGit will Make your Life Easier
  37. 37. Branching• checkout -b• merging• Rebasing• cherry-pick
  38. 38. How To Think About Branching• Topic Branches• Mainline • What do you want “master” to mean?• Branching examples
  39. 39. 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
  40. 40. 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
  41. 41. Branching git checkout -b add_login_activitymasterMac fb4f5d9 c5083fa add_login_activity Mac 9aa8827 fe594ce ccb6f5e
  42. 42. Branching: Merging git checkout master git merge add_login_activitymasterMac 9aa8827 fe594ce ccb6f5e fb4f5d9 c5083fa 3f43fa3 add_login_activity Mac 9aa8827 fe594ce ccb6f5e
  43. 43. Branching: Rebasing master Mac fb4f5d9 c5083fa 3f43fa3 add_login_activity before Mac 9aa8827 fe594ce ccb6f5emasterMac fb4f5d9 c5083fa 3f43fa3 add_login_activit after Mac 9aa8827 fe594ce ccb6f5e `git rebase master`
  44. 44. Branching: Rebasing• Better than merging• Don’t use if you’ve pushed your branch to a remote • Git will complain about refs • Can override with `git push -force`• Also available on `git pull --rebase` • Helpful for avoiding merge commits • May cause problems if git can’t automatically merge • `git reset HEAD` and start over with normal `git pull`
  45. 45. Cherry-pick git cherry-pick fe594ce A new commitmaster with the changes from fe594ceMac fb4f5d9 c5083fa 3f43fa3 add_login_activity Mac 9aa8827 fe594ce ccb6f5e
  46. 46. Cherry Picking• Doesn’t add a reference to the old commit• Only applies the changes• Future merges should apply cleanly
  47. 47. Release ManagementGit will Make your Life Easier
  48. 48. Tagging• tag• push --tags
  49. 49. Tagging git tag -a -m"Tagging v1.0" v1.0 c5083famasterMac fb4f5d9 c5083fa 3f43fa3• Both -v1.0 and c5083fa will point to c5083fa• Push this tag with `git push --tags`• Can be cryptologically signed
  50. 50. Bug FixingGit will Make your Life Easier
  51. 51. Bug Fixing• blame• bisect
  52. 52. Bisect git bisect start HEAD git bisect bad fb4f5d9 Mac c5083fa 3f43fa3 9aa8827 fe594ce ccb6f5e 2e531cb git bisect good fb4f5d9 HEAD fb4f5d9 Mac c5083fa 3f43fa3 9aa8827 fe594ce ccb6f5e 2e531cb git bisect good Git tells you this was the git bisect good first bad git bisect bad commit HEAD fb4f5d9 Mac c5083fa 3f43fa3 9aa8827 fe594ce ccb6f5e 2e531cb
  53. 53. Open Source CodeGit will Make your Life Easier
  54. 54.• Search it!• Forking• Pull Requests
  55. 55. Thank you!GitFor the Android DeveloperAnDevCon 2011 : Tony Hillerson