0
Git-4-Geeks
1st WEEK
DATE
GEEKY ACADEMY 2013
GEEK ACADEMY
2013
WHO ARE WE?
SALAH PIYA
Sala (Dean) Chalermthai
Siam Chamnan Kit
SChalermthai@sprint3r.com
Piya (Tae) Lum...
GEEK ACADEMY
2013
WHO ARE YOU?
GEEK ACADEMY
2013
G
GIT
In software development, Git / tɡɪ / is a distributed version control and
source code management (...
GEEK ACADEMY
2013
Git History
o Linux submitting patches model is quite interesting & unique in that time
o Linus hates CV...
GEEK ACADEMY
2013
Git History
• Nothing matches the criteria. Linus decided to creates his own SCM, Git.
• After the 2.6.1...
GEEK ACADEMY
2013
Git History
• Kernel 2.6.12 release was managed by Git
• Junio Harmano, major contributor was responsibl...
Git4G33ks
GEEK ACADEMY 2013
GEEK ACADEMY
2013
Problem#:How is the course structured?
• Scenario based: Problems & Solutions
GEEK ACADEMY
2013
Problem#:What is distributed SCM?
GEEK ACADEMY
2013
Centralized CSM
Centralized
Repository
Developer
Developer
Developer
GEEK ACADEMY
2013
Distributed CSM
Shared Repository
Developer
Developer
Developer
Local Repository
Local Repository
Local ...
GEEK ACADEMY
2013
Problem#: Is Git Installed?
$ git --version
git version 1.8.3.1
GEEK ACADEMY
2013
Problem#: How to create a local repo?
$ git init
GEEK ACADEMY
2013
Problem#: How to clone a remote repo?
$ git clone git@github.com:<username>/git_training.git
$ ssh-keyge...
GEEK ACADEMY
2013
Problem#: How to see history?
$ git log --oneline --graph
Note:
git config --global alias.tree "log --gr...
GEEK ACADEMY
2013
C3
HEAD
master
C1 C2
GEEK ACADEMY
2013
Problem3: How to make a commit?
$ git status
$ echo ‘hello world’ >> file1.txt
$ git status
$ git add fi...
GEEK ACADEMY
2013
C4
HEAD
master
C2 C3C1
GEEK ACADEMY
2013
NOTE:
svn add != git add
GEEK ACADEMY
2013
INDEX (staging)
Working Directory
C4
HEAD
master
C2 C3C1
git add
git commit
GEEK ACADEMY
2013
Git diff
$ echo ‘how are you?’ >> file1.txt
$ git status
$ git diff
GEEK ACADEMY
2013
Git diff
$ git add file1.txt
$ git status
# Changes to be committed:# (use "git rm
--cached <file>..." t...
GEEK ACADEMY
2013
Git INDEX
$ git diff
GEEK ACADEMY
2013
Git INDEX
$ git diff --cached
GEEK ACADEMY
2013
HEAD
INDEX (staging)
Working Directory
git add
git commit
git diff
git diff --cached
GEEK ACADEMY
2013
INDEX is a SNAPSHOT!
$ echo 'oops!forgot something' >> file1.txt
$ git status
GEEK ACADEMY
2013
INDEX is a SNAPSHOT!
$ echo 'oops!forgot something' >> file1.txt
$ git status
$ git diff
$ git commit -a...
GEEK ACADEMY
2013
C5
HEAD
master
C3 C4C2C1
GEEK ACADEMY
2013
Recap
• git add
• git commit
• git status
• git diff
• git checkout
• git reset
• git log
GIT BRANCHING
GEEK ACADEMY 2013
GEEK ACADEMY
2013
S
GIT BRANCHING
- GIT branching is super easy & lightweight
- Branching is just a ref (AKA. pointer)
- S...
GEEK ACADEMY
2013
Problem#: How to create a new branch?
$ git branch feature1
$ git branch
$ git checkout feature1
$ git b...
GEEK ACADEMY
2013
C5
HEAD
master
C3 C4
GEEK ACADEMY
2013
C5
HEAD
master
C3 C4
feature1
git branch feature1
GEEK ACADEMY
2013
C5
HEAD
master
C3 C4
feature1
git checkout feature1
GEEK ACADEMY
2013
Problem#: How to create a new branch and
switch to it?
$ git checkout -b feature2
$ git branch
GEEK ACADEMY
2013
Problem#: How to create a new branch
from a commit point?
$ git checkout -b feature3 HEAD~1
$ git tree -...
GEEK ACADEMY
2013
Makes 2 commits to feature2 branch and tag
it!
$ git checkout feature2
$ echo ‘1’ >> feature2.txt
$ git ...
GEEK ACADEMY
2013
C5
HEAD
master
C3 C4
C6 C7
feature2
GEEK ACADEMY
2013
Problem#: How to merge a branch?
$ git checkout master
$ git merge feature2
GEEK ACADEMY
2013
C5
HEAD
master
C3 C4
C6 C7
feature2
GEEK ACADEMY
2013
C5
HEAD
master
C3 C4 C6 C7
feature2
FAST FORWARDED!
GEEK ACADEMY
2013
Switch back to feature3 branch and create 1
new commit!
GEEK ACADEMY
2013
C5
HEAD
master
C3 C4 C6 C7
feature2
C8
feature3
GEEK ACADEMY
2013
Switch back to master and now try to merge
feature3 branch!
GEEK ACADEMY
2013
C5C3 C4
master
C6 C7
feature2
C8
feature3
C9
HEAD
Cannot make a fast-forward. So a new
merge commit is c...
GEEK ACADEMY
2013
Problem#: How to reset a branch?
$ git checkout master
$ git reset --hard feature2
$ git tree
GEEK ACADEMY
2013
C5C3 C4
master
C6 C7
feature2
C8
feature3
HEAD
GEEK ACADEMY
2013
Problem#: How to delete a branch?
$ git checkout master
$ git branch -D feature2
$ git branch
$ git tree
GEEK ACADEMY
2013
C5C3 C4
master
C6 C7
feature2
C8
feature3
HEAD
GEEK ACADEMY
2013
C5C3 C4
master
C6 C7
C8
feature3
HEAD
GEEK ACADEMY
2013
Problem#: How to rebase a branch?
$ git checkout feature3
$ git rebase master
GEEK ACADEMY
2013
C5C3 C4
master
C6 C7
C8
feature3
HEAD
C8’
Challenge: switch back to master and fast-forward it to featur...
GEEK ACADEMY
2013
C5C3 C4
master
C6 C7
feature3
HEAD
C8’
GEEK ACADEMY
2013
C5C3 C4
master
C6 C7
feature3
HEAD
C8’
Conflict
resolving
GEEK ACADEMY 2013
GEEK ACADEMY
2013
Neither, Rebase or Merge did not make
conflicts go away!!
Git Remote
GEEK ACADEMY 2013
GEEK ACADEMY
2013
Problem#: How to see remote details?
$ git remote -v
$ git remote show <remote>
GEEK ACADEMY
2013
Problem#: How to see tracking remote
branches?
$ git branch -r
$ git branch -a
GEEK ACADEMY
2013
Problem#: How to push changes to a branch
$ git push origin master
GEEK ACADEMY
2013
Find a couple to work with!
GEEK ACADEMY
2013
1. A & B clone from same repo
2. A add feature1, commit and push; B add feature2, commit and push
3. A a...
GEEK ACADEMY
2013
Problem#: How to pull from remote?
$ git pull origin master
GEEK ACADEMY
2013
Git pull == git fetch;git merge origin/master
GEEK ACADEMY
2013
git tree --all
GEEK ACADEMY
2013
Git pull --rebase == git fetch;git rebase
origin/master
GEEK ACADEMY
2013
Problem#: How to diff with remote branch?
$ git fetch;
$ git diff origin/master
$ git diff ...origin/mas...
GEEK ACADEMY
2013
Problem#: You want to pull but you are not
ready to commit?
$ git reset --hard HEAD~1
$ echo ‘experiment...
GEEK ACADEMY
2013
Problem#: How to stash changes?
$ git stash
$ git status
$ git pull origin master
$ git stash pop
Warnin...
Tagging &
Branching Tips
GEEK ACADEMY 2013
GEEK ACADEMY
2013
Problem#: Git checkout vs Git reset?
$ git checkout <commit>
$ git reset <commit>
GEEK ACADEMY
2013
Problem#: What to do when you forgot to
create a feature branch?
$ git checkout master
$ touch feature6....
GEEK ACADEMY
2013
Problem#: What to do when you forgot to
create a feature branch?
$ git branch feature6
$ git tree --all
...
GEEK ACADEMY
2013
Problem#: How to create a tag?
$ git tag v1.0
$ git tag v1.1 <commit>
$ git push origin v1.0
GEEK ACADEMY
2013
Problem#: How to push to different remote
branch name?
$ git checkout -b myFeature5
$ git push origin my...
GEEK ACADEMY
2013
Problem#: How to delete a local branch?
$ git branch -D feature2
GEEK ACADEMY
2013
Problem#: How to delete a remote branch?
$ git push origin :feature2
GEEK ACADEMY
2013
Problem#: How to remove deleted tracking
branch?
$ git branch -a
$ git fetch
$ git prune
$ git fetch -p
UNDO
CHANGES
GEEK ACADEMY 2013
GEEK ACADEMY
2013
Problem#: How to revert a public commit?
$ git revert #commit
GEEK ACADEMY
2013
Problem#: How to amend to local last
commit?
$ echo ‘finish feature4’ >> feature4.txt
$ git add feature4...
GEEK ACADEMY
2013
Problem#: How to do rebase interactive?
$ git rebase -i HEAD~4
#you can move, delete, edit, squash commi...
Git for
debugging
GEEK ACADEMY 2013
GEEK ACADEMY
2013
Problem#: How to see who commit which line
of code and when?
$ git blame <file>
GEEK ACADEMY
2013
Problem#: How to see which revision that
introduce the bug?
$ git bisect start
$ git bisect bad
$ git bi...
Git Submodule
GEEK ACADEMY 2013
GEEK ACADEMY
2013
Problem#: How to create a git submodule?
$ git submodule add <remote> <directory>
$ git status
$ git com...
Git Tips
GEEK ACADEMY 2013
GEEK ACADEMY
2013
Problem#: How to cherry-pick commits?
$ git cherry-pick <commit>
GEEK ACADEMY
2013
Problem#: How to remove untracked files?
$ git clean -df
GEEK ACADEMY
2013
Problem#: How to add new remote?
$ git remote add <alias> <remote>
$ git fetch <alias>
Git Workflow
GEEK ACADEMY 2013
GEEK ACADEMY
2013
Problem#: Git flow?
http://nvie.com/posts/a-successful-git-branch
https://github.com/nvie/gitflow
GEEK ACADEMY
2013
Problem#: Code review with
Github/BitBucket Pull Request
GEEK ACADEMY
2013
Problem#: Code review with Gerrit
GEEK ACADEMY
2013
Feature Branch vs Branch by Abstraction
• Feature Branch == Poor man’s modular architect
• Feature toggl...
GEEK ACADEMY
2013
Summary
• Git is a very cool & powerful tool
• Once you understand its basic fundamental, you’ll start f...
GEEK ACADEMY 2013
Upcoming SlideShare
Loading in...5
×

Geek git

1,442

Published on

Published in: Technology, News & Politics
0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,442
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
55
Comments
0
Likes
6
Embeds 0
No embeds

No notes for slide
  • - poll: who’s using what?- cvs- svn- sourcesafe- perforce- git- mercurial - bazzar- ใครใช้ dropbox?- ใครไม่ใช้อะไรเลย ??- เริ่มใช้กันมาตั้งแต่เมื่อไหร่ ?
  • - BitKeeper - distributed commercial scm for open source projects.
  • http://www.youtube.com/watch?v=4XpnKHJAok8
  • $ git config --global user.name &quot;Salahuddin Chalermthai&quot;$ git config --global user.email [email_address] git config --global color.ui true
  • git add to make the files trackable and prepare them for the next commit
  • git add to make the files trackable and prepare them for the next commit
  • Git add (to INDEX)
  • git status; git diff diff is a diff between WT and INDEX? what does that mean is to be shown next.
  • but diff shows NOTHING!?!
  • but diff shows NOTHING!?!
  • but diff shows NOTHING!?!
  • git diff
  • INDEX is a snapshot of time. # Changes to be committed :# (use &quot;git rm --cached &lt;file&gt;...&quot; to unstage)# # new file: file2.txt # Changes not staged for commit :# (use &quot;git add &lt;file&gt;...&quot; to update what will be committed)# (use &quot;git checkout -- &lt;file&gt;...&quot; to discard changes in working directory)# # modified: file2.txt # modified: file2.txt # modified: file2.txt # modified: file2.txt # modified: file2.txt
  • INDEX is a snapshot of time. - try git diff again - readd and commit by using git commit -am # Changes to be committed :# (use &quot;git rm --cached &lt;file&gt;...&quot; to unstage)# # new file: file2.txt # Changes not staged for commit :# (use &quot;git add &lt;file&gt;...&quot; to update what will be committed)# (use &quot;git checkout -- &lt;file&gt;...&quot; to discard changes in working directory)# # modified: file2.txt # modified: file2.txt # modified: file2.txt # modified: file2.txt # modified: file2.txt
  • git checkout, git reset have more to come!
  • - Merging SVN branches is another hard topic
  • git add to make the files trackable and prepare them for the next commit
  • git add to make the files trackable and prepare them for the next commit
  • HEAD~1 == head -1
  • git checkout master git merge feature3 #input merge commit message &amp; save git tree
  • What is rebase? rebase is to rewrite history.
  • You still have to resolve it! clone [email_address] :schalermthai/git_training_with_conflicts.git and try resolve conflicts with both merge and rebase!
  • origin is an default ALIAS
  • check git hub
  • setup a new git repo. Add github collaborator as necessary
  • B and A will have to pull first before push
  • origin is an default ALIAS
  • setup a new git repo. Add github collaborator as necessary
  • setup a new git repo. Add github collaborator as necessary
  • setup a new git repo. Add github collaborator as necessary
  • $ git diff remote/origin This shows the incoming remote changes as deletions; any commits in your local repository are shown as additions. $ git diff ...remote/origin Shows incoming remote changes as additions; the triple-dot excludes changes committed to your local repository. $ git diff ..remote/origin Shows incoming remote changes as additions; the double-dot includes changes committed to your local repository as deletions (since they are not yet pushed).
  • You can’t PULL and you aren’t ready to commit! STASH to rescue
  • Warning!: GIT STASH can create conflicts!
  • Warning!: GIT STASH can create conflicts!
  • Warning!: GIT STASH can create conflicts!
  • Warning!: GIT STASH can create conflicts!
  • Warning!: GIT STASH can create conflicts!
  • Warning!: GIT STASH can create conflicts!
  • Warning!: GIT STASH can create conflicts!
  • Warning!: GIT STASH can create conflicts!
  • A friend deleted a branch you used to hold reference
  • like rebase: LOCAL changes only
  • http://git-scm.com/book/en/Git-Tools-Rewriting-History
  • git blame -C -L 0,4 feature3.txt
  • BINARY SEARCH! http://stackoverflow.com/questions/4713088/how-to-use-git-bisect
  • http://git-scm.com/book/en/Git-Tools-Debugging-with-Git
  • When to use submodules!
  • http://git-scm.com/book/en/Git-Tools-Debugging-with-Git
  • http://git-scm.com/book/en/Git-Tools-Debugging-with-Git
  • http://code.google.com/p/gerrit/ https://review.openstack.org/Documentation/intro-quick.html
  • Transcript of "Geek git"

    1. 1. Git-4-Geeks 1st WEEK DATE GEEKY ACADEMY 2013
    2. 2. GEEK ACADEMY 2013 WHO ARE WE? SALAH PIYA Sala (Dean) Chalermthai Siam Chamnan Kit SChalermthai@sprint3r.com Piya (Tae) Lumyong - piya.tae@gmail.com
    3. 3. GEEK ACADEMY 2013 WHO ARE YOU?
    4. 4. GEEK ACADEMY 2013 G GIT In software development, Git / tɡɪ / is a distributed version control and source code management (SCM) system with an emphasis on speed. Initially designed and developed by Linus Torvalds for Linux kernel development, Git has since been adopted by many other projects.
    5. 5. GEEK ACADEMY 2013 Git History o Linux submitting patches model is quite interesting & unique in that time o Linus hates CVS so much, he never believe in it o He was in doomed maintaining Linux Kernel using Tarball + patch o BitMover offer BitKeeper free usage. BitKeeper saved his life, but just for a while o BitKeeper has a very strict Software License. People start to get upset o Politics happened. Linus needs a replacement for BitKeeper o Key criteria are: o Needs to be Distributed SCM, like BitKeeper o Needs to be highly Performance. 3 seconds max to apply a patch o Guaranteed what goes in comes out correctly.
    6. 6. GEEK ACADEMY 2013 Git History • Nothing matches the criteria. Linus decided to creates his own SCM, Git. • After the 2.6.12-rc2 Linux kernel development release, he make an announce: “I’m not going to touch linux until I have a replacement of BitKeepers” -- Linus Torvalds
    7. 7. GEEK ACADEMY 2013 Git History • Kernel 2.6.12 release was managed by Git • Junio Harmano, major contributor was responsible for Git 1.0 release on 21 Dec 2005 • He remains as the project’s maintainer • Linus on Git, Google Tech Talk: http://www.youtube.com/watch?v=4XpnKHJAok8
    8. 8. Git4G33ks GEEK ACADEMY 2013
    9. 9. GEEK ACADEMY 2013 Problem#:How is the course structured? • Scenario based: Problems & Solutions
    10. 10. GEEK ACADEMY 2013 Problem#:What is distributed SCM?
    11. 11. GEEK ACADEMY 2013 Centralized CSM Centralized Repository Developer Developer Developer
    12. 12. GEEK ACADEMY 2013 Distributed CSM Shared Repository Developer Developer Developer Local Repository Local Repository Local Repository
    13. 13. GEEK ACADEMY 2013 Problem#: Is Git Installed? $ git --version git version 1.8.3.1
    14. 14. GEEK ACADEMY 2013 Problem#: How to create a local repo? $ git init
    15. 15. GEEK ACADEMY 2013 Problem#: How to clone a remote repo? $ git clone git@github.com:<username>/git_training.git $ ssh-keygen goto https://github.com/schalermthai/git_training fork IT!
    16. 16. GEEK ACADEMY 2013 Problem#: How to see history? $ git log --oneline --graph Note: git config --global alias.tree "log --graph --decorate --oneline --abbrev-commit"
    17. 17. GEEK ACADEMY 2013 C3 HEAD master C1 C2
    18. 18. GEEK ACADEMY 2013 Problem3: How to make a commit? $ git status $ echo ‘hello world’ >> file1.txt $ git status $ git add file1.txt $ git status $ git commit -m “my first commit”
    19. 19. GEEK ACADEMY 2013 C4 HEAD master C2 C3C1
    20. 20. GEEK ACADEMY 2013 NOTE: svn add != git add
    21. 21. GEEK ACADEMY 2013 INDEX (staging) Working Directory C4 HEAD master C2 C3C1 git add git commit
    22. 22. GEEK ACADEMY 2013 Git diff $ echo ‘how are you?’ >> file1.txt $ git status $ git diff
    23. 23. GEEK ACADEMY 2013 Git diff $ git add file1.txt $ git status # Changes to be committed:# (use "git rm --cached <file>..." to unstage)## new file: file1.txt
    24. 24. GEEK ACADEMY 2013 Git INDEX $ git diff
    25. 25. GEEK ACADEMY 2013 Git INDEX $ git diff --cached
    26. 26. GEEK ACADEMY 2013 HEAD INDEX (staging) Working Directory git add git commit git diff git diff --cached
    27. 27. GEEK ACADEMY 2013 INDEX is a SNAPSHOT! $ echo 'oops!forgot something' >> file1.txt $ git status
    28. 28. GEEK ACADEMY 2013 INDEX is a SNAPSHOT! $ echo 'oops!forgot something' >> file1.txt $ git status $ git diff $ git commit -am “added file1”
    29. 29. GEEK ACADEMY 2013 C5 HEAD master C3 C4C2C1
    30. 30. GEEK ACADEMY 2013 Recap • git add • git commit • git status • git diff • git checkout • git reset • git log
    31. 31. GIT BRANCHING GEEK ACADEMY 2013
    32. 32. GEEK ACADEMY 2013 S GIT BRANCHING - GIT branching is super easy & lightweight - Branching is just a ref (AKA. pointer) - SVN Branching is very heavyweight. - Heavy enough so you wouldn’t want to create a branch unless it’s super necessary
    33. 33. GEEK ACADEMY 2013 Problem#: How to create a new branch? $ git branch feature1 $ git branch $ git checkout feature1 $ git branch $ git tree
    34. 34. GEEK ACADEMY 2013 C5 HEAD master C3 C4
    35. 35. GEEK ACADEMY 2013 C5 HEAD master C3 C4 feature1 git branch feature1
    36. 36. GEEK ACADEMY 2013 C5 HEAD master C3 C4 feature1 git checkout feature1
    37. 37. GEEK ACADEMY 2013 Problem#: How to create a new branch and switch to it? $ git checkout -b feature2 $ git branch
    38. 38. GEEK ACADEMY 2013 Problem#: How to create a new branch from a commit point? $ git checkout -b feature3 HEAD~1 $ git tree --all
    39. 39. GEEK ACADEMY 2013 Makes 2 commits to feature2 branch and tag it! $ git checkout feature2 $ echo ‘1’ >> feature2.txt $ git add feature2.txt $ git commit -m “completed task 2.1” $ echo ‘2’ >> feature2.txt $ git commit -am “completed task 2.2” $ git tree
    40. 40. GEEK ACADEMY 2013 C5 HEAD master C3 C4 C6 C7 feature2
    41. 41. GEEK ACADEMY 2013 Problem#: How to merge a branch? $ git checkout master $ git merge feature2
    42. 42. GEEK ACADEMY 2013 C5 HEAD master C3 C4 C6 C7 feature2
    43. 43. GEEK ACADEMY 2013 C5 HEAD master C3 C4 C6 C7 feature2 FAST FORWARDED!
    44. 44. GEEK ACADEMY 2013 Switch back to feature3 branch and create 1 new commit!
    45. 45. GEEK ACADEMY 2013 C5 HEAD master C3 C4 C6 C7 feature2 C8 feature3
    46. 46. GEEK ACADEMY 2013 Switch back to master and now try to merge feature3 branch!
    47. 47. GEEK ACADEMY 2013 C5C3 C4 master C6 C7 feature2 C8 feature3 C9 HEAD Cannot make a fast-forward. So a new merge commit is created
    48. 48. GEEK ACADEMY 2013 Problem#: How to reset a branch? $ git checkout master $ git reset --hard feature2 $ git tree
    49. 49. GEEK ACADEMY 2013 C5C3 C4 master C6 C7 feature2 C8 feature3 HEAD
    50. 50. GEEK ACADEMY 2013 Problem#: How to delete a branch? $ git checkout master $ git branch -D feature2 $ git branch $ git tree
    51. 51. GEEK ACADEMY 2013 C5C3 C4 master C6 C7 feature2 C8 feature3 HEAD
    52. 52. GEEK ACADEMY 2013 C5C3 C4 master C6 C7 C8 feature3 HEAD
    53. 53. GEEK ACADEMY 2013 Problem#: How to rebase a branch? $ git checkout feature3 $ git rebase master
    54. 54. GEEK ACADEMY 2013 C5C3 C4 master C6 C7 C8 feature3 HEAD C8’ Challenge: switch back to master and fast-forward it to feature3
    55. 55. GEEK ACADEMY 2013 C5C3 C4 master C6 C7 feature3 HEAD C8’
    56. 56. GEEK ACADEMY 2013 C5C3 C4 master C6 C7 feature3 HEAD C8’
    57. 57. Conflict resolving GEEK ACADEMY 2013
    58. 58. GEEK ACADEMY 2013 Neither, Rebase or Merge did not make conflicts go away!!
    59. 59. Git Remote GEEK ACADEMY 2013
    60. 60. GEEK ACADEMY 2013 Problem#: How to see remote details? $ git remote -v $ git remote show <remote>
    61. 61. GEEK ACADEMY 2013 Problem#: How to see tracking remote branches? $ git branch -r $ git branch -a
    62. 62. GEEK ACADEMY 2013 Problem#: How to push changes to a branch $ git push origin master
    63. 63. GEEK ACADEMY 2013 Find a couple to work with!
    64. 64. GEEK ACADEMY 2013 1. A & B clone from same repo 2. A add feature1, commit and push; B add feature2, commit and push 3. A add feature3, commit and push; 3. A add feature3, commit and push; 3. A add feature3, commit and push;
    65. 65. GEEK ACADEMY 2013 Problem#: How to pull from remote? $ git pull origin master
    66. 66. GEEK ACADEMY 2013 Git pull == git fetch;git merge origin/master
    67. 67. GEEK ACADEMY 2013 git tree --all
    68. 68. GEEK ACADEMY 2013 Git pull --rebase == git fetch;git rebase origin/master
    69. 69. GEEK ACADEMY 2013 Problem#: How to diff with remote branch? $ git fetch; $ git diff origin/master $ git diff ...origin/master $ git diff ..origin/master
    70. 70. GEEK ACADEMY 2013 Problem#: You want to pull but you are not ready to commit? $ git reset --hard HEAD~1 $ echo ‘experiment an idea’ >> feature3.txt $ cat feature3.txt $ git status $ git pull origin master STASH to rescue
    71. 71. GEEK ACADEMY 2013 Problem#: How to stash changes? $ git stash $ git status $ git pull origin master $ git stash pop Warning!: GIT STASH can create conflicts!
    72. 72. Tagging & Branching Tips GEEK ACADEMY 2013
    73. 73. GEEK ACADEMY 2013 Problem#: Git checkout vs Git reset? $ git checkout <commit> $ git reset <commit>
    74. 74. GEEK ACADEMY 2013 Problem#: What to do when you forgot to create a feature branch? $ git checkout master $ touch feature6.txt $ git add feature6.txt $ git commit -m “complete feature6”
    75. 75. GEEK ACADEMY 2013 Problem#: What to do when you forgot to create a feature branch? $ git branch feature6 $ git tree --all $ git reset --hard origin/master $ git tree --all
    76. 76. GEEK ACADEMY 2013 Problem#: How to create a tag? $ git tag v1.0 $ git tag v1.1 <commit> $ git push origin v1.0
    77. 77. GEEK ACADEMY 2013 Problem#: How to push to different remote branch name? $ git checkout -b myFeature5 $ git push origin myFeature5:feature5
    78. 78. GEEK ACADEMY 2013 Problem#: How to delete a local branch? $ git branch -D feature2
    79. 79. GEEK ACADEMY 2013 Problem#: How to delete a remote branch? $ git push origin :feature2
    80. 80. GEEK ACADEMY 2013 Problem#: How to remove deleted tracking branch? $ git branch -a $ git fetch $ git prune $ git fetch -p
    81. 81. UNDO CHANGES GEEK ACADEMY 2013
    82. 82. GEEK ACADEMY 2013 Problem#: How to revert a public commit? $ git revert #commit
    83. 83. GEEK ACADEMY 2013 Problem#: How to amend to local last commit? $ echo ‘finish feature4’ >> feature4.txt $ git add feature4.txt $ git commit -m “complete feature4” $ echo ‘forgot this’ >> feature4.txt $ git add feature3-1.txt $ git commit --amend
    84. 84. GEEK ACADEMY 2013 Problem#: How to do rebase interactive? $ git rebase -i HEAD~4 #you can move, delete, edit, squash commits
    85. 85. Git for debugging GEEK ACADEMY 2013
    86. 86. GEEK ACADEMY 2013 Problem#: How to see who commit which line of code and when? $ git blame <file>
    87. 87. GEEK ACADEMY 2013 Problem#: How to see which revision that introduce the bug? $ git bisect start $ git bisect bad $ git bisect good v1.0
    88. 88. Git Submodule GEEK ACADEMY 2013
    89. 89. GEEK ACADEMY 2013 Problem#: How to create a git submodule? $ git submodule add <remote> <directory> $ git status $ git commit -m “added submodule”
    90. 90. Git Tips GEEK ACADEMY 2013
    91. 91. GEEK ACADEMY 2013 Problem#: How to cherry-pick commits? $ git cherry-pick <commit>
    92. 92. GEEK ACADEMY 2013 Problem#: How to remove untracked files? $ git clean -df
    93. 93. GEEK ACADEMY 2013 Problem#: How to add new remote? $ git remote add <alias> <remote> $ git fetch <alias>
    94. 94. Git Workflow GEEK ACADEMY 2013
    95. 95. GEEK ACADEMY 2013 Problem#: Git flow? http://nvie.com/posts/a-successful-git-branch https://github.com/nvie/gitflow
    96. 96. GEEK ACADEMY 2013 Problem#: Code review with Github/BitBucket Pull Request
    97. 97. GEEK ACADEMY 2013 Problem#: Code review with Gerrit
    98. 98. GEEK ACADEMY 2013 Feature Branch vs Branch by Abstraction • Feature Branch == Poor man’s modular architect • Feature toggle + Branch by abstraction • Feature branch suffers when two team members start working on two different feature branches for too long. git rebase origin/develop every day wont help much
    99. 99. GEEK ACADEMY 2013 Summary • Git is a very cool & powerful tool • Once you understand its basic fundamental, you’ll start fall in love with its infinite potential • Keep calm and geek on!
    100. 100. GEEK ACADEMY 2013
    1. A particular slide catching your eye?

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

    ×