SlideShare a Scribd company logo
Git
For the Android Developer
AnDevCon 2011 : Tony Hillerson
#AnDevCon #effectiveui
http://www.slideshare.net/thillerson/scm-for-android-developers-using-git
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:
Preliminaries
Getting Git and Getting Set Up
What’s a Git?

 A completely ignorant, childish person with no manners.
                                                               - http://urbandictionary.com




                 Linus Torvalds
                 http://en.wikipedia.org/wiki/Linus_Torvalds
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
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 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
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://www.pragprog.com/screencasts/
   v-scgithub/insider-guide-to-github - Scott Chacon
Note
• Code may be in backticks: `git <command>`
  • Don’t input the backticks
The Command Line
A Short Sermon
Seven Use Cases
Where Git will Make your Life Easier
Project History
Git will Make your Life Easier
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
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
git               git
         or      clone
init


                 git                  86650c185eda50c9f9d58e2fbdf8b7113e5dee54
                         git commit
   changes       add

                 git
                         git commit   6facfd9f34173f4fb024196996e948a87c85eb56
   changes       add

                 git
                         git commit   b02ef5bf190e28ba24eab3ffab6133181cb5b5ef
   changes       add



       ...   ∞
Simple Workflow
.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 - 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)
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
Getting Out of Trouble
Git 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 <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
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` a file
• Oops! I just committed a bug
• USE ONLY BEFORE YOU SHARE CHANGES
git revert
• Commits the reverse of a commit
• The previous commit is still there
• != svn revert
Collaboration
Git 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”                  Committer




                           Committer




Star
• ssh://user@computer:path/to/repo.git
• http                           Peer

• Gitosis
• Gitolite
                     Peer                Peer




Peer to N Peers
Dictator      ... etc. Maintains a “blessed repository”




            Lieutenant                                                Lieutenant




Developer                Developer              Developer                                      Developer




Hierarchical (Linux model)
Topical Development
Git 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
• Make a new branch to spike something
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
Branching
                           git checkout -b add_login_activity




master


Mac
      fb4f5d9   c5083fa



                          add_login_activity


                          Mac

                                9aa8827        fe594ce    ccb6f5e
Branching: Merging

                                                git checkout master

                                                                      git merge add_login_activity

master


Mac                                                                     9aa8827        fe594ce       ccb6f5e
      fb4f5d9   c5083fa           3f43fa3




                      add_login_activity


                      Mac

                            9aa8827         fe594ce        ccb6f5e
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`
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`
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
Cherry Picking
• Doesn’t add a reference to the old commit
• Only applies the changes
• Future merges should apply cleanly
Release Management
Git will Make your Life Easier
Tagging
• tag
• push --tags
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
Bug Fixing
Git will Make your Life Easier
Bug Fixing
• blame
• bisect
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
Open Source Code
Git will Make your Life Easier
Github.com
• Search it!
• Forking
• Pull Requests
Thank you!




Git
For the Android Developer
AnDevCon 2011 : Tony Hillerson

More Related Content

What's hot (19)

PDF
Presentacion git
Ignacio Martín
 
ODP
Why You Should Be Using Git
Francisco Vieira
 
PDF
Git advanced
Peter Vandenabeele
 
PDF
Git essentials
Otto Kekäläinen
 
PDF
Starting with Git & GitHub
Nicolás Tourné
 
PPT
Open Source Collaboration With Git And Git Hub
Nick Quaranto
 
KEY
Git Magic: Versioning Files like a Boss
tmacwilliam
 
PPTX
GitBlit plugin for Gerrit Code Review
Luca Milanesio
 
PDF
Getting Started with Git
Rick Umali
 
PDF
沒有 GUI 的 Git
Chia Wei Tsai
 
KEY
Git Basics Philips
Ariejan de Vroom
 
PDF
Advanced Git
Sergiu-Ioan Ungur
 
PPTX
Git'in on Windows
Stacy Vicknair
 
PDF
01 git interview questions &amp; answers
DeepQuest Software
 
PDF
Git internals
Haggai Philip Zagury
 
PDF
Essential git for developers
Adam Culp
 
PDF
Introduction to git, an efficient distributed version control system
AlbanLevy
 
PPTX
Git'in in 15
Stacy Vicknair
 
Presentacion git
Ignacio Martín
 
Why You Should Be Using Git
Francisco Vieira
 
Git advanced
Peter Vandenabeele
 
Git essentials
Otto Kekäläinen
 
Starting with Git & GitHub
Nicolás Tourné
 
Open Source Collaboration With Git And Git Hub
Nick Quaranto
 
Git Magic: Versioning Files like a Boss
tmacwilliam
 
GitBlit plugin for Gerrit Code Review
Luca Milanesio
 
Getting Started with Git
Rick Umali
 
沒有 GUI 的 Git
Chia Wei Tsai
 
Git Basics Philips
Ariejan de Vroom
 
Advanced Git
Sergiu-Ioan Ungur
 
Git'in on Windows
Stacy Vicknair
 
01 git interview questions &amp; answers
DeepQuest Software
 
Git internals
Haggai Philip Zagury
 
Essential git for developers
Adam Culp
 
Introduction to git, an efficient distributed version control system
AlbanLevy
 
Git'in in 15
Stacy Vicknair
 

Viewers also liked (8)

PPTX
Evernote
Terri Orlowski
 
PDF
.Git for WordPress Developers
mpvanwinkle
 
PPTX
Essential git for developers
Aidan Casey
 
PPT
Introduction to Git for developers
Dmitry Guyvoronsky
 
PDF
[Easy] How to use Evernote: Beginner's Guide
Ana Uy
 
PDF
DATAS Technolody may2016 eng AK
Alexey Kononenko
 
PDF
Git for the Android Developer
EffectiveUI
 
PDF
Platform freelance ASP .NET / C#
Saâd Zerhouni
 
Evernote
Terri Orlowski
 
.Git for WordPress Developers
mpvanwinkle
 
Essential git for developers
Aidan Casey
 
Introduction to Git for developers
Dmitry Guyvoronsky
 
[Easy] How to use Evernote: Beginner's Guide
Ana Uy
 
DATAS Technolody may2016 eng AK
Alexey Kononenko
 
Git for the Android Developer
EffectiveUI
 
Platform freelance ASP .NET / C#
Saâd Zerhouni
 
Ad

Similar to Git for the Android Developer (20)

PDF
Git for Android Developers
Tony Hillerson
 
PPTX
Git One Day Training Notes
glen_a_smith
 
PPTX
Git reposirory descritiopn use this for demo p
shailesh patil
 
PDF
Introduction to Git, DrupalCamp LA 2015
mwrather
 
PDF
The Basics of Open Source Collaboration With Git and GitHub
BigBlueHat
 
PDF
Git and Github slides.pdf
Tilton2
 
PDF
Git and Github workshop ppt slide by slide
RaghavendraVattikuti1
 
PDF
Git简介
clvrobj
 
PPT
3 Git
Fabio Fumarola
 
PDF
Wokshop de Git
Alberto Leal
 
PDF
Introduction to Git
Colin Su
 
PDF
Git, GitHub and Open Source
Lorna Mitchell
 
PPT
Talk to git
YenTing Chen
 
PDF
Git-r-Done
Cesar Martinez
 
PDF
Git and Github workshop
Otto Kekäläinen
 
PPTX
Techoalien git
Aditya Tiwari
 
PPTX
Techoalien git
Aditya Tiwari
 
PPTX
Techoalien git
Aditya Tiwari
 
PPTX
simple Git
Caesar Chi
 
PDF
Git Started With Git
Nick Quaranto
 
Git for Android Developers
Tony Hillerson
 
Git One Day Training Notes
glen_a_smith
 
Git reposirory descritiopn use this for demo p
shailesh patil
 
Introduction to Git, DrupalCamp LA 2015
mwrather
 
The Basics of Open Source Collaboration With Git and GitHub
BigBlueHat
 
Git and Github slides.pdf
Tilton2
 
Git and Github workshop ppt slide by slide
RaghavendraVattikuti1
 
Git简介
clvrobj
 
Wokshop de Git
Alberto Leal
 
Introduction to Git
Colin Su
 
Git, GitHub and Open Source
Lorna Mitchell
 
Talk to git
YenTing Chen
 
Git-r-Done
Cesar Martinez
 
Git and Github workshop
Otto Kekäläinen
 
Techoalien git
Aditya Tiwari
 
Techoalien git
Aditya Tiwari
 
Techoalien git
Aditya Tiwari
 
simple Git
Caesar Chi
 
Git Started With Git
Nick Quaranto
 
Ad

More from Effective (20)

PDF
User Testing: Adapt to Fit Your Needs
Effective
 
PDF
Death of a Design: 5 Stages of Grief
Effective
 
PDF
UX Design Process 101: Where to start with UX
Effective
 
PDF
Give Them What They Want: Discovering Customer Need with Wearable Technology
Effective
 
PDF
Common Innovation Myths (World Usability Day)
Effective
 
PDF
Introduction to UX
Effective
 
PDF
2016 SXSW Measures for Justice Panel Picker Presentation
Effective
 
PDF
Water For People UX Awards Submission
Effective
 
PDF
Getting into the Game: How EA Put User Research into Practice
Effective
 
PPT
Scottrade and Understanding the Customer Journey: When Segmentation Isn’t Enough
Effective
 
PDF
A Blended Space for Heritage Storytelling
Effective
 
PPT
Using Behavioral Modeling to Engage Customers Throughout the Decision-Making ...
Effective
 
PDF
Mobile Website Design: Responsive, Adaptive or Both?
Effective
 
PDF
Integrated Thinking: The Answer to Enterprise IT’s Perpetual Struggle - Forre...
Effective
 
PPTX
Liferay and Water For People: From Data to Information
Effective
 
PDF
The Rules of UX - Enterprise 2.0
Effective
 
PPT
Making Mobile Meaningful NY 2013
Effective
 
PDF
Experience Driven Development - Future Insights Live 2013
Effective
 
PDF
SXSW 2013 Daily Recap - Sunday GoodxGlobal
Effective
 
PDF
The Human Interface: Making UX An Integral Part of Your Technology Buying Dec...
Effective
 
User Testing: Adapt to Fit Your Needs
Effective
 
Death of a Design: 5 Stages of Grief
Effective
 
UX Design Process 101: Where to start with UX
Effective
 
Give Them What They Want: Discovering Customer Need with Wearable Technology
Effective
 
Common Innovation Myths (World Usability Day)
Effective
 
Introduction to UX
Effective
 
2016 SXSW Measures for Justice Panel Picker Presentation
Effective
 
Water For People UX Awards Submission
Effective
 
Getting into the Game: How EA Put User Research into Practice
Effective
 
Scottrade and Understanding the Customer Journey: When Segmentation Isn’t Enough
Effective
 
A Blended Space for Heritage Storytelling
Effective
 
Using Behavioral Modeling to Engage Customers Throughout the Decision-Making ...
Effective
 
Mobile Website Design: Responsive, Adaptive or Both?
Effective
 
Integrated Thinking: The Answer to Enterprise IT’s Perpetual Struggle - Forre...
Effective
 
Liferay and Water For People: From Data to Information
Effective
 
The Rules of UX - Enterprise 2.0
Effective
 
Making Mobile Meaningful NY 2013
Effective
 
Experience Driven Development - Future Insights Live 2013
Effective
 
SXSW 2013 Daily Recap - Sunday GoodxGlobal
Effective
 
The Human Interface: Making UX An Integral Part of Your Technology Buying Dec...
Effective
 

Recently uploaded (20)

PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
July Patch Tuesday
Ivanti
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PDF
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Python basic programing language for automation
DanialHabibi2
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
July Patch Tuesday
Ivanti
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Python basic programing language for automation
DanialHabibi2
 

Git for the Android Developer

  • 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
  • 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. Note • Code may be in backticks: `git <command>` • Don’t input the backticks
  • 13. The Command Line A Short Sermon
  • 14. Seven Use Cases Where Git will Make your Life Easier
  • 15. Project History Git 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 clone init 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 • 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
  • 23. Getting Out of Trouble Git 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. Collaboration Git 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 Committer Star
  • 34. • ssh://user@computer:path/to/repo.git • http Peer • Gitosis • Gitolite Peer Peer Peer to N Peers
  • 35. Dictator ... etc. Maintains a “blessed repository” Lieutenant Lieutenant Developer Developer Developer Developer Hierarchical (Linux model)
  • 36. Topical Development Git 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_activity master Mac fb4f5d9 c5083fa add_login_activity Mac 9aa8827 fe594ce ccb6f5e
  • 42. Branching: Merging git checkout master git merge add_login_activity master Mac 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 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
  • 47. Release Management Git will Make your Life Easier
  • 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
  • 50. Bug Fixing Git will Make your Life Easier
  • 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 Code Git will Make your Life Easier
  • 54. Github.com • Search it! • Forking • Pull Requests
  • 55. Thank you! Git For the Android Developer AnDevCon 2011 : Tony Hillerson