SlideShare a Scribd company logo
Did you            yet?Did you            yet?
“ Git  is a British English slang roughly
equivalent to "unpleasant person".
1 . 1
ChangelogChangelog
v 1.0.1
Basic git concept and commands
git flow concept
1 . 2
Design GoalDesign Goal
Git is an open source,  distributed  version
control system designed to be  fast and
branching
Decentralized
vs Centralized (SVN / Perforce / CVS)
Suitable for fast development of multiple branch in
parallel
Git Generally DOES NOT delete data
Git Generally append data in version tree.
Recovering deleted data could be tricky
2 . 1
Work FlowWork Flow
Index
2 . 2
Pros / ConsPros / Cons
Centralized Decentralized
Concurrent Access
Control
File Locking N.A; Manual
intervention is required
to resolve the conflict.
Offline Development Unable to submit
changelist; create a tag /
branch. 
Able to commit to local
repository
Remote Server One Centralized server multiple remote repo
2 . 3
Pros / ConsPros / Cons
Centralized Decentralized
Concurrent Access
Control
File Locking N.A; Manual
intervention is required
to resolve the conflict.
Offline Development Unable to submit
changelist; create a tag /
branch. 
Able to commit to local
repository
Remote Server One Centralized server multiple remote repo
2 . 3
Pros / ConsPros / Cons
Centralized Decentralized
Concurrent Access
Control
File Locking N.A; Manual
intervention is required
to resolve the conflict.
Offline Development Unable to submit
changelist; create a tag /
branch. 
Able to commit to local
repository
Remote Server One Centralized server multiple remote repo
2 . 3
Git ObjectsGit Objects
 $ ll .git/
4096 Apr 7 2018 branches/
528 Nov 9 17:32 COMMIT_EDITMSG
284 Nov 8 20:48 config
73 Apr 7 2018 description
272 Jun 18 00:04 FETCH_HEAD
23 Nov 9 12:35 HEAD
4096 Apr 7 2018 hooks/
16153 Nov 9 17:31 index
4096 Apr 7 2018 info/
4096 Apr 7 2018 logs/
4096 Aug 15 22:56 objects/
41 Nov 8 20:49 ORIG_HEAD
107 Apr 7 2018 packed-refs
4096 Nov 6 14:31 refs/
3 . 1
CommitCommit
A.k.a. Ref / Reference
Alias to a hash (SHA-1) commit hash
See the SHA-1 commit hashes
$ git log
commit 059806c1e05ed7a3a387da16d05844f63c47251a
Author: Author Name <Author Email>
Date: Fri Nov 9 17:31:31 2018 +0800
Commit Title
Commit Description
commit 91e622c61f99f24dbda741050e251837a643f6c9
Author: Michael Fong <mcfong.open@gmail.com>
Date: Thu Nov 8 20:26:33 2018 +0800
Another Commit
3 . 2
HEADHEAD
HEAD file is a symbolic ref for the current branch
$ tree .git/refs/heads/
.git/refs/heads/
├── ConnectionPool
├── LocalhostJmxConnectorServerProxyDemo
├── master
├── RACBenchmark
├── string-builder-perf-death-match
├── study-fadvise-effect
├── tuneWarmUpIteration
└── unintentional-obj-retension
0 directories, 8 files
$ cat .git/refs/heads/master
059806c1e05ed7a3a387da16d05844f63c47251a
Uses HEAD file to store latest commit info of the
branch
3 . 3
BasicBasic
CommandsCommands
4 . 1
Initialize Git SettingInitialize Git Setting
User Information
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com
Editor Information
# Set default editor to vim
$ git config --global core.editor vim
# Set default editor to emacs
$ git config --global core.editor emacs
List current settings
$ git config --list
user.email=mcfong.open@gmail.com
user.name=Michael Fong
core.editor=vim
...
4 . 2
Clone RepositoryClone Repository
$ git clone https://github.com/<username>/<project>
Clone repository via Https
$ git clone ssh://github.com/<username>/<project>
Clone repository via SSH
Show current repository status
$ git status
On branch <local-repo>
Your branch is up-to-date with <remote-repo>.
nothing to commit, working directory clean
<If there is (new) file different from current ver,
they will appear here>
# Diff against local workspace and index
$ git diff
4 . 3
Commit ChangesCommit Changes
# add new files
$ git add 1.file
# add by pattern
$ git add *.file
# add by everything under directory
$ git add ./
$ git add -all
# remove file from tracking
$ git rm file.py
# Diff against local repo and index
$ git diff --cached
Staging Changes
Update to local Staging Area / Index
Commit Changes
Update to local repo
# Enter commit commit description in default editor
$ git commit
# alternatively, one command commit
$ git commit -am "Enter your commit description"
4 . 4
Branch ManagementBranch Management
# create a new branch
$ git checkout master
$ git branch new-branch
# Alternatively, create a new branch from remote-repo/remote-branch
$ git checkout <remote-repo>/<remote-branch> -b <local-branch>
$ git checkout origin/master -b new-branch
#Create a new branch from tag
$ git checkout tags/<tag-name> -b new-branch
Create a new local branch
Switch to existing local branch
List all Branches
$ git checkout new-branch
# (noarg - local branch; -r remote branch; -a all branch)
$ git branch -av
Delete Branch
# Delete local repository
$ git branch -d new-branch
# Delete local repository by force
$ git branch -D new-branch
# Delete a branch from remote repository
$ git push <remote-repo> :<branch-name> 4 . 5
Remote CommandRemote Command
# Add a new remote repo
$ git remote add origin <GIT_URL_HTTPS_or_SSH>
# Update an existing remote repo
$ git remote update origin <GIT_URL_HTTPS_or_SSH>
Push to remote repo:branch
# Fetch & Merge
$ git pull
# Fetch from remote repo
$ git fetch origin
# Merge from remote branch master
$ git merge origin master
Pull from remote repository
Add / Update a remote repository
# push to remote-repo (origin) / remote-branch (master)
$ git push <remote-repo> <local-branch>:<remote-branch>
$ git push origin master:master
$ git push origin master
$ git push origin new-branch:new-branch
4 . 6
(Local Branch) Merge Strategy I(Local Branch) Merge Strategy I
Fast Forward Merge
When the merge resolves as a fast-forward, only
update the branch pointer, without creating a
merge commit.
Default merge strategy
$ git checkout master
$ git merge new-branch (--ff)
4 . 7
(Local Branch) Merge Strategy II(Local Branch) Merge Strategy II
Non Fast Forward Merge
Create a merge commit
$ git checkout master
$ git merge new-branch --no-ff
4 . 8
(Local Branch) Merge Strategy II(Local Branch) Merge Strategy II
Merge Commit
$ git checkout -b new-branch
$ git commit -am 'commit'
$ git checkout master
$ git merge new-branch --no-ff
$ git log
commit 33a935fb06182ba9c6868a9bf85efe7c2e5770f3
Merge: 1d9f153 efd5daa
Author: XXX
Date: Mon Nov 26 11:41:25 2018 +0800
Merge branch 'new-branch'
commit efd5daabfc1d4366f197dc71c3edfd251b0396d0
Author: XXX
Date: Mon Nov 26 11:41:00 2018 +0800
commit
2018-11-26 11:41 Michael Fong M─┐ [master] Merge branch 'new-branch'
2018-11-26 11:41 Michael Fong │ o commit
2018-11-21 15:58 Michael Fong o─┘ {origin/master} {origin/HEAD}
Branching graph
4 . 9
(Remote Branch) Merge(Remote Branch) Merge
Merge between two branch on remote repository
Github: Pull Request
Gitlab: Merge Request
Non fast forward merge
Default strategy for merging PR
Usually configurableg
4 . 10
Merge StrategyMerge Strategy
Log Branch Graph
Fast Forward Clean Less intuitive
No Fast Forward Merge commit More intuitive
4 . 11
Merge ConflictsMerge Conflicts
Manual intervention is required.
 
After self correction is done; add and commit the
conflict files.
$ git add index.html
$ git commit
4 . 12
Rebase IRebase I
Moving a branch onto a new base commit
Rebasing onto master will take all commits from
master and apply your branch commits on top one by
one.
Later could combine with merge to master
4 . 13
Rebase IIRebase II
If combined with squash, there will possibly be only
one commit.
4 . 14
Squash ISquash I
squash is a mechanism to consolidate multiple
commit into one.
It comes with rebase / merge command
4 . 15
Squash IISquash II
pick commit1 (528f601)
squash  commit2 (a96173c)
edit commit3 (eadd9c2)
4 . 16
Squash IIISquash III
Squashing commit 2 into commit 1
4 . 17
Squash IVSquash IV
Edit commit 3
4 . 18
Cherry PickCherry Pick
Given one or more existing commits, apply the change
each one introduces, recording a new commit for
each.
$ git cherry-pick C2 C4
4 . 19
TagTag
Annotation to represent release
Create a tag
List all tags
$ git tag -a <tag-name> -m 'description'
$ git push <remote-repo> <tag-name>
$ git tag -l
Show tag metadata
$ git show <tag-name>
Delete a tag
$ git tag -d <tag-name>
$ git push <remote-repo> <tag-name>
4 . 20
RecoverRecover
CommandsCommands
5 . 1
StashStash
How to save unfinished implementation temporarily?
Save the current state of work.
# Save current work, and rollback to HEAD keep current work space clean
$ git stash -u
# Reload latest stash record
$ git stash pop
# List stash record
$ git stash list
5 . 2
Undo Commit IUndo Commit I
$ git reset --soft HEAD~1
$ git diff --cached
$ git reset HEAD~1
$ git diff
$ git reset --hard HEAD~1
Reset current HEAD to the specific state
Changes are UNSTAGED
Changes are STAGED 
Changes are REMOVED from log
5 . 3
Undo Commit IIUndo Commit II
$ git checkout path/to/filename
$ git revert commit-hash
Reverts a commit with another commit 
 Restores the file to the latest version
in HEAD, changes are dropped
5 . 4
Reference LogReference Log
Historical records when the tips of branches and other
references were updated in the LOCAL repository.
Helpful when you want to look up historical commit
$ git reflog
Maybe your last resort to undo bad commit
Use at your RISK!
$ git reset --hard HEAD@{n}
5 . 5
Bash Alias IBash Alias I
# Nice format for `git log`
alias git.log="git log --graph --abbrev-commit --decorate --
format=format:'%C(bold blue)%h%C(reset) - %C(bold
cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset) %C(bold cyan)
(committed: %cD)%C(reset) %C(auto)%d%C(reset)%n''         
%C(white)%s%C(reset)%n''          %C(dim white)- %an <%ae>
%C(reset) %C(dim white)(committer: %cn <%ce>)%C(reset)' --all"
* 059806c - Fri, 9 Nov 2018 17:31:31 +0800 (2 days ago) (committed: Fri, 9 Nov 2018 17:31:31 +080
| Add unit test to ByteBuf
| - Michael Fong <mcfong.open@gmail.com> (committer: Michael Fong <mcfong.open@gmail.c
| * f5832fa - Fri, 9 Nov 2018 12:35:40 +0800 (2 days ago) (committed: Fri, 9 Nov 2018 12:35:40 +0
| | squash
| | - Michael Fong <mcfong.open@gmail.com> (committer: Michael Fong <mcfong.open@gmail
| * f5f556a - Tue, 6 Nov 2018 19:54:47 +0800 (5 days ago) (committed: Thu, 8 Nov 2018 20:49:30 +0
|/ Add fadvise64
| - Michael Fong <mcfong.open@gmail.com> (committer: Michael Fong <mcfong.open@gmail
* 91e622c - Thu, 8 Nov 2018 20:26:33 +0800 (3 days ago) (committed: Thu, 8 Nov 2018 20:42:14 +080
| Copy libnative-utility.so to target/classes for java-jni
| - Michael Fong <mcfong.open@gmail.com> (committer: Michael Fong <mcfong.open@gmail.c
* 794bf26 - Wed, 7 Nov 2018 16:18:03 +0800 (4 days ago) (committed: Thu, 8 Nov 2018 00:45:32 +080
5 . 6
tigtig
Installation
$ sudo apt-get install tig
log
$ tig log
“ ncurses-based text-mode interface for git.
status
$ tig status
5 . 7
Branching BestBranching Best
PracticePractice
6 . 1
ProblemsProblems
Everyone has a copy.
Unfortunately, NOT the same copy!
Which master is more up to date?
Requiring
Discipline
Methodology
6 . 2
Ref
Git Flow MethodologyGit Flow Methodology
6 . 3
Branching ModelsBranching Models
master  - ONE true MASTER
develop
feature
Feature branches typically exist in
developer repos only, not in origin
release
Release branches support preparation
of a new production release.
hot-fix
 When a critical bug in a production
version must be resolved
immediately, a hotfix branch may be
branched off from the corresponding
tag on the master branch that marks
the production version.
6 . 4
ToolTool
Provide high level operation
github/git-flow/
Git Flow cheatsheet
6 . 5
ReferenceReference
Linux Travolds on git
Git-Basics
Learn How to Git
tig
https://www.youtube.com/embed/4XpnKHJ
Aok8?enablejsapi=1
7

More Related Content

PDF
Git training
PDF
Git - a powerful version control tool
PDF
Brief tutorial on Git
PDF
Git and Github
PPTX
PDF
Git Introduction Tutorial
KEY
Git and GitHub
PDF
Git tutorial
Git training
Git - a powerful version control tool
Brief tutorial on Git
Git and Github
Git Introduction Tutorial
Git and GitHub
Git tutorial

What's hot (20)

PDF
Introduction to Git, DrupalCamp LA 2015
PPTX
Git Terminologies
PDF
Introduction To Git For Version Control Architecture And Common Commands Comp...
PDF
Starting with Git & GitHub
PDF
Git 101 tutorial presentation
PDF
Presentacion git
PPT
Git Introduction
PPTX
Git tutorial
PDF
What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...
PPTX
Introduction git
PDF
Git & GitHub WorkShop
KEY
The everyday developer's guide to version control with Git
PDF
Git and github - Verson Control for the Modern Developer
PDF
Git Tutorial I
PDF
Inside GitHub with Chris Wanstrath
PDF
Mini git tutorial
PPTX
Git Basic
PDF
GIT_In_90_Minutes
PDF
Advanced Git Tutorial
Introduction to Git, DrupalCamp LA 2015
Git Terminologies
Introduction To Git For Version Control Architecture And Common Commands Comp...
Starting with Git & GitHub
Git 101 tutorial presentation
Presentacion git
Git Introduction
Git tutorial
What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...
Introduction git
Git & GitHub WorkShop
The everyday developer's guide to version control with Git
Git and github - Verson Control for the Modern Developer
Git Tutorial I
Inside GitHub with Chris Wanstrath
Mini git tutorial
Git Basic
GIT_In_90_Minutes
Advanced Git Tutorial
Ad

Similar to Did you git yet? (20)

PDF
GIT: Content-addressable filesystem and Version Control System
PPTX
Git-ing out of your git messes
PDF
Git cheat sheet with diagram-5.pdf
PPTX
Get Good With Git
PDF
Honestly Git Playground 20190221
PDF
Git basics
PPTX
PDF
GIT Basics
PPTX
Get going with_git_ppt
PDF
Git training cheat sheet
PDF
Git and github 101
PDF
Git cheat sheet
PPTX
Use Git like a pro - condensed
PPTX
git internals
KEY
Gittalk
PDF
PDF
Git Tutorial Yang Yang
PDF
Improving your workflow with git
PPTX
Learning Basic GIT Cmd
GIT: Content-addressable filesystem and Version Control System
Git-ing out of your git messes
Git cheat sheet with diagram-5.pdf
Get Good With Git
Honestly Git Playground 20190221
Git basics
GIT Basics
Get going with_git_ppt
Git training cheat sheet
Git and github 101
Git cheat sheet
Use Git like a pro - condensed
git internals
Gittalk
Git Tutorial Yang Yang
Improving your workflow with git
Learning Basic GIT Cmd
Ad

Recently uploaded (20)

PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PPT
Project quality management in manufacturing
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
Geodesy 1.pptx...............................................
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
web development for engineering and engineering
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
additive manufacturing of ss316l using mig welding
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
ETO & MEO Certificate of Competency Questions and Answers
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Arduino robotics embedded978-1-4302-3184-4.pdf
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Lesson 3_Tessellation.pptx finite Mathematics
Project quality management in manufacturing
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Geodesy 1.pptx...............................................
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
web development for engineering and engineering
bas. eng. economics group 4 presentation 1.pptx
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
additive manufacturing of ss316l using mig welding
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Foundation to blockchain - A guide to Blockchain Tech
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
ETO & MEO Certificate of Competency Questions and Answers

Did you git yet?

  • 1. Did you            yet?Did you            yet? “ Git  is a British English slang roughly equivalent to "unpleasant person". 1 . 1
  • 2. ChangelogChangelog v 1.0.1 Basic git concept and commands git flow concept 1 . 2
  • 3. Design GoalDesign Goal Git is an open source,  distributed  version control system designed to be  fast and branching Decentralized vs Centralized (SVN / Perforce / CVS) Suitable for fast development of multiple branch in parallel Git Generally DOES NOT delete data Git Generally append data in version tree. Recovering deleted data could be tricky 2 . 1
  • 5. Pros / ConsPros / Cons Centralized Decentralized Concurrent Access Control File Locking N.A; Manual intervention is required to resolve the conflict. Offline Development Unable to submit changelist; create a tag / branch.  Able to commit to local repository Remote Server One Centralized server multiple remote repo 2 . 3
  • 6. Pros / ConsPros / Cons Centralized Decentralized Concurrent Access Control File Locking N.A; Manual intervention is required to resolve the conflict. Offline Development Unable to submit changelist; create a tag / branch.  Able to commit to local repository Remote Server One Centralized server multiple remote repo 2 . 3
  • 7. Pros / ConsPros / Cons Centralized Decentralized Concurrent Access Control File Locking N.A; Manual intervention is required to resolve the conflict. Offline Development Unable to submit changelist; create a tag / branch.  Able to commit to local repository Remote Server One Centralized server multiple remote repo 2 . 3
  • 8. Git ObjectsGit Objects  $ ll .git/ 4096 Apr 7 2018 branches/ 528 Nov 9 17:32 COMMIT_EDITMSG 284 Nov 8 20:48 config 73 Apr 7 2018 description 272 Jun 18 00:04 FETCH_HEAD 23 Nov 9 12:35 HEAD 4096 Apr 7 2018 hooks/ 16153 Nov 9 17:31 index 4096 Apr 7 2018 info/ 4096 Apr 7 2018 logs/ 4096 Aug 15 22:56 objects/ 41 Nov 8 20:49 ORIG_HEAD 107 Apr 7 2018 packed-refs 4096 Nov 6 14:31 refs/ 3 . 1
  • 9. CommitCommit A.k.a. Ref / Reference Alias to a hash (SHA-1) commit hash See the SHA-1 commit hashes $ git log commit 059806c1e05ed7a3a387da16d05844f63c47251a Author: Author Name <Author Email> Date: Fri Nov 9 17:31:31 2018 +0800 Commit Title Commit Description commit 91e622c61f99f24dbda741050e251837a643f6c9 Author: Michael Fong <[email protected]> Date: Thu Nov 8 20:26:33 2018 +0800 Another Commit 3 . 2
  • 10. HEADHEAD HEAD file is a symbolic ref for the current branch $ tree .git/refs/heads/ .git/refs/heads/ ├── ConnectionPool ├── LocalhostJmxConnectorServerProxyDemo ├── master ├── RACBenchmark ├── string-builder-perf-death-match ├── study-fadvise-effect ├── tuneWarmUpIteration └── unintentional-obj-retension 0 directories, 8 files $ cat .git/refs/heads/master 059806c1e05ed7a3a387da16d05844f63c47251a Uses HEAD file to store latest commit info of the branch 3 . 3
  • 12. Initialize Git SettingInitialize Git Setting User Information $ git config --global user.name "John Doe" $ git config --global user.email [email protected] Editor Information # Set default editor to vim $ git config --global core.editor vim # Set default editor to emacs $ git config --global core.editor emacs List current settings $ git config --list [email protected] user.name=Michael Fong core.editor=vim ... 4 . 2
  • 13. Clone RepositoryClone Repository $ git clone https://github.com/<username>/<project> Clone repository via Https $ git clone ssh://github.com/<username>/<project> Clone repository via SSH Show current repository status $ git status On branch <local-repo> Your branch is up-to-date with <remote-repo>. nothing to commit, working directory clean <If there is (new) file different from current ver, they will appear here> # Diff against local workspace and index $ git diff 4 . 3
  • 14. Commit ChangesCommit Changes # add new files $ git add 1.file # add by pattern $ git add *.file # add by everything under directory $ git add ./ $ git add -all # remove file from tracking $ git rm file.py # Diff against local repo and index $ git diff --cached Staging Changes Update to local Staging Area / Index Commit Changes Update to local repo # Enter commit commit description in default editor $ git commit # alternatively, one command commit $ git commit -am "Enter your commit description" 4 . 4
  • 15. Branch ManagementBranch Management # create a new branch $ git checkout master $ git branch new-branch # Alternatively, create a new branch from remote-repo/remote-branch $ git checkout <remote-repo>/<remote-branch> -b <local-branch> $ git checkout origin/master -b new-branch #Create a new branch from tag $ git checkout tags/<tag-name> -b new-branch Create a new local branch Switch to existing local branch List all Branches $ git checkout new-branch # (noarg - local branch; -r remote branch; -a all branch) $ git branch -av Delete Branch # Delete local repository $ git branch -d new-branch # Delete local repository by force $ git branch -D new-branch # Delete a branch from remote repository $ git push <remote-repo> :<branch-name> 4 . 5
  • 16. Remote CommandRemote Command # Add a new remote repo $ git remote add origin <GIT_URL_HTTPS_or_SSH> # Update an existing remote repo $ git remote update origin <GIT_URL_HTTPS_or_SSH> Push to remote repo:branch # Fetch & Merge $ git pull # Fetch from remote repo $ git fetch origin # Merge from remote branch master $ git merge origin master Pull from remote repository Add / Update a remote repository # push to remote-repo (origin) / remote-branch (master) $ git push <remote-repo> <local-branch>:<remote-branch> $ git push origin master:master $ git push origin master $ git push origin new-branch:new-branch 4 . 6
  • 17. (Local Branch) Merge Strategy I(Local Branch) Merge Strategy I Fast Forward Merge When the merge resolves as a fast-forward, only update the branch pointer, without creating a merge commit. Default merge strategy $ git checkout master $ git merge new-branch (--ff) 4 . 7
  • 18. (Local Branch) Merge Strategy II(Local Branch) Merge Strategy II Non Fast Forward Merge Create a merge commit $ git checkout master $ git merge new-branch --no-ff 4 . 8
  • 19. (Local Branch) Merge Strategy II(Local Branch) Merge Strategy II Merge Commit $ git checkout -b new-branch $ git commit -am 'commit' $ git checkout master $ git merge new-branch --no-ff $ git log commit 33a935fb06182ba9c6868a9bf85efe7c2e5770f3 Merge: 1d9f153 efd5daa Author: XXX Date: Mon Nov 26 11:41:25 2018 +0800 Merge branch 'new-branch' commit efd5daabfc1d4366f197dc71c3edfd251b0396d0 Author: XXX Date: Mon Nov 26 11:41:00 2018 +0800 commit 2018-11-26 11:41 Michael Fong M─┐ [master] Merge branch 'new-branch' 2018-11-26 11:41 Michael Fong │ o commit 2018-11-21 15:58 Michael Fong o─┘ {origin/master} {origin/HEAD} Branching graph 4 . 9
  • 20. (Remote Branch) Merge(Remote Branch) Merge Merge between two branch on remote repository Github: Pull Request Gitlab: Merge Request Non fast forward merge Default strategy for merging PR Usually configurableg 4 . 10
  • 21. Merge StrategyMerge Strategy Log Branch Graph Fast Forward Clean Less intuitive No Fast Forward Merge commit More intuitive 4 . 11
  • 22. Merge ConflictsMerge Conflicts Manual intervention is required.   After self correction is done; add and commit the conflict files. $ git add index.html $ git commit 4 . 12
  • 23. Rebase IRebase I Moving a branch onto a new base commit Rebasing onto master will take all commits from master and apply your branch commits on top one by one. Later could combine with merge to master 4 . 13
  • 24. Rebase IIRebase II If combined with squash, there will possibly be only one commit. 4 . 14
  • 25. Squash ISquash I squash is a mechanism to consolidate multiple commit into one. It comes with rebase / merge command 4 . 15
  • 26. Squash IISquash II pick commit1 (528f601) squash  commit2 (a96173c) edit commit3 (eadd9c2) 4 . 16
  • 27. Squash IIISquash III Squashing commit 2 into commit 1 4 . 17
  • 28. Squash IVSquash IV Edit commit 3 4 . 18
  • 29. Cherry PickCherry Pick Given one or more existing commits, apply the change each one introduces, recording a new commit for each. $ git cherry-pick C2 C4 4 . 19
  • 30. TagTag Annotation to represent release Create a tag List all tags $ git tag -a <tag-name> -m 'description' $ git push <remote-repo> <tag-name> $ git tag -l Show tag metadata $ git show <tag-name> Delete a tag $ git tag -d <tag-name> $ git push <remote-repo> <tag-name> 4 . 20
  • 32. StashStash How to save unfinished implementation temporarily? Save the current state of work. # Save current work, and rollback to HEAD keep current work space clean $ git stash -u # Reload latest stash record $ git stash pop # List stash record $ git stash list 5 . 2
  • 33. Undo Commit IUndo Commit I $ git reset --soft HEAD~1 $ git diff --cached $ git reset HEAD~1 $ git diff $ git reset --hard HEAD~1 Reset current HEAD to the specific state Changes are UNSTAGED Changes are STAGED  Changes are REMOVED from log 5 . 3
  • 34. Undo Commit IIUndo Commit II $ git checkout path/to/filename $ git revert commit-hash Reverts a commit with another commit   Restores the file to the latest version in HEAD, changes are dropped 5 . 4
  • 35. Reference LogReference Log Historical records when the tips of branches and other references were updated in the LOCAL repository. Helpful when you want to look up historical commit $ git reflog Maybe your last resort to undo bad commit Use at your RISK! $ git reset --hard HEAD@{n} 5 . 5
  • 36. Bash Alias IBash Alias I # Nice format for `git log` alias git.log="git log --graph --abbrev-commit --decorate -- format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset) %C(bold cyan) (committed: %cD)%C(reset) %C(auto)%d%C(reset)%n''          %C(white)%s%C(reset)%n''          %C(dim white)- %an <%ae> %C(reset) %C(dim white)(committer: %cn <%ce>)%C(reset)' --all" * 059806c - Fri, 9 Nov 2018 17:31:31 +0800 (2 days ago) (committed: Fri, 9 Nov 2018 17:31:31 +080 | Add unit test to ByteBuf | - Michael Fong <[email protected]> (committer: Michael Fong <[email protected] | * f5832fa - Fri, 9 Nov 2018 12:35:40 +0800 (2 days ago) (committed: Fri, 9 Nov 2018 12:35:40 +0 | | squash | | - Michael Fong <[email protected]> (committer: Michael Fong <mcfong.open@gmail | * f5f556a - Tue, 6 Nov 2018 19:54:47 +0800 (5 days ago) (committed: Thu, 8 Nov 2018 20:49:30 +0 |/ Add fadvise64 | - Michael Fong <[email protected]> (committer: Michael Fong <mcfong.open@gmail * 91e622c - Thu, 8 Nov 2018 20:26:33 +0800 (3 days ago) (committed: Thu, 8 Nov 2018 20:42:14 +080 | Copy libnative-utility.so to target/classes for java-jni | - Michael Fong <[email protected]> (committer: Michael Fong <[email protected] * 794bf26 - Wed, 7 Nov 2018 16:18:03 +0800 (4 days ago) (committed: Thu, 8 Nov 2018 00:45:32 +080 5 . 6
  • 37. tigtig Installation $ sudo apt-get install tig log $ tig log “ ncurses-based text-mode interface for git. status $ tig status 5 . 7
  • 39. ProblemsProblems Everyone has a copy. Unfortunately, NOT the same copy! Which master is more up to date? Requiring Discipline Methodology 6 . 2
  • 40. Ref Git Flow MethodologyGit Flow Methodology 6 . 3
  • 41. Branching ModelsBranching Models master  - ONE true MASTER develop feature Feature branches typically exist in developer repos only, not in origin release Release branches support preparation of a new production release. hot-fix  When a critical bug in a production version must be resolved immediately, a hotfix branch may be branched off from the corresponding tag on the master branch that marks the production version. 6 . 4
  • 42. ToolTool Provide high level operation github/git-flow/ Git Flow cheatsheet 6 . 5
  • 43. ReferenceReference Linux Travolds on git Git-Basics Learn How to Git tig https://www.youtube.com/embed/4XpnKHJ Aok8?enablejsapi=1 7