GitFor the Android DeveloperAnDevCon 2011 : Tony Hillerson#AnDevCon #effectiveuihttp://www.slideshare.net/thillerson/scm-f...
About Me• Worked with Android and Git for a few years now• O’Reilly Screencaster: Developing Android Applications  • http:...
PreliminariesGetting Git and Getting Set Up
What’s a Git? A completely ignorant, childish person with no manners.                                                     ...
What’s a Git?     Git is a free & open source, distributed version    control system designed to handle everything from   ...
Getting Set Up on Mac• Homebrew - http://mxcl.github.com/homebrew/• MacPorts - http://www.macports.org/
Getting Set Up on Windows• msysgit -http://code.google.com/p/msysgit/• Cygwin - http://www.cygwin.com/
Getting Set Up on Linux• apt, etc - you probably know the drill
Gooies!• Git Tower - http://git-tower.com                                                           M• Brother Bard’s GitX...
Eclipse Integration• http://www.eclipse.org/egit/
Reference• Git - http://git-scm.com/• ProGit - http://progit.org/book/ - Scott Chacon• Insider Guide to Github - http://ww...
Note• Code may be in backticks: `git <command>`  • Don’t input the backticks
The Command LineA Short Sermon
Seven Use CasesWhere Git will Make your Life Easier
Project HistoryGit will Make your Life Easier
Why Source Control• For the solo developer?   •   Protection against mistakes   •   Freedom       •   to refactor       • ...
Simple Commands• `git init`- Creates an empty Git repository• .gitignore - tells git to ignore certain files• `git add` - A...
git               git         or      cloneinit                 git                  86650c185eda50c9f9d58e2fbdf8b7113e5de...
.gitignore• Can be nested deeply• https://github.com/github/gitignore  • Use it! Contribute!
Git Log - The Project’s History• What got committed?• Commit messages• Content• When? Who?
What’s With all the Characters?86650c185eda50c9f9d58e2fbdf8b7113e5dee54• SHA1 Hash• Uniquely identifies a commit• Secure - ...
Interactive Add - Building Commits• `git add` simply adds to the stage• `git commit -a` will commit all changes to tracked...
Getting Out of TroubleGit will Make your Life Easier
Advanced Commands• blame• checkout• commit -a• reset• stash• commit --amend• revert
git blame• remember: git help blame• Who broke the build??? etc...
git checkout, commit -a, reset• remember: git help reset• `git commit -a` = commit bypassing `git add`• `git checkout <file...
git stash• remember: git help stash• Stash away changes in a safe place
git commit --amend• Oops! I misspelled something in the commit message• Oops! I did `git commit -a` and forgot to `git add...
git revert• Commits the reverse of a commit• The previous commit is still there• != svn revert
CollaborationGit will Make your Life Easier
Remotes• remote add• push• clone• pull• fetch
Strategies• Star• Peer to Peer• Blessed Repository• Hierarchical
Committer              Committer                Committer                           “The       Committer          Server” ...
• ssh://user@computer:path/to/repo.git• http                           Peer• Gitosis• Gitolite                     Peer   ...
Dictator      ... etc. Maintains a “blessed repository”            Lieutenant                                             ...
Topical DevelopmentGit will Make your Life Easier
Branching• checkout -b• merging• Rebasing• cherry-pick
How To Think About Branching• Topic Branches• Mainline  • What do you want “master” to mean?• Branching examples
Topic Branches• Branching is about controlling feature sets• Make a new branch for a story• Make a new branch for a bug fix...
Team Branching Strategies• What do you want “master” to mean?• Keep master deployable?  • one strategy for web software• U...
Branching                           git checkout -b add_login_activitymasterMac      fb4f5d9   c5083fa                    ...
Branching: Merging                                                git checkout master                                     ...
Branching: Rebasing master Mac       fb4f5d9   c5083fa         3f43fa3                           add_login_activity       ...
Branching: Rebasing• Better than merging• Don’t use if you’ve pushed your branch to a remote  • Git will complain about re...
Cherry-pick                 git cherry-pick fe594ce                                                       A new commitmast...
Cherry Picking• Doesn’t add a reference to the old commit• Only applies the changes• Future merges should apply cleanly
Release ManagementGit will Make your Life Easier
Tagging• tag• push --tags
Tagging      git tag -a -m"Tagging v1.0" v1.0 c5083famasterMac      fb4f5d9        c5083fa        3f43fa3• Both -v1.0 and ...
Bug FixingGit will Make your Life Easier
Bug Fixing• blame• bisect
Bisect  git bisect start                                                            HEAD  git bisect bad         fb4f5d9  ...
Open Source CodeGit will Make your Life Easier
Github.com• Search it!• Forking• Pull Requests
Thank you!GitFor the Android DeveloperAnDevCon 2011 : Tony Hillerson
Upcoming SlideShare
Loading in...5
×

Git for the Android Developer

1,350

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. This presentation explains why Git is different, and what that difference means to you as an Android developer.

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

No Downloads
Views
Total Views
1,350
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
9
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "Git for the Android Developer"

  1. 1. GitFor the Android DeveloperAnDevCon 2011 : Tony Hillerson#AnDevCon #effectiveuihttp://www.slideshare.net/thillerson/scm-for-android-developers-using-git
  2. 2. About Me• Worked with Android and Git for a few years now• O’Reilly Screencaster: Developing Android Applications • http://training.oreilly.com/androidapps/ • http://training.oreilly.com/androidapps2/• Tech Reviewer:
  3. 3. PreliminariesGetting Git and Getting Set Up
  4. 4. What’s a Git? A completely ignorant, childish person with no manners. - http://urbandictionary.com Linus Torvalds http://en.wikipedia.org/wiki/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. - http://git-scm.com
  6. 6. Getting Set Up on Mac• Homebrew - http://mxcl.github.com/homebrew/• MacPorts - http://www.macports.org/
  7. 7. Getting Set Up on Windows• msysgit -http://code.google.com/p/msysgit/• Cygwin - http://www.cygwin.com/
  8. 8. Getting Set Up on Linux• apt, etc - you probably know the drill
  9. 9. Gooies!• Git Tower - http://git-tower.com M• Brother Bard’s GitX fork -Mac http://brotherbard.com/blog/2010/03/experimental-gitx-fork/ A C• Tortoise Git - http://code.google.com/p/tortoisegit/ WMac I N
  10. 10. Eclipse Integration• http://www.eclipse.org/egit/
  11. 11. Reference• Git - http://git-scm.com/• ProGit - http://progit.org/book/ - Scott Chacon• Insider Guide to Github - http://www.pragprog.com/screencasts/ 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• https://github.com/github/gitignore • 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. Github.com• Search it!• Forking• Pull Requests
  55. 55. Thank you!GitFor the Android DeveloperAnDevCon 2011 : Tony Hillerson

×