Your SlideShare is downloading. ×
0
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
How to use git without rage
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

How to use git without rage

6,574

Published on

0 Comments
13 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,574
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
157
Comments
0
Likes
13
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Xx de enero de 2010 Use git without rage
  • 2. “VCS should be a subject in informatics” Heared about VCS
  • 3. “ We use VCS as if we were trained monkeys” Heared about VCS
  • 4. Types of VCS LVCS (Localized VCS) CVCS (Centralized VCS) DVCS (Distributed VCS)
  • 5. LVCS <ul><li>cp -r project projectB
  • 6. rcs (mac os) </li></ul>
  • 7. CVCS (Centralized VCS) <ul><li>SVN
  • 8. CVS </li></ul>
  • 9. DVCS (Distributed VCS) <ul><li>Git
  • 10. Mercurial </li></ul>
  • 11. Git Basics
  • 12. First-time git setup <ul><li>Three places </li><ul><li>System: git config --system (/etc/gitconfig)
  • 13. Global: git config --global (~/.gitconfig)
  • 14. Local: git config (cwd) </li></ul><li>git config [--system | --local] property value
  • 15. git config --global user.name 'wadus' </li></ul>
  • 16. Git Basics
  • 17. File status cycle untracked staged modified unmodified git add edit git add git commit git commit -a
  • 18. Workflows <ul>Scenario 1: Creating a repository from the beginnig and working with it (with no rage) </ul>
  • 19. Scenario 1: creating the repository <ul>git init (from directory project) Pffffff... this was hard!!!! </ul>
  • 20. Workflows -Scenario 1: edit some files <ul>Edit and/or create some files for your project this is what developing is about in last term, isn't it? </ul>
  • 21. Workflows -Scenario 1: commiting changes <ul>So, now you want to commit changes, but first... some advices for those who are used to working with CSCVs such as svn or cvs 100.times do <ul>puts “I will think in local terms, 'cos I am not working with remotes (yet)” </ul>end </ul>
  • 22. Workflows - Scenario 1: adding files to the staging area <ul>git status git add <file> -> add files to staging area (either new or modified files) Wow!!! I could not have imagined it!!!! </ul>
  • 23. Workflows – Scenario 1: Removing files from the staging area <ul>Damn it!!! I staged some files I didn't have to git reset HEAD <file> Phewwww!!!! </ul>
  • 24. Workflows – Scenario 1: What am I about to commit? <ul>Ok, I want to commit my changes, but which files I am about to commit? git status git diff (for unstaged files) git diff --cached (for staged files) </ul>
  • 25. Workflows – Scenario 1: Let's commit!!! <ul>git commit -> it will commit all the files in staging area git commit <filename> -> it will commit named files git commit -a -> it will commit all modified files skipping the staging area for those which are not staged </ul>
  • 26. Workflows – Scenario 1: deleting files <ul>rm <filename> removes file manually git rm <filename> stages deletion <ul>...or... </ul>git rm <filename> will do both things </ul>
  • 27. Workflows – Scenario 1: undeleting files <ul>git status will give you clues if deletion is in the staging area <ul>git reset HEAD <filename> </ul>if deletion is not in the staging area <ul>git checkout <filename> </ul></ul>
  • 28. Workflows – Scenario 1: moving files <ul>mv filename filename2 git rm filename git add filename2 <ul>...or... </ul>git mv filename filename2 </ul>
  • 29. Workfows- Scenario 1: undoing things <ul>git commit --amend will modify last commit <ul>git commit “ OMG, WTF, damn it!!! I forgot to add a file” git add damned_file git commit --ammend “ commit --amend FTW!!!” </ul></ul>
  • 30. Workfows- Scenario 1: undoing things (ii) <ul>Unstaging a staged file <ul>git reset HEAD filename </ul>Unmodify a modified and unstaged file <ul>git checkout filename </ul></ul>
  • 31. Workflows <ul>Scenario 2: working with remotes </ul>
  • 32. Workfows- Scenario 2: adding a remote <ul>So I want to work with another repo... git remote add [shortname] [url] git remote add origin your_url Now I finally understand what I've been doing with github all this time!!! </ul>
  • 33. Workfows- Scenario 2: showing your remotes <ul>If you want to know which repos you are working with: git remote git remote -v </ul>
  • 34. Workfows- Scenario 2: fetching and pulling <ul>To get data from your remotes git fetch [remote-name] git pull [remote-name] fetch or pull??? pull = fetch + merge </ul>
  • 35. Workfows- Scenario 2: pushing <ul>If you want to share your data: git push [remote-name] [branch] </ul>
  • 36. Workfows- Scenario 2: inspecting a remote <ul>git remote show [remote-name] Look at the “Local ref configured for git push” Local refs configured for 'git push': <ul>master pushes to master (local out of date) test pushes to test (up to date) </ul></ul>
  • 37. Workfows- Scenario 2: removing and renaming remotes <ul>git remote rename [original-name] [new-name] git remote rm [remote-name] This changes take effect on your LOCAL repo (remember: local, local, local) </ul>
  • 38. Workflows <ul>Scenario 3: tagging </ul>
  • 39. Workfows- Scenario 3: listing tags <ul>git tag </ul>
  • 40. Workfows- Scenario 3: tag types <ul>2 types of tags: lightweight and annotated Lightweight: It is like a branch that doesn't change, a pointer to a specific commit Annotated: These are stored as full objects. Checksumed and metadata are included </ul>
  • 41. Workfows- Scenario 3: Creating and showing tags <ul>Annotated: <ul>git tag -a [tag] </ul>Lightweight: <ul>git tag [tag] </ul>git show [tag] </ul>
  • 42. Workfows- Scenario 3: Creating tags later <ul>git tag -a <tag> <(part of) checksum of the commit> </ul>
  • 43. Workfows- Scenario 3: Sharing tags <ul>When pushing, you do not share tags git push origin [tagname] Hey! This is like sharing branches... git push origin --tags shares all the tags </ul>
  • 44. Branching: the beginning of magic Please, keep on thinking in local... or I will send @pacoguzman to kill you!!!
  • 45. Branching: the beginning of magic <ul>Let's do some review... git add README test.rb LICENSE git commit -m 'initial commit of my project' How is this commit stored? </ul>
  • 46. Branching: the beginning of magic taken from http://progit.org/
  • 47. Branching: the beginning of magic <ul>Let's assume we keep on doing some commits </ul>
  • 48. Branching: the beginning of magic taken from http://progit.org/
  • 49. Branching: the beginning of magic <ul>I thought we were going to talk about branches, you son of the bit!!! </ul>
  • 50. Branching: the beginning of magic <ul>I thought we were going to talk about branches, you son of the bit !!! </ul>A very bad geek joke
  • 51. Branching: the beginning of magic <ul>Branch: A movable pointer to one of these commits. Do you smell it??? Yeah! And it seems that it's going to taste even better! </ul>
  • 52. Branching: the beginning of magic taken from http://progit.org/
  • 53. Branching: the beginning of magic <ul>So... let's imagine we want to make a new branch: git branch testing </ul>
  • 54. Branching: the beginning of magic taken from http://progit.org/
  • 55. Branching: the beginning of magic <ul>Hey! But somehow I have to know wich branch I am at, aren't I??? </ul>
  • 56. Branching: the beginning of magic taken from http://progit.org/
  • 57. Branching: the beginning of magic <ul>git checkout testing </ul>
  • 58. Branching: the beginning of magic taken from http://progit.org/
  • 59. Branching: the beginning of magic <ul>Very pretty... but... how the hell is this supposed to be useful??? </ul>
  • 60. Branching: the beginning of magic <ul>touch newfile.txt git commit -a -m 'new file' </ul>
  • 61. Branching: the beginning of magic taken from http://progit.org/
  • 62. Branching: the beginning of magic <ul>git checkout master </ul>
  • 63. Branching: the beginning of magic taken from http://progit.org/
  • 64. Branching: the beginning of magic <ul>touch another_file.txt git commit -a -m 'another new file in master branch' </ul>
  • 65. Branching: the beginning of magic taken from http://progit.org/
  • 66. Workflows <ul>Scenario 4: working with branches </ul>
  • 67. Scenario 4: Context <ul>You are working on a new story, comfortably and peacefully when suddenly you receive a call – OMG! and you are told that it is urgent - but surely not important - to fix some bug in the application (e.g: to change some text which only appears in that last screen of your app) </ul>
  • 68. Scenario 4: steps resume <ul><li>Create a branch for the new story you are going to work on
  • 69. Do some work on that branch
  • 70. Swear after you receive that f*ck*ng damned call
  • 71. Commit or stash all the changes that you haven't saved yet – if you want to -
  • 72. Checkout your production (usually master) branch
  • 73. Create a branch to add the hotfix
  • 74. Fix that so f*ck*ng urgent issue
  • 75. Merge this branch and push it to production
  • 76. Switch back to your original story and continue working on it </li></ul>
  • 77. Scenario 4: the process <ul>git checkout master -b issue_1 </ul>C1 C3 C2 master * issue_1
  • 78. Scenario 4: the process <ul>make some changes and commit them </ul>C1 C3 C2 master * issue_1 C4
  • 79. Scenario 4: the process <ul>Create a new branch from master for that hotfix git checkout master -b hotfix </ul>C1 C3 C2 master issue_1 C4 * hotfix
  • 80. Scenario 4: the process <ul>Fix the problem and commit changes </ul>C1 C3 C2 master issue_1 C4 * hotfix C5
  • 81. Scenario 4: fast forward merge <ul>Merge hotfix into master git checkout master git merge hotfix </ul>C1 C3 C2 * master issue_1 C4 hotfix C5
  • 82. Scenario 4: fast forward merge <ul>What kind of merge is this!!! You have done nothing but moving forward master pointer </ul>C1 C3 C2 * master issue_1 C4 hotfix C5
  • 83. Scenario 4: the process <ul>End issue_1 and commit changes </ul>C1 C3 C2 * master issue_1 C4 hotfix C5 C6
  • 84. Scenario 4: three way merge <ul>Merge changes git checkout master git merge issue_1 </ul>C3 issue_1 C4 hotfix C5 C6 * master
  • 85. Scenario 4: three way merge <ul>Merge changes git checkout master git merge issue_1 </ul>C3 * master issue_1 C4 hotfix C5 C6 C7
  • 86. Scenario 4: merge conflicts <ul>If there are merge conflicts you have to solve them manually. Once you have resolved them, you can set these files as merged with git add <filename> git commit </ul>
  • 87. Scenario 4: branch management <ul>git branch lists branches git branch -v lists branches with their last commit git branch --merged lists merged branches git branch --no-merged lists unmerged branches git branch -d <branchname> deletes merged branch (-D for unmerged branches) </ul>
  • 88. Branching workflows
  • 89. Branching workflows: long running branches taken from http://progit.org/
  • 90. Branching workflows: topic branches taken from http://progit.org/
  • 91. Branching workflows: topic branches <ul>Merge iss91v2 and dumbidea </ul>taken from http://progit.org/
  • 92. Remote branches <ul>References to the state of branches on your remote repos They are local branches which you can not move. They are moved automatically whenever you do any network communication </ul>
  • 93. Pushing branches <ul>git push <remote> <branch> [:server_branch_name] git push origin my_local_branch:server_branch </ul>
  • 94. Deleting remote branches <ul>git push origin :branch_to_be_deleted It's like git push origin (nothing):branch_to_be_deleted </ul>
  • 95. Tracking branches <ul>Checking out a remote branch, will create a tracking branch. With tracking branches you can call <ul>git push git pull </ul>without remote or branches names When you clone a repo, a local branch “master” is created, which tracks origin/master </ul>
  • 96. Rebasing
  • 97. Basic rebasing vs merge <ul>This is what we already know git merge experiment </ul>taken from http://progit.org/
  • 98. Basic rebasing vs merge <ul>And this is rebasing git rebase master experiment or... git checkout experiment git rebase master </ul>
  • 99. Basic rebasing vs merge taken from http://progit.org/
  • 100. Basic rebasing vs merge <ul>It gets the diffs introduced by each commit of the branch you're on. It saves those diffs to temporary files It resets the current branch to the common ancestor with the branch you are rebasing onto It applies these changes and creates a new commit </ul>
  • 101. Basic rebasing vs merge <ul>Now, you can do a fast forward merge </ul>taken from http://progit.org/
  • 102. Rebasing onto other branches taken from http://progit.org/
  • 103. Rebasing onto other branches <ul>git rebase --onto master server client </ul>taken from http://progit.org/
  • 104. Rebasing onto other branches <ul>git checkout master git merge client </ul>taken from http://progit.org/
  • 105. Rebasing onto other branches <ul>git rebase master server </ul>taken from http://progit.org/
  • 106. Rebasing or not rebasing? <ul>Be very careful when rebasing commits published in a public repository... …you could be killed by other developers </ul>
  • 107. Rebasing or not rebasing? taken from http://progit.org/
  • 108. Rebasing or not rebasing? <ul>Fetch changes in remote repo </ul>taken from http://progit.org/
  • 109. Rebasing or not rebasing? <ul>Someone rebased changes (C4 – C6) </ul>taken from http://progit.org/
  • 110. Rebasing or not rebasing? <ul>C4 and C4' introduce the same changes </ul>taken from http://progit.org/
  • 111. DISTRIBUTED WORKFLOWS
  • 112. Centralized workflow (small teams) taken from http://progit.org/
  • 113. Integration manager workflow (github) taken from http://progit.org/
  • 114. Dictator Lieutenant Workflow (linux kernel) taken from http://progit.org/
  • 115. Tricks & Tips
  • 116. Stashing <ul>If you're working on some feature and suddenly you are forced to work on a hotfix, what do you do with changes in code you don't want to commit? The answer is Stash </ul>
  • 117. Stashing (i) <ul>git stash [save 'message'] saves changes <ul>Note: if you have untracked files, these won't be stashed </ul>git stash list </ul>
  • 118. Stashing (ii) <ul>git stash apply [stash_id] applies stash git stash drop [stash_id] deletes stash git stash pop [stash_id] applies + deletes git stash show [stash_id] -p|git apply -R unapplies (careful with new files) git stash [stash_id] branch branchname applies into new branch </ul>
  • 119. Rewriting history <ul>Changing the last commit <ul>git commit --ammend </ul>Changing history git rebase -i <parent_of_the_last_commit_you_want_to_edit> <ul>e.g git rebase -i HEAD~3 e.g git rebase my-tag~1 </ul></ul>
  • 120. Rewriting history: actions <ul>pick: use commit normally reword: use commit but edit commit message edit: use commit but stop for amending squash: use commit but meld into previous one fixup: like squash, but discard this commit's log message </ul>
  • 121. Cherry picking <ul>If you want to get one commit out of a branch git cherry-pick <sha-1_commit> (from the branch which you want the commit into) Be careful because it ends with two different commits which introuduces the same set of changes </ul>
  • 122. Getting file's content of a specific revision <ul>git show <treeish>:<filename> with this you get the content of that file </ul>
  • 123. Debugging with git: file anotation <ul>git blame [-L line1, line2] <file> you can see when each line of the method was edited and by whom </ul>
  • 124. Debugging with git: binary search <ul>git bisect start git bisect bad [commit_id] git bisect good [commit_id] git bisect reset </ul>
  • 125. References <ul>http://progit.org http://gitready.com git man pages </ul>
  • 126. !gracias!

×