Your SlideShare is downloading. ×
0
GIT BASICS
                 Ariejan de Vroom – Kabisa ICT




http://kabisa.nl
http://ariejan.net
http://twitter.com/ariej...
WHAT THE GIT?!

“I'm an egotistical bastard, and I name all my projects after
       myself. First Linux, now git.” – Linu...
GET GIT!
http://git-scm.com/
SURVEY

• Who is NOT using version control?
• Subversion? Mercurial?
• Anything else?
WHY GIT?!
• Distributed Repositories
• Non-linear Development
• Very fast branching and merging
• Toolkit Design
• Scales
...
LET’S ROCK!

~/gitbasics $ git init
Initialized empty Git repository
in /Users/ariejan/gitbasics/.git/
LET’S ROLL!

~/gitbasics $ git clone
git@github.com/ariejan/gitbasics.git
~/gitbasics $ echo "Live long and prosper" > README
~/gitbasics $ git add README
~/gitbasics $ git commit -m "Added README...
WHAT JUST HAPPENED?

~/gitbasics $ git log

commit 8e60b09d3082e9473944075cc01b3b67bb97d5c3
Author: Ariejan de Vroom <arie...
HOW GIT WORKS
    Working Directory

              git add


      Staging Area

              git commit


      Reposito...
WORKFLOW

• Hack! ( TextMate, vim, ... )
• Stage your changes ( git add )
• Review your changes ( git status | diff )
• Co...
USING BRANCHES

• Very, very fast
• Keep different code paths separate
• Try new things
• Atomic merges!
SURVEY

• How many of you use branching?
• Do you work exclusively on trunk/master?
• NEVER work on trunk/master?
BRANCHING

c1   c2   c3   c4   master




          c5   c6   new_feature
LET’S BRANCH!
~/gitbasics $ git checkout -b new_feature
Switched to a new branch "new_feature"

~/gitbasics $ git branch
 ...
MERGING

• Merge two branches together
• Add new features
• Add bugs fixes
MERGING

c1   c2    c3   c4   c7   master




           c5   c6        new_feature
MERGING

~/gitbasics $ git checkout master
Switched to branch "master"

~/gitbasics $ git merge new_feature
REBASING

• Bring a branch up-to-date
• Rebasing is rewriting history!
• Don’t use rebasing on a branch you’re
  sharing!
REBASING

c1       c2    c3    c4    master




new_feature    c3’   c4’      c5    c6
REBASING

~/gitbasics $ git checkout new_feature
Switched to branch "new_feature"

~/gitbasics $ git rebase master
REMOTE

• Store and share your code!
 • github.com
 • gitosis ( self-managed over SSH )
PUSH

~/gitbasics $ git add origin git@github.com/ariejan/
gitbasics.git

~/gitbasics $ git push origin master
FETCH / PULL


~/gitbasics $ git fetch origin

~/gitbasics $ git pull origin master
WORKFLOW
             Working Directory

add


                Staging Area

 commit                   checkout   merge


...
TAGGING


• Mark a point in history
• Optionally sign it cryptographically with
  GnuPG
TAGGING
      v1.0




c1    c2     c3   c4
TAGGING

~/gitbasics $ git tag -a -m "Tag v1.0" v1.0
Switched to branch "new_feature"

~/gitbasics $ git tag
v1.0

~/gitba...
USING TAGS

~/gitbasics $ git checkout -b fix_1.0 v1.0
Switched to branch "fix_1.0"

~/gitbasics $ git rebase v1.0

~/gitb...
TAGS @ GITHUB
BISECTING


• Binary search for a bad commit
• Find out where it when wrong (and who to
  blame!)
BISECTING

     v1.0        Good or Bad?        HEAD



c1   c2     c3   c4        c5   c6    c7
BISECTING
                      Good or
       v1.0                                HEAD
                       Bad?


 c1 ...
RELEASE
    MANAGEMENT

• Manage your DTSP environments
• Branches to the rescue!
RELEASE
             MANAGEMENT

~/gitbasics $ git branch production master

~/gitbasics $ git push origin production

~/g...
RELEASE
             MANAGEMENT

~/gitbasics $ git checkout production

~/gitbasics $ git rebase master

~/gitbasics $ git...
TAGGING RELEASES

~/gitbasics $ git checkout master

~/gitbasics $ git tag -a -m "Tag v1.0.3" v1.0.3
~/gitbasics $ git pus...
THE STASH


• Stash away uncommitted changes
• Ideal for quick bug fixes!
THE STASH
~/gitbasics $ git status
#	 modified:   README

~/gitbasics $ git stash
~/gitbasics $ git status
nothing to comm...
GITHUB.COM

• Share your code!
• Hardcore forking action!
• Crowd Sourcing
NETWORK
NETWORK
FORKQUEUE
PULL REQUESTS


~/imdb $ git add -f boscomonkey 
git://github.com/boscomonkey/imdb.git
~/imdb $ git checkout -b boscomonke...
SURVEY


• Who is going to try Git?
• Stick with Subversion?
WE’RE HIRING!
  AWESOME CODERS


  recruitment@kabisa.nl
THANKS!
Slides will be posted to http://slideshare.net/ariejan
          Contact me at ariejan@kabisa.nl
     or follow me...
Git Basics at Rails Underground
Upcoming SlideShare
Loading in...5
×

Git Basics at Rails Underground

3,312

Published on

My Git Basics presentation at Rails Underground.

Published in: Technology
1 Comment
10 Likes
Statistics
Notes
No Downloads
Views
Total Views
3,312
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
123
Comments
1
Likes
10
Embeds 0
No embeds

No notes for slide

Transcript of "Git Basics at Rails Underground"

  1. 1. GIT BASICS Ariejan de Vroom – Kabisa ICT http://kabisa.nl http://ariejan.net http://twitter.com/ariejan
  2. 2. WHAT THE GIT?! “I'm an egotistical bastard, and I name all my projects after myself. First Linux, now git.” – Linus Torvalds
  3. 3. GET GIT! http://git-scm.com/
  4. 4. SURVEY • Who is NOT using version control? • Subversion? Mercurial? • Anything else?
  5. 5. WHY GIT?! • Distributed Repositories • Non-linear Development • Very fast branching and merging • Toolkit Design • Scales • Cryptographic authentication of history.
  6. 6. LET’S ROCK! ~/gitbasics $ git init Initialized empty Git repository in /Users/ariejan/gitbasics/.git/
  7. 7. LET’S ROLL! ~/gitbasics $ git clone git@github.com/ariejan/gitbasics.git
  8. 8. ~/gitbasics $ echo "Live long and prosper" > README ~/gitbasics $ git add README ~/gitbasics $ git commit -m "Added README" [master (root-commit)]: created 8e60b09: "Added README" 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 README
  9. 9. WHAT JUST HAPPENED? ~/gitbasics $ git log commit 8e60b09d3082e9473944075cc01b3b67bb97d5c3 Author: Ariejan de Vroom <ariejan@ariejan.net> Date: Mon May 11 21:51:24 2009 +0200 Added README
  10. 10. HOW GIT WORKS Working Directory git add Staging Area git commit Repository
  11. 11. WORKFLOW • Hack! ( TextMate, vim, ... ) • Stage your changes ( git add ) • Review your changes ( git status | diff ) • Commit (locally) ( git commit ) • Repeat
  12. 12. USING BRANCHES • Very, very fast • Keep different code paths separate • Try new things • Atomic merges!
  13. 13. SURVEY • How many of you use branching? • Do you work exclusively on trunk/master? • NEVER work on trunk/master?
  14. 14. BRANCHING c1 c2 c3 c4 master c5 c6 new_feature
  15. 15. LET’S BRANCH! ~/gitbasics $ git checkout -b new_feature Switched to a new branch "new_feature" ~/gitbasics $ git branch master * new_feature ~/gitbasics $ git checkout master Switched to branch "master" ~/gitbasics $ git branch -d feature3 Deleted branch feature3
  16. 16. MERGING • Merge two branches together • Add new features • Add bugs fixes
  17. 17. MERGING c1 c2 c3 c4 c7 master c5 c6 new_feature
  18. 18. MERGING ~/gitbasics $ git checkout master Switched to branch "master" ~/gitbasics $ git merge new_feature
  19. 19. REBASING • Bring a branch up-to-date • Rebasing is rewriting history! • Don’t use rebasing on a branch you’re sharing!
  20. 20. REBASING c1 c2 c3 c4 master new_feature c3’ c4’ c5 c6
  21. 21. REBASING ~/gitbasics $ git checkout new_feature Switched to branch "new_feature" ~/gitbasics $ git rebase master
  22. 22. REMOTE • Store and share your code! • github.com • gitosis ( self-managed over SSH )
  23. 23. PUSH ~/gitbasics $ git add origin git@github.com/ariejan/ gitbasics.git ~/gitbasics $ git push origin master
  24. 24. FETCH / PULL ~/gitbasics $ git fetch origin ~/gitbasics $ git pull origin master
  25. 25. WORKFLOW Working Directory add Staging Area commit checkout merge Repository push fetch pull Remote
  26. 26. TAGGING • Mark a point in history • Optionally sign it cryptographically with GnuPG
  27. 27. TAGGING v1.0 c1 c2 c3 c4
  28. 28. TAGGING ~/gitbasics $ git tag -a -m "Tag v1.0" v1.0 Switched to branch "new_feature" ~/gitbasics $ git tag v1.0 ~/gitbasics $ git push --tags
  29. 29. USING TAGS ~/gitbasics $ git checkout -b fix_1.0 v1.0 Switched to branch "fix_1.0" ~/gitbasics $ git rebase v1.0 ~/gitbasics $ git log v1.0..HEAD
  30. 30. TAGS @ GITHUB
  31. 31. BISECTING • Binary search for a bad commit • Find out where it when wrong (and who to blame!)
  32. 32. BISECTING v1.0 Good or Bad? HEAD c1 c2 c3 c4 c5 c6 c7
  33. 33. BISECTING Good or v1.0 HEAD Bad? c1 c2 c3 c4 c5 c6 c7 ~/gitbasics $ git bisect start ~/gitbasics $ git bisect bad ~/gitbasics $ git bisect good v1.0 ~/gitbasics $ git bisect bad | good ~/gitbasics $ git bisect reset ~/gitbasics $ git bisect start HEAD v1.0
  34. 34. RELEASE MANAGEMENT • Manage your DTSP environments • Branches to the rescue!
  35. 35. RELEASE MANAGEMENT ~/gitbasics $ git branch production master ~/gitbasics $ git push origin production ~/gitbasics $ git checkout --track -b production origin/production
  36. 36. RELEASE MANAGEMENT ~/gitbasics $ git checkout production ~/gitbasics $ git rebase master ~/gitbasics $ git push origin production
  37. 37. TAGGING RELEASES ~/gitbasics $ git checkout master ~/gitbasics $ git tag -a -m "Tag v1.0.3" v1.0.3 ~/gitbasics $ git push --tags ~/gitbasics $ git checkout production ~/gitbasics $ git rebase v1.0.3 ~/gitbasics $ git push origin production
  38. 38. THE STASH • Stash away uncommitted changes • Ideal for quick bug fixes!
  39. 39. THE STASH ~/gitbasics $ git status # modified: README ~/gitbasics $ git stash ~/gitbasics $ git status nothing to commit # Hack, stage, review, commit, etc. ~/gitbasics $ git stash pop ~/gitbasics $ git status # modified: README
  40. 40. GITHUB.COM • Share your code! • Hardcore forking action! • Crowd Sourcing
  41. 41. NETWORK
  42. 42. NETWORK
  43. 43. FORKQUEUE
  44. 44. PULL REQUESTS ~/imdb $ git add -f boscomonkey git://github.com/boscomonkey/imdb.git ~/imdb $ git checkout -b boscomonkey/master ~/imdb $ git pull boscomonkey master ~/imdb $ git checkout master ~/imdb $ git merge boscomonkey/master ~/imdb $ git push
  45. 45. SURVEY • Who is going to try Git? • Stick with Subversion?
  46. 46. WE’RE HIRING! AWESOME CODERS recruitment@kabisa.nl
  47. 47. THANKS! Slides will be posted to http://slideshare.net/ariejan Contact me at ariejan@kabisa.nl or follow me at http://twitter.com/ariejan
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×