SlideShare a Scribd company logo
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

More Related Content

PDF
Git 's way
PDF
Let the contribution begin
PDF
Git Anti-Patterns: How To Mess Up With Git and Love it Again - DevoxxPL 2017
PDF
Git Anti Patterns - XP Days Ukraine 2017
PDF
Develop Android/iOS app using golang
PDF
Git Anti-Patterns - Extended Version With 28 Common Anti-Patterns) - SCTurkey...
PDF
Collaborative Development: The Only CD That Matters - Brent Beer - Codemotion...
PDF
Git inter-snapshot public
Git 's way
Let the contribution begin
Git Anti-Patterns: How To Mess Up With Git and Love it Again - DevoxxPL 2017
Git Anti Patterns - XP Days Ukraine 2017
Develop Android/iOS app using golang
Git Anti-Patterns - Extended Version With 28 Common Anti-Patterns) - SCTurkey...
Collaborative Development: The Only CD That Matters - Brent Beer - Codemotion...
Git inter-snapshot public

What's hot (16)

PDF
Git and GitHub - The beginning
PDF
Introduction to Git (even for non-developers)
ODP
JBUG Netherlands Openshift Primer
PPTX
Intro. to Git and Github
ODP
Red Hat Developer Day London: Advanced Java & JBoss in the Cloud
PDF
LetSwift 2017 - 토스 iOS 앱의 개발/배포 환경
PDF
(Live) build and run golang web server on android.avi
PDF
Android is going to Go! Android and Golang
PDF
DO YOU WANT TO USE A VCS
PDF
WebGeek AppNimbus (Nikko Bautista)
PDF
Let the contribution begin (EST futures)
PDF
Enabling Microservices @Orbitz - DevOpsDays Chicago 2015
PDF
Git the Docs: A fun, hands-on introduction to version control
PDF
JAZOON'13 - Stefan Saasen - True Git: The Great Migration
PDF
An introduction to_golang.avi
PDF
Develop Android app using Golang
Git and GitHub - The beginning
Introduction to Git (even for non-developers)
JBUG Netherlands Openshift Primer
Intro. to Git and Github
Red Hat Developer Day London: Advanced Java & JBoss in the Cloud
LetSwift 2017 - 토스 iOS 앱의 개발/배포 환경
(Live) build and run golang web server on android.avi
Android is going to Go! Android and Golang
DO YOU WANT TO USE A VCS
WebGeek AppNimbus (Nikko Bautista)
Let the contribution begin (EST futures)
Enabling Microservices @Orbitz - DevOpsDays Chicago 2015
Git the Docs: A fun, hands-on introduction to version control
JAZOON'13 - Stefan Saasen - True Git: The Great Migration
An introduction to_golang.avi
Develop Android app using Golang
Ad

Similar to Geek git (20)

PDF
Git for beginners
PPTX
Get going with_git_ppt
PPTX
Git One Day Training Notes
ODP
Git tech talk
PDF
Learn Git Fundamentals
PDF
Getting some Git
PPTX
Git more done
PDF
Git for developers
PDF
Git basics
PPT
PPTX
Learning Basic GIT Cmd
PDF
SVN 2 Git
PPT
Git presentation
PPTX
An introduction to Git
PDF
Git Basics 1 Carenza
PDF
Git training v10
PDF
Git of every day
PDF
git-commands-cheat-sheet-infopediya-com.pdf
PPT
Fundamentals and basics of Git and commands
Git for beginners
Get going with_git_ppt
Git One Day Training Notes
Git tech talk
Learn Git Fundamentals
Getting some Git
Git more done
Git for developers
Git basics
Learning Basic GIT Cmd
SVN 2 Git
Git presentation
An introduction to Git
Git Basics 1 Carenza
Git training v10
Git of every day
git-commands-cheat-sheet-infopediya-com.pdf
Fundamentals and basics of Git and commands
Ad

Recently uploaded (20)

PDF
Approach and Philosophy of On baking technology
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Big Data Technologies - Introduction.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
A Presentation on Artificial Intelligence
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
Encapsulation theory and applications.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Machine learning based COVID-19 study performance prediction
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
Approach and Philosophy of On baking technology
Network Security Unit 5.pdf for BCA BBA.
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
NewMind AI Weekly Chronicles - August'25-Week II
Unlocking AI with Model Context Protocol (MCP)
Big Data Technologies - Introduction.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Per capita expenditure prediction using model stacking based on satellite ima...
A Presentation on Artificial Intelligence
Building Integrated photovoltaic BIPV_UPV.pdf
Spectroscopy.pptx food analysis technology
Encapsulation theory and applications.pdf
MYSQL Presentation for SQL database connectivity
Machine learning based COVID-19 study performance prediction
A comparative analysis of optical character recognition models for extracting...
MIND Revenue Release Quarter 2 2025 Press Release
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Assigned Numbers - 2025 - Bluetooth® Document

Geek git

Editor's Notes

  • #4: - poll: who’s using what?- cvs- svn- sourcesafe- perforce- git- mercurial - bazzar- ใครใช้ dropbox?- ใครไม่ใช้อะไรเลย ??- เริ่มใช้กันมาตั้งแต่เมื่อไหร่ ?
  • #5: - BitKeeper - distributed commercial scm for open source projects.
  • #6: http://www.youtube.com/watch?v=4XpnKHJAok8
  • #15: $ git config --global user.name &quot;Salahuddin Chalermthai&quot;$ git config --global user.email [email_address] git config --global color.ui true
  • #17: git add to make the files trackable and prepare them for the next commit
  • #19: git add to make the files trackable and prepare them for the next commit
  • #21: Git add (to INDEX)
  • #23: git status; git diff diff is a diff between WT and INDEX? what does that mean is to be shown next.
  • #24: but diff shows NOTHING!?!
  • #25: but diff shows NOTHING!?!
  • #26: but diff shows NOTHING!?!
  • #27: git diff
  • #28: 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
  • #29: 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
  • #31: git checkout, git reset have more to come!
  • #33: - Merging SVN branches is another hard topic
  • #34: git add to make the files trackable and prepare them for the next commit
  • #38: git add to make the files trackable and prepare them for the next commit
  • #39: HEAD~1 == head -1
  • #47: git checkout master git merge feature3 #input merge commit message &amp; save git tree
  • #54: What is rebase? rebase is to rewrite history.
  • #59: You still have to resolve it! clone [email_address] :schalermthai/git_training_with_conflicts.git and try resolve conflicts with both merge and rebase!
  • #61: origin is an default ALIAS
  • #63: check git hub
  • #64: setup a new git repo. Add github collaborator as necessary
  • #65: B and A will have to pull first before push
  • #66: origin is an default ALIAS
  • #67: setup a new git repo. Add github collaborator as necessary
  • #68: setup a new git repo. Add github collaborator as necessary
  • #69: setup a new git repo. Add github collaborator as necessary
  • #70: $ 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).
  • #71: You can’t PULL and you aren’t ready to commit! STASH to rescue
  • #72: Warning!: GIT STASH can create conflicts!
  • #74: Warning!: GIT STASH can create conflicts!
  • #75: Warning!: GIT STASH can create conflicts!
  • #76: Warning!: GIT STASH can create conflicts!
  • #77: Warning!: GIT STASH can create conflicts!
  • #78: Warning!: GIT STASH can create conflicts!
  • #79: Warning!: GIT STASH can create conflicts!
  • #80: Warning!: GIT STASH can create conflicts!
  • #81: A friend deleted a branch you used to hold reference
  • #84: like rebase: LOCAL changes only
  • #85: http://git-scm.com/book/en/Git-Tools-Rewriting-History
  • #87: git blame -C -L 0,4 feature3.txt
  • #88: BINARY SEARCH! http://stackoverflow.com/questions/4713088/how-to-use-git-bisect
  • #89: http://git-scm.com/book/en/Git-Tools-Debugging-with-Git
  • #90: When to use submodules!
  • #91: http://git-scm.com/book/en/Git-Tools-Debugging-with-Git
  • #95: http://git-scm.com/book/en/Git-Tools-Debugging-with-Git
  • #98: http://code.google.com/p/gerrit/ https://review.openstack.org/Documentation/intro-quick.html