a handful of Git
workflows for the
      agilist

        steven harman
    twitter: stevenharman
   http://stevenharman.net
stop worrying
   and start
loving The Git.
picture Git


image via: http://nvie.com/git-model
basic branch/feature
      workflow
remote Git repository (origin)




                   master
remote Git repository (origin)




                                    master




                local Git repository (your clone)


:> git clone git@github.com:stevenharman/foo.git
:> cd foo
:master>

                                   master    origin/master
remote Git repository (origin)




                                    master




                local Git repository (your clone)



:master> git checkout -b feature
:feature> [... hackity-hack-hack ...]
:feature> git commit -am ‘did something awesome.’

                  feature
                                   master    origin/master
remote Git repository (origin)



// someone else pushed a change to the remote.
                                    master

                                    master




                local Git repository (your clone)




                  feature
                                   master    origin/master
remote Git repository (origin)




                                    master

                                    master




                local Git repository (your clone)




:feature> [... more hackity-hack-hack ...]
:feature> git commit -am ‘more awesomeness. bacon!’

                  feature

                  feature
                                   master    origin/master
remote Git repository (origin)




                                    master

                                    master




                local Git repository (your clone)




:feature> git fetch origin

                  feature
                                    origin/master
                  feature
                                   master    origin/master
remote Git repository (origin)




                                    master

                                    master




                local Git repository (your clone)




:feature> git checkout master
:master> git merge origin/master

                  feature
                                   master     origin/master
                                    origin/master
                  feature
                                   master     origin/master
remote Git repository (origin)




                                    master

                                    master




                local Git repository (your clone)




:master> git merge feature
                                   master

                  feature
                                    origin/master
                                   master     origin/master
                                    origin/master
                  feature
                                   master     origin/master
remote Git repository (origin)




                    master

                    master




local Git repository (your clone)




  feature
                   master     origin/master
                    origin/master
  feature
                   master     origin/master
remote Git repository (origin)




                                    master

                                    master




                local Git repository (your clone)


:master> git checkout feature
:feature> git rebase master
                  feature
                                   master

                  feature
                                    origin/master
                                   master     origin/master
                                    origin/master
                  feature
                                   master     origin/master
remote Git repository (origin)




                                    master

                                    master




                local Git repository (your clone)


:feature> git checkout master
:master> git merge feature
                       feature
                  feature          master
                                   master

                  feature
                                    origin/master
                                    origin/master
                                   master     origin/master
                  feature
                                   master     origin/master
remote Git repository (origin)



                                    master




                                    master




                local Git repository (your clone)



:master> git push origin master

                       feature
                  feature          master     origin/master
                                   master

                  feature
                                    origin/master
                                    origin/master
                                   master     origin/master
                  feature
                                   master     origin/master
remote Git repository (origin)



                                    master




                                    master




                local Git repository (your clone)



:master> git branch -d feature

                       feature
                  feature          master     origin/master
                                   master

                  feature
                                    origin/master
                                    origin/master
                                   master     origin/master
                  feature
                                   master     origin/master
derivations

• branch for a spike
• branches for concurrent design
• push/pull changes directly from teammate
• stashing changes temporarily
• reset to prior commit (in case of FUBAR)
some cool tools for
    your Git utility belt
•   git reset
•   git cherry-pick
•   git stash
•   git bisect
•   git add -p
•   git reflog
•   git svn
get Git info

• http://ProGit.org (the site for THE book)
• http://gitready.com
• http://gitcasts.com
• http://whygitisbetterthanx.com/
• http://delicious.com/stevenharman/git
fork these slides from
http://github.com/stevenharman/git-workflows




                 steven harman
             twitter: stevenharman
            http://stevenharman.net

Git workflow

  • 1.
    a handful ofGit workflows for the agilist steven harman twitter: stevenharman http://stevenharman.net
  • 2.
    stop worrying and start loving The Git.
  • 3.
    picture Git image via:http://nvie.com/git-model
  • 4.
  • 5.
    remote Git repository(origin) master
  • 6.
    remote Git repository(origin) master local Git repository (your clone) :> git clone git@github.com:stevenharman/foo.git :> cd foo :master> master origin/master
  • 7.
    remote Git repository(origin) master local Git repository (your clone) :master> git checkout -b feature :feature> [... hackity-hack-hack ...] :feature> git commit -am ‘did something awesome.’ feature master origin/master
  • 8.
    remote Git repository(origin) // someone else pushed a change to the remote. master master local Git repository (your clone) feature master origin/master
  • 9.
    remote Git repository(origin) master master local Git repository (your clone) :feature> [... more hackity-hack-hack ...] :feature> git commit -am ‘more awesomeness. bacon!’ feature feature master origin/master
  • 10.
    remote Git repository(origin) master master local Git repository (your clone) :feature> git fetch origin feature origin/master feature master origin/master
  • 11.
    remote Git repository(origin) master master local Git repository (your clone) :feature> git checkout master :master> git merge origin/master feature master origin/master origin/master feature master origin/master
  • 12.
    remote Git repository(origin) master master local Git repository (your clone) :master> git merge feature master feature origin/master master origin/master origin/master feature master origin/master
  • 13.
    remote Git repository(origin) master master local Git repository (your clone) feature master origin/master origin/master feature master origin/master
  • 14.
    remote Git repository(origin) master master local Git repository (your clone) :master> git checkout feature :feature> git rebase master feature master feature origin/master master origin/master origin/master feature master origin/master
  • 15.
    remote Git repository(origin) master master local Git repository (your clone) :feature> git checkout master :master> git merge feature feature feature master master feature origin/master origin/master master origin/master feature master origin/master
  • 16.
    remote Git repository(origin) master master local Git repository (your clone) :master> git push origin master feature feature master origin/master master feature origin/master origin/master master origin/master feature master origin/master
  • 17.
    remote Git repository(origin) master master local Git repository (your clone) :master> git branch -d feature feature feature master origin/master master feature origin/master origin/master master origin/master feature master origin/master
  • 18.
    derivations • branch fora spike • branches for concurrent design • push/pull changes directly from teammate • stashing changes temporarily • reset to prior commit (in case of FUBAR)
  • 19.
    some cool toolsfor your Git utility belt • git reset • git cherry-pick • git stash • git bisect • git add -p • git reflog • git svn
  • 20.
    get Git info •http://ProGit.org (the site for THE book) • http://gitready.com • http://gitcasts.com • http://whygitisbetterthanx.com/ • http://delicious.com/stevenharman/git
  • 21.
    fork these slidesfrom http://github.com/stevenharman/git-workflows steven harman twitter: stevenharman http://stevenharman.net

Editor's Notes

  • #2 \n
  • #3 git is awesome - if you’re using it, you know. if not, don’t be scared, give it a try.\n
  • #4 don’t be scared, it’s not as bad as it looks.\n
  • #5 \n
  • #6 let’s assume there already exists a Git repository somewhere in the cloud. like maybe... The GitHub.\n
  • #7 start by cloning a copy of that remote repository (conventionally known as “origin”) to our local machine.\n
  • #8 we need to work a sweet new feature. step 1) create a local branch to work in. step 2) hackity-hack-hack. step 3) commit the changes. [repeat steps 2 & 3 as necessary]\n
  • #9 a teammate, or maybe even another you, has pushed some new changes.\n
  • #10 [still continuing steps 2 & 3 from earlier]\n
  • #11 get any new changes that are on the remote, but not local.\n
  • #12 merge the changes from the remote “master” branch into our local “master” branch. because there are no divergent changes on our local master, this is a “fast-forward merge” along the master’s graph.\n
  • #13 now we need to merge our feature into “master” so we can release it. \n\noption 1) merge feature in. [keeps all info, but we end up with a noisy history graph that’s hard to follow]\n
  • #14 OR [go back to just after we merged in the fetched changes]\n
  • #15 option 2) rebase our “feature” branch on top of “master”.\n\nthis “rewinds” our branch back to where it started, then “fast-forwards” along “master”, and finally re-applies each of our change sets. afterward, our local commits have a new SHA1 hash, meaning they are different objects than before rebase, however, the original committer info & meta-data are preserved.\n
  • #16  now we can merge our changes into “master.” because we already have all of the changes that exist in “master,” this results in a “fast-forward” merge onto “master”.\n
  • #17 finally we share our sweet, sweet bacon with the rest of the world by pushing our local changes to the remote (origin).\n
  • #18 now everyone can enjoy the bacony-goodness!\n
  • #19 \n
  • #20 add -p to interactively stage hunks of a file change.\n
  • #21 \n
  • #22 feel free to hit me up with any questions.\n