Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A Handful of Git Workflows for the Agilist

A Handful of Git Workflows for the Agilist

Less about agility and more of a visual introduction to Git and what it's doing when you collaborate with others via Git.

Steven Harman

May 27, 2010
Tweet

More Decks by Steven Harman

Other Decks in Technology

Transcript

  1. a handful of Git workflows for the agilist steven harman

    twitter: stevenharman http://stevenharman.net
  2. stop worrying and start loving The Git. git is awesome

    - if you’re using it, you know. if not, don’t be scared, give it a try.
  3. remote Git repository (origin) master let’s assume there already exists

    a Git repository somewhere in the cloud. like maybe... The GitHub.
  4. remote Git repository (origin) master local Git repository (your clone)

    master origin/master :> git clone [email protected]:stevenharman/foo.git :> cd foo :master> start by cloning a copy of that remote repository (conventionally known as “origin”) to our local machine.
  5. remote Git repository (origin) master local Git repository (your clone)

    master origin/master local Git repository (your clone) master feature origin/master :master> git checkout -b feature :feature> [... hackity-hack-hack ...] :feature> git commit -am ‘did something awesome.’ 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]
  6. remote Git repository (origin) master local Git repository (your clone)

    master origin/master local Git repository (your clone) master feature origin/master remote Git repository (origin) master // someone else pushed a change to the remote. a teammate, or maybe even another you, has pushed some new changes.
  7. remote Git repository (origin) master local Git repository (your clone)

    master origin/master local Git repository (your clone) master feature origin/master remote Git repository (origin) master local Git repository (your clone) master feature origin/master :feature> [... more hackity-hack-hack ...] :feature> git commit -am ‘more awesomeness. bacon!’ [still continuing steps 2 & 3 from earlier]
  8. remote Git repository (origin) master local Git repository (your clone)

    master origin/master local Git repository (your clone) master feature origin/master remote Git repository (origin) master local Git repository (your clone) master feature origin/master local Git repository (your clone) master origin/master feature :feature> git fetch origin get any new changes that are on the remote, but not local.
  9. remote Git repository (origin) master local Git repository (your clone)

    master origin/master local Git repository (your clone) master feature origin/master remote Git repository (origin) master local Git repository (your clone) master feature origin/master local Git repository (your clone) master origin/master feature local Git repository (your clone) master feature origin/master :feature> git checkout master :master> git merge origin/master 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.
  10. remote Git repository (origin) master local Git repository (your clone)

    master origin/master local Git repository (your clone) master feature origin/master remote Git repository (origin) master local Git repository (your clone) master feature origin/master local Git repository (your clone) master origin/master feature local Git repository (your clone) master feature origin/master local Git repository (your clone) master feature origin/master :master> git merge feature now we need to merge our feature into “master” so we can release it. option 1) merge feature in. [keeps all info, but we end up with a noisy history graph that’s hard to follow]
  11. remote Git repository (origin) master local Git repository (your clone)

    master origin/master local Git repository (your clone) master feature origin/master remote Git repository (origin) master local Git repository (your clone) master feature origin/master local Git repository (your clone) master origin/master feature local Git repository (your clone) master feature origin/master OR [go back to just after we merged in the fetched changes]
  12. remote Git repository (origin) master local Git repository (your clone)

    master origin/master local Git repository (your clone) master feature origin/master remote Git repository (origin) master local Git repository (your clone) master feature origin/master local Git repository (your clone) master origin/master feature local Git repository (your clone) master feature origin/master local Git repository (your clone) master feature origin/master local Git repository (your clone) master feature origin/master :master> git checkout feature :feature> git rebase master option 2) rebase our “feature” branch on top of “master”. this “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.
  13. remote Git repository (origin) master local Git repository (your clone)

    master origin/master local Git repository (your clone) master feature origin/master remote Git repository (origin) master local Git repository (your clone) master feature origin/master local Git repository (your clone) master origin/master feature local Git repository (your clone) master feature origin/master local Git repository (your clone) master feature origin/master local Git repository (your clone) master feature origin/master local Git repository (your clone) master feature origin/master :feature> git checkout master :master> git merge feature 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”.
  14. remote Git repository (origin) master local Git repository (your clone)

    master origin/master local Git repository (your clone) master feature origin/master remote Git repository (origin) master local Git repository (your clone) master feature origin/master local Git repository (your clone) master origin/master feature local Git repository (your clone) master feature origin/master local Git repository (your clone) master feature origin/master local Git repository (your clone) master feature origin/master local Git repository (your clone) master feature origin/master remote Git repository (origin) master local Git repository (your clone) master feature origin/master :master> git push origin master finally we share our sweet, sweet bacon with the rest of the world by pushing our local changes to the remote (origin).
  15. remote Git repository (origin) master local Git repository (your clone)

    master origin/master local Git repository (your clone) master feature origin/master remote Git repository (origin) master local Git repository (your clone) master feature origin/master local Git repository (your clone) master origin/master feature local Git repository (your clone) master feature origin/master local Git repository (your clone) master feature origin/master local Git repository (your clone) master feature origin/master local Git repository (your clone) master feature origin/master remote Git repository (origin) master local Git repository (your clone) master feature origin/master remote Git repository (origin) master local Git repository (your clone) master origin/master :master> git branch -d feature now everyone can enjoy the bacony-goodness!
  16. 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)
  17. some cool tools for your Git utility belt • git

    reset • git cherry-pick • git stash • git bisect • git add -p • git reflog • git svn add -p to interactively stage hunks of a file change.
  18. 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