Geek git
Upcoming SlideShare
Loading in...5
×
 

Geek git

on

  • 1,383 views

 

Statistics

Views

Total Views
1,383
Views on SlideShare
1,379
Embed Views
4

Actions

Likes
5
Downloads
50
Comments
0

3 Embeds 4

http://jfeeds.carsmantra.com 2
http://wp.joshlabs.in 1
http://wp.joshlabs.webfactional.com 1

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • - 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 "Salahuddin Chalermthai"$ 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 "git rm --cached ..." to unstage)# # new file: file2.txt # Changes not staged for commit :# (use "git add ..." to update what will be committed)# (use "git checkout -- ..." 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 "git rm --cached ..." to unstage)# # new file: file2.txt # Changes not staged for commit :# (use "git add ..." to update what will be committed)# (use "git checkout -- ..." 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 & 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

Geek git Geek git Presentation Transcript

  • 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) Lumyong - piya.tae@gmail.com
  • 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 (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.
  • 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.
  • 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
  • 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
  • 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 Repository
  • 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-keygen goto https://github.com/schalermthai/git_training fork IT!
  • GEEK ACADEMY 2013 Problem#: How to see history? $ git log --oneline --graph Note: git config --global alias.tree "log --graph --decorate --oneline --abbrev-commit"
  • 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 file1.txt $ git status $ git commit -m “my first commit”
  • 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>..." to unstage)## new file: file1.txt
  • 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 -am “added file1”
  • 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) - SVN Branching is very heavyweight. - Heavy enough so you wouldn’t want to create a branch unless it’s super necessary
  • GEEK ACADEMY 2013 Problem#: How to create a new branch? $ git branch feature1 $ git branch $ git checkout feature1 $ git branch $ git tree
  • 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 --all
  • 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
  • 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 created
  • 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 feature3
  • 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 add feature3, commit and push; 3. A add feature3, commit and push; 3. A add feature3, commit and push;
  • 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/master $ git diff ..origin/master
  • 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
  • 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!
  • 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.txt $ git add feature6.txt $ git commit -m “complete feature6”
  • 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
  • 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 myFeature5:feature5
  • 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.txt $ git commit -m “complete feature4” $ echo ‘forgot this’ >> feature4.txt $ git add feature3-1.txt $ git commit --amend
  • GEEK ACADEMY 2013 Problem#: How to do rebase interactive? $ git rebase -i HEAD~4 #you can move, delete, edit, squash commits
  • 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 bisect good v1.0
  • Git Submodule GEEK ACADEMY 2013
  • GEEK ACADEMY 2013 Problem#: How to create a git submodule? $ git submodule add <remote> <directory> $ git status $ git commit -m “added submodule”
  • 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 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
  • 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!
  • GEEK ACADEMY 2013