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

Up to speed with Git

Kimmo Toro
September 30, 2011

Up to speed with Git

Short Git introduction followed up by few Git exercises.

Introduction will teach you what Git is, how does it compare to other version control systems and how Git helps you when you’re developing software with agile methods.

The exercises with Git help you in learning what’s in it for you.

After going through this presentation and the exercises you’ll be able to go full throttle with Git and get your colleagues (and bosses) convinced of the benefits of Git.

Kimmo Toro

September 30, 2011
Tweet

Other Decks in Programming

Transcript

  1. Up to speed with Git Some talk and some hands-on

    stuff as well Your host tonight: Kimmo Toro [email protected] This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
  2. Perform a diff, view history of any file, commit changes,

    merge branches, obtain any version of any file, create and switch branches, stash changes, create new repositories...
  3. 1. Get latest version of the codebase 2. Create a

    branch for fixing bug #128 3. Work for an hour 4. EMERGENCY! Quick, we need a hotfix for bug #256!!! 5. Checkout master branch 6. Create a branch for bug #256 7. Fix #256 8. Checkout master branch 9. Merge branch for bug #256 10. Push changes to central repo 11. Checkout branch for bug #128 and continue working
  4. 1. Get latest version of the codebase 2. Create a

    branch for fixing bug #128 3. Work for an hour 4. EMERGENCY! Quick, we need a hotfix for bug #256!!! 5. Checkout master branch 6. Create a branch for bug #256 7. Fix #256 8. Checkout master branch 9. Merge branch for bug #256 10. Push changes to central repo 11. Checkout branch for bug #128 and continue working
  5. 1. Get latest version of the codebase 2. Create a

    branch for fixing bug #128 3. Work for an hour 4. EMERGENCY! Quick, we need a hotfix for bug #256!!! 5. Checkout master branch 6. Create a branch for bug #256 7. Fix #256 8. Checkout master branch 9. Merge branch for bug #256 10. Push changes to central repo 11. Checkout branch for bug #128 and continue working Remote operation Remote operation
  6. Local workflow Working directory Index (Local) Repository git add STAGING

    git commit Stuff here is staged Sandbox / work in progress Committed stuff goes here
  7. Local workflow Working directory Index (Local) Repository git add STAGING

    git commit Stuff here is staged Sandbox / work in progress Committed stuff goes here git status shows status of working directory and stuff in index git log shows what has already been committed
  8. Git Configuration git config --global user.name "John Doe" git config

    --global user.email “[email protected]" git config --global color.ui auto
  9. First Exercise 1. Create a repository 2. Add two files

    in it 3. Check status 4. Commit 5. Check status 6. Check log
  10. Third Exercise 1. Again, do some modifications 2. Add modified

    stuff to index 3. See status - don’t commit yet! 4. Modify same file(s) again 5. See status 6. Commit
  11. Local workflow Working directory Index (Local) Repository git add STAGING

    git commit Stuff here is staged Sandbox / work in progress Committed stuff goes here git status shows status of working directory and stuff in index git log shows what has already been committed
  12. Git Takes Snapshots When you stage something, Git takes a

    snapshot and stores it to the index.
  13. Precious Tip #2 You can store your favorite git commands

    as handy aliases Windows: git config --global alias.lg "log --pretty=format:'%%h - %%an, %%ar : %%s'“ Linux: git config --add --global alias.lg "log --pretty=format:'%h - %an, %ar : %s'"
  14. Exercise #6 1. Launch gitk 2. Do some work on

    your git repository (modify, add, commit etc.) 3. Hit F5 after changes to refresh gitk UI 4. Try to understand what it is showing to you
  15. #7 Branching 1. Create a new branch and switch to

    that 2. Add some new files and commit them in the branch 3. Check gitk once and a while
  16. Merging (that’ll be #8) 1. Merge your previously created branch

    to master 2. What happened? 3. What does gitk show? 4. What does git log show? 5. Delete unneeded branch
  17. Stashing (Nine) 1. Do some changes (where ever) 2. Stash

    your changes aside 3. Do some other changes, commit 4. Get your stashed changes back
  18. Rebasing (ten already?) 1. Create yet another branch, switch to

    it 2. Do some changes, commit 3. Switch to master, do some changes, commit 4. See gitk
  19. Rebasing (#10) 5. Merge changes from the branch to master

    6. What happened? 7. What does gitk show? 8. What does git log show? 9. Again, delete unneeded branch
  20. Still Rebasing (X) 10.Create a branch, switch to it 11.Do

    changes, commit 12.Switch to master, do changes, commit 13.Checkout branch 14.Rebase master to branch
  21. Rebasing ‘til it hurts 15.Check what gitk shows 16.See git

    log 17.Checkout master and merge your branch there 18.See gitk and git log
  22. Merge A B C E D F G H topic

    master Merge C + H I As a result we have a new commit (I) which has two parents (C and H)
  23. Rebase 3 A’ B’ C’ E D F G H

    topic master F G H As a result we have new commits(F-H) from master now in our topic branch
  24. Merge after Rebase A’ B’ C’ E D F G

    H topic master F G H As a result Git actually just moves the pointer for master to point to last commit in topic. There are no additional commits made. A’ B’ C’
  25. More stuff (and no time) • Cloning a repository •

    Pull vs. Fetch and Merge • Pushing changes upstream • Creating and tracking remote branches • Interactive rebasing • Git reset