Your SlideShare is downloading. ×
  • Like
SCM for Android Developers Using Git
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.


Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

SCM for Android Developers Using Git


Delivered March 8 2011 at AnDevCon

Delivered March 8 2011 at AnDevCon

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    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

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. GitFor the Android DeveloperAnDevCon 2011 : Tony Hillerson#AnDevCon #effectiveui
  • 2. About Me• Worked with Android and Git for a few years now• O’Reilly Screencaster: Developing Android Applications • •• Tech Reviewer:
  • 3. PreliminariesGetting Git and Getting Set Up
  • 4. What’s a Git? A completely ignorant, childish person with no manners. - Linus Torvalds
  • 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. Getting Set Up on Mac• Homebrew -• MacPorts -
  • 7. Getting Set Up on Windows• msysgit -• Cygwin -
  • 8. Getting Set Up on Linux• apt, etc - you probably know the drill
  • 9. Gooies!• Git Tower - M• Brother Bard’s GitX fork -Mac A C• Tortoise Git - WMac I N
  • 10. Eclipse Integration•
  • 11. Reference• Git -• ProGit - - Scott Chacon• Insider Guide to Github - v-scgithub/insider-guide-to-github - Scott Chacon
  • 12. Note• Code may be in backticks: `git <command>` • Don’t input the backticks
  • 13. The Command LineA Short Sermon
  • 14. Seven Use CasesWhere Git will Make your Life Easier
  • 15. Project HistoryGit will Make your Life Easier
  • 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. 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. 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. .gitignore• Can be nested deeply• • Use it! Contribute!
  • 20. Git Log - The Project’s History• What got committed?• Commit messages• Content• When? Who?
  • 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. 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. Getting Out of TroubleGit will Make your Life Easier
  • 24. Advanced Commands• blame• checkout• commit -a• reset• stash• commit --amend• revert
  • 25. git blame• remember: git help blame• Who broke the build??? etc...
  • 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. git stash• remember: git help stash• Stash away changes in a safe place
  • 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. git revert• Commits the reverse of a commit• The previous commit is still there• != svn revert
  • 30. CollaborationGit will Make your Life Easier
  • 31. Remotes• remote add• push• clone• pull• fetch
  • 32. Strategies• Star• Peer to Peer• Blessed Repository• Hierarchical
  • 33. Committer Committer Committer “The Committer Server” Committer CommitterStar
  • 34. • ssh://user@computer:path/to/repo.git• http Peer• Gitosis• Gitolite Peer PeerPeer to N Peers
  • 35. Dictator ... etc. Maintains a “blessed repository” Lieutenant LieutenantDeveloper Developer Developer DeveloperHierarchical (Linux model)
  • 36. Topical DevelopmentGit will Make your Life Easier
  • 37. Branching• checkout -b• merging• Rebasing• cherry-pick
  • 38. How To Think About Branching• Topic Branches• Mainline • What do you want “master” to mean?• Branching examples
  • 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. 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. Branching git checkout -b add_login_activitymasterMac fb4f5d9 c5083fa add_login_activity Mac 9aa8827 fe594ce ccb6f5e
  • 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. 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. 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. 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. Cherry Picking• Doesn’t add a reference to the old commit• Only applies the changes• Future merges should apply cleanly
  • 47. Release ManagementGit will Make your Life Easier
  • 48. Tagging• tag• push --tags
  • 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. Bug FixingGit will Make your Life Easier
  • 51. Bug Fixing• blame• bisect
  • 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. Open Source CodeGit will Make your Life Easier
  • 54.• Search it!• Forking• Pull Requests
  • 55. Thank you!GitFor the Android DeveloperAnDevCon 2011 : Tony Hillerson