WordPress Websites for Engineers: Elevate Your Brand
SCM for Android Developers Using Git
1. Git
For the Android Developer
AnDevCon 2011 : Tony Hillerson
#AnDevCon #effectiveui
http://www.slideshare.net/thillerson/scm-for-android-developers-using-git
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:
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. 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. Getting Set Up on Mac
• Homebrew - http://mxcl.github.com/homebrew/
• MacPorts - http://www.macports.org/
7. Getting Set Up on Windows
• msysgit -http://code.google.com/p/msysgit/
• Cygwin - http://www.cygwin.com/
8. Getting Set Up on Linux
• apt, etc - you probably know the drill
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/ W
Mac
I
N
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
19. .gitignore
• Can be nested deeply
• https://github.com/github/gitignore
• 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
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
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_activity
master
Mac
fb4f5d9 c5083fa
add_login_activity
Mac
9aa8827 fe594ce ccb6f5e
43. Branching: Rebasing
master
Mac
fb4f5d9 c5083fa 3f43fa3
add_login_activity
before Mac
9aa8827 fe594ce ccb6f5e
master
Mac
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 commit
master with the changes
from fe594ce
Mac
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
49. Tagging
git tag -a -m"Tagging v1.0" v1.0 c5083fa
master
Mac
fb4f5d9 c5083fa 3f43fa3
• Both -v1.0 and c5083fa will point to c5083fa
• Push this tag with `git push --tags`
• Can be cryptologically signed
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