SlideShare a Scribd company logo
Fundamentals of Git
By Zachary Ling
29th, Aug, 2011
1
Outline
• History of Git
• Distributed V.S Centralized Version Control
• Getting started
• Branching and Merging
• Working with remote
• Summary
2
A Brief History of Git
• Linus uses BitKeeper to manage Linux code
• Ran into BitKeeper licensing issue
– Liked functionality
– Looked at CVS as how not to do things
• April 5, 2005 - Linus sends out email showing first
version
• June 15, 2005 - Git used for Linux version control
3
Git is Not an SCM
Never mind merging. It's not an SCM, it's a
distribution and archival mechanism. I bet you
could make a reasonable SCM on top of it,
though. Another way of looking at it is to say
that it's really a content-addressable
filesystem, used to track directory trees.
Linus Torvalds, 7 Apr 2005
http://lkml.org/lkml/2005/4/8/9
4
Centralized Version Control
• Traditional version control system
– Server with database
– Clients have a working version
• Examples
– CVS
– Subversion
– Visual Source Safe
• Challenges
– Multi-developer conflicts
– Client/server communication
5
Distributed Version Control
• Authoritative server by
convention only
• Every working checkout
is a repository
• Get version control
even when detached
• Backups are trivial
• Other distributed
systems include
– Mercurial
– BitKeeper
– Darcs
– Bazaar
6
7
8
9
10
Git Advantages
• Resilience
– No one repository has more data than any other
• Speed
– Very fast operations compared to other VCS (I’m looking at you CVS
and Subversion)
• Space
– Compression can be done across repository not just per file
– Minimizes local size as well as push/pull data transfers
• Simplicity
– Object model is very simple
• Large userbase with robust tools
11
Some GIT Disadvantages
• Definite learning curve, especially for those used to
centralized systems
– Can sometimes seem overwhelming to learn
• Conceptual difference
• Huge amount of commends
12
Getting Started
• Git use snapshot storage
13
Getting Started
• Three trees of Git
– The HEAD
• last commit snapshot, next parent
– Index
• Proposed next commit snapshot
– Working directory
• Sandbox
14
Getting Started
• A basic workflow
– (Possible init or clone) Init a repo
– Edit files
– Stage the changes
– Review your changes
– Commit the changes
15
Getting Started
• Init a repository • Git init
zachary@zachary-desktop:~/code/gitdemo$ git init
Initialized empty Git repository in /home/zachary/code/gitdemo/.git/
zachary@zachary-desktop:~/code/gitdemo$ ls -l .git/
total 32
drwxr-xr-x 2 zachary zachary 4096 2011-08-28 14:51 branches
-rw-r--r-- 1 zachary zachary 92 2011-08-28 14:51 config
-rw-r--r-- 1 zachary zachary 73 2011-08-28 14:51 description
-rw-r--r-- 1 zachary zachary 23 2011-08-28 14:51 HEAD
drwxr-xr-x 2 zachary zachary 4096 2011-08-28 14:51 hooks
drwxr-xr-x 2 zachary zachary 4096 2011-08-28 14:51 info
drwxr-xr-x 4 zachary zachary 4096 2011-08-28 14:51 objects
drwxr-xr-x 4 zachary zachary 4096 2011-08-28 14:51 refs
16
Getting Started
• A basic workflow
– Edit files
– Stage the changes
– Review your changes
– Commit the changes
• Use your favorite editor
17
Getting Started
• A basic workflow
– Edit files
– Stage the changes
– Review your changes
– Commit the changes
• Git add filename
zachary@zachary-desktop:~/code/gitdemo$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: hello.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
18
Getting Started
• A basic workflow
– Edit files
– Stage the changes
– Review your changes
– Commit the changes
• Git status
zachary@zachary-desktop:~/code/gitdemo$ git add hello.txt
zachary@zachary-desktop:~/code/gitdemo$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: hello.txt
#
19
Getting Started
• A basic workflow
– Edit files
– Stage the changes
– Review your changes
– Commit the changes
• Git commit
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: hello.txt
#
20
Getting Started
• A basic workflow
– Edit files
– Stage the changes
– Review your changes
– Commit the changes
21
Getting Started
• View changes
• Git diff
– Show the difference
between working
directory and staged
• Git diff --cached
– Show the difference
between staged and the
HEAD
• View history
• Git log
zachary@zachary-desktop:~/code/gitdemo$ git log
commit efb3aeae66029474e28273536a8f52969d705d04
Author: Zachary Ling <zacling@gmail.com>
Date: Sun Aug 28 15:02:08 2011 +0800
Add second line
commit 453914143eae3fc5a57b9504343e2595365a7357
Author: Zachary Ling <zacling@gmail.com>
Date: Sun Aug 28 14:59:13 2011 +0800
Initial commit
22
Getting Started
• Revert changes (Get back to a previous version)
– Git checkout commit_hash
zachary@zachary-desktop:~/code/gitdemo$ git log
commit efb3aeae66029474e28273536a8f52969d705d04
Author: Zachary Ling <zacling@gmail.com>
Date: Sun Aug 28 15:02:08 2011 +0800
Add second line
commit 453914143eae3fc5a57b9504343e2595365a7357
Author: Zachary Ling <zacling@gmail.com>
Date: Sun Aug 28 14:59:13 2011 +0800
Initial commit
zachary@zachary-desktop:~/code/gitdemo$ git checkout 4539
Note: checking out '4539'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
HEAD is now at 4539141... Initial commit
23
Branching
• Git sees commit this way…
• Branch annotates which commit we are
working on
24
Branching
25
26
27
28
29
30
31
32
33
Merging
• What do we do with this mess?
– Merge them
34
Merging
• Steps to merge two branch
– Checkout the branch you want to merge onto
– Merge the branch you want to merge
35
36
37
38
39
40
41
Branching and Merging
• Why this is cool?
– Non-linear development
clone the code that is in production
create a branch for issue #53 (iss53)
work for 10 minutes
someone asks for a hotfix for issue #102
checkout ‘production’
create a branch (iss102)
fix the issue
checkout ‘production’, merge ‘iss102’
push ‘production’
checkout ‘iss53’ and keep working
42
Working with remote
• Use git clone to replicate
repository
• Get changes with
– git fetch
– git pull (fetches and merges)
• Propagate changes with
– git push
• Protocols
– Local filesystem (file://)
– SSH (ssh://)
– HTTP (http:// https://)
– Git protocol (git://)
43
Working with remote
Local filesystem
• Pros
– Simple
– Support existing access
control
– NFS enabled
• Cons
– Public share is difficult to
set up
– Slow on top of NFS
44
Working with remote
SSH
• Pros
– Support authenticated
write access
– Easy to set up as most
system provide ssh
toolsets
– Fast
• Compression before
transfer
• Cons
– No anonymous access
• Not even for read access
45
Working with remote
GIT
• Pros
– Fastest protocal
– Allow public anonymous
access
• Cons
– Lack of authentication
– Difficult to set up
– Use port 9418
• Not standard port
• Can be blocked
46
Working with remote
HTTP/HTTPS
• Pros
– Very easy to set up
– Unlikely to be blocked
• Using standard port
• Cons
– Inefficient
47
Working with remote
• One person project
– Local repo is enough
– No need to bother with
remote
• Small team project
– SSH write access for a
few core developers
– GIT public read access
48
Working with remote
• Use git remote add to add an remote
repository
Git remote add origin git@github.com:FreezingGod/vimcfg.git
zachary@zachary-desktop:~/.vim_runtime$ git remote
origin
49
Working with remote
• Remote branching
– Branch on remote are different from local branch
50
Working with remote
• Remote branching
– Branch on remote are
different from local
branch
– Git fetch origin to get
remote changes
– Git pull origin try to fetch
reomte changes and
merge it onto current
branch
51
Working with remote
• Git push remote_name branch_name
– Share your work done on branch_name to remote
remote_name
52
Summary
• We covered fundamentals of Git
– Three trees of git
• HEAD, INDEX and working directory
– Basic work flow
• Modify, stage and commit cycle
– Branching and merging
• Branch and merge
– Remote
• Add remote, push, pull, fetch
– Other commands
• Revert change, history view
53
Summary
• However, this is by no means a complete portray
of git, some advanced topics are skipped:
– Rebasing
– Commit amend
– Distributed workflow
• For more information, consult
– Official document
– Pro Git
• Free book available at http://progit.org/book/
54
Q&A
• Any questions?
55
References
• Some of the slides are adopted from
“Introduction to Git” available at
http://innovationontherun.com/presentation-
files/Introduction%20To%20GIT.ppt
• Some of the figure are adopted from Pro GIT by
Chacon, which is available at
http://progit.org/book/
• Some of the slides are adopted from “Git 101”
available at
http://assets.en.oreilly.com/1/event/45/Git%201
01%20Tutorial%20Presentation.pdf
56
Ad

More Related Content

Similar to Fundamentals and basics of Git and commands (20)

tech winter break workshop on git &git hub.pptx
tech winter break workshop on git &git hub.pptxtech winter break workshop on git &git hub.pptx
tech winter break workshop on git &git hub.pptx
ashishraulin
 
Git training v10
Git training v10Git training v10
Git training v10
Skander Hamza
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configuration
Kishor Kumar
 
Essential git for developers
Essential git for developersEssential git for developers
Essential git for developers
Aidan Casey
 
Git tips and tricks
Git   tips and tricksGit   tips and tricks
Git tips and tricks
Chris Ballance
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
Amit Mathur
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
glen_a_smith
 
Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners
HubSpot
 
git and github
git and githubgit and github
git and github
Darren Oakley
 
An introduction to Git
An introduction to GitAn introduction to Git
An introduction to Git
Muhil Vannan
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
Max Claus Nunes
 
Git Introductive
Git IntroductiveGit Introductive
Git Introductive
Adham Saad
 
GIT INTRODUCTION
GIT INTRODUCTIONGIT INTRODUCTION
GIT INTRODUCTION
MohanRaviRohitth
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
Roland Emmanuel Salunga
 
Demo
DemoDemo
Demo
Miracle Anyanwu
 
Mini git tutorial
Mini git tutorialMini git tutorial
Mini git tutorial
Cristian Lucchesi
 
Talk to git
Talk to gitTalk to git
Talk to git
YenTing Chen
 
Git Workflow
Git WorkflowGit Workflow
Git Workflow
Gary Yeh
 
Learn Git - For Beginners and Intermediate levels
Learn Git - For Beginners and Intermediate levelsLearn Git - For Beginners and Intermediate levels
Learn Git - For Beginners and Intermediate levels
Gorav Singal
 
Techoalien git
Techoalien gitTechoalien git
Techoalien git
Aditya Tiwari
 
tech winter break workshop on git &git hub.pptx
tech winter break workshop on git &git hub.pptxtech winter break workshop on git &git hub.pptx
tech winter break workshop on git &git hub.pptx
ashishraulin
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configuration
Kishor Kumar
 
Essential git for developers
Essential git for developersEssential git for developers
Essential git for developers
Aidan Casey
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
Amit Mathur
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
glen_a_smith
 
Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners
HubSpot
 
An introduction to Git
An introduction to GitAn introduction to Git
An introduction to Git
Muhil Vannan
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
Max Claus Nunes
 
Git Introductive
Git IntroductiveGit Introductive
Git Introductive
Adham Saad
 
Git Workflow
Git WorkflowGit Workflow
Git Workflow
Gary Yeh
 
Learn Git - For Beginners and Intermediate levels
Learn Git - For Beginners and Intermediate levelsLearn Git - For Beginners and Intermediate levels
Learn Git - For Beginners and Intermediate levels
Gorav Singal
 

More from DivyanshGupta922023 (19)

Git mercurial - Git basics , features and commands
Git mercurial - Git basics , features and commandsGit mercurial - Git basics , features and commands
Git mercurial - Git basics , features and commands
DivyanshGupta922023
 
(Public) FedCM BlinkOn 16 fedcm and privacy sandbox apis
(Public) FedCM BlinkOn 16 fedcm and privacy sandbox apis(Public) FedCM BlinkOn 16 fedcm and privacy sandbox apis
(Public) FedCM BlinkOn 16 fedcm and privacy sandbox apis
DivyanshGupta922023
 
DevOps The Buzzword - everything about devops
DevOps The Buzzword - everything about devopsDevOps The Buzzword - everything about devops
DevOps The Buzzword - everything about devops
DivyanshGupta922023
 
Git Basics walkthough to all basic concept and commands of git
Git Basics walkthough to all basic concept and commands of gitGit Basics walkthough to all basic concept and commands of git
Git Basics walkthough to all basic concept and commands of git
DivyanshGupta922023
 
jquery summit presentation for large scale javascript applications
jquery summit  presentation for large scale javascript applicationsjquery summit  presentation for large scale javascript applications
jquery summit presentation for large scale javascript applications
DivyanshGupta922023
 
Next.js - ReactPlayIO.pptx
Next.js - ReactPlayIO.pptxNext.js - ReactPlayIO.pptx
Next.js - ReactPlayIO.pptx
DivyanshGupta922023
 
Management+team.pptx
Management+team.pptxManagement+team.pptx
Management+team.pptx
DivyanshGupta922023
 
DHC Microbiome Presentation 4-23-19.pptx
DHC Microbiome Presentation 4-23-19.pptxDHC Microbiome Presentation 4-23-19.pptx
DHC Microbiome Presentation 4-23-19.pptx
DivyanshGupta922023
 
developer-burnout.pdf
developer-burnout.pdfdeveloper-burnout.pdf
developer-burnout.pdf
DivyanshGupta922023
 
AzureIntro.pptx
AzureIntro.pptxAzureIntro.pptx
AzureIntro.pptx
DivyanshGupta922023
 
api-driven-development.pdf
api-driven-development.pdfapi-driven-development.pdf
api-driven-development.pdf
DivyanshGupta922023
 
Internet of Things.pptx
Internet of Things.pptxInternet of Things.pptx
Internet of Things.pptx
DivyanshGupta922023
 
Functional JS+ ES6.pptx
Functional JS+ ES6.pptxFunctional JS+ ES6.pptx
Functional JS+ ES6.pptx
DivyanshGupta922023
 
AAAI19-Open.pptx
AAAI19-Open.pptxAAAI19-Open.pptx
AAAI19-Open.pptx
DivyanshGupta922023
 
10-security-concepts-lightning-talk 1of2.pptx
10-security-concepts-lightning-talk 1of2.pptx10-security-concepts-lightning-talk 1of2.pptx
10-security-concepts-lightning-talk 1of2.pptx
DivyanshGupta922023
 
Introduction to Directed Acyclic Graphs.pptx
Introduction to Directed Acyclic Graphs.pptxIntroduction to Directed Acyclic Graphs.pptx
Introduction to Directed Acyclic Graphs.pptx
DivyanshGupta922023
 
ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptx
DivyanshGupta922023
 
01-React js Intro.pptx
01-React js Intro.pptx01-React js Intro.pptx
01-React js Intro.pptx
DivyanshGupta922023
 
Nextjs13.pptx
Nextjs13.pptxNextjs13.pptx
Nextjs13.pptx
DivyanshGupta922023
 
Git mercurial - Git basics , features and commands
Git mercurial - Git basics , features and commandsGit mercurial - Git basics , features and commands
Git mercurial - Git basics , features and commands
DivyanshGupta922023
 
(Public) FedCM BlinkOn 16 fedcm and privacy sandbox apis
(Public) FedCM BlinkOn 16 fedcm and privacy sandbox apis(Public) FedCM BlinkOn 16 fedcm and privacy sandbox apis
(Public) FedCM BlinkOn 16 fedcm and privacy sandbox apis
DivyanshGupta922023
 
DevOps The Buzzword - everything about devops
DevOps The Buzzword - everything about devopsDevOps The Buzzword - everything about devops
DevOps The Buzzword - everything about devops
DivyanshGupta922023
 
Git Basics walkthough to all basic concept and commands of git
Git Basics walkthough to all basic concept and commands of gitGit Basics walkthough to all basic concept and commands of git
Git Basics walkthough to all basic concept and commands of git
DivyanshGupta922023
 
jquery summit presentation for large scale javascript applications
jquery summit  presentation for large scale javascript applicationsjquery summit  presentation for large scale javascript applications
jquery summit presentation for large scale javascript applications
DivyanshGupta922023
 
DHC Microbiome Presentation 4-23-19.pptx
DHC Microbiome Presentation 4-23-19.pptxDHC Microbiome Presentation 4-23-19.pptx
DHC Microbiome Presentation 4-23-19.pptx
DivyanshGupta922023
 
10-security-concepts-lightning-talk 1of2.pptx
10-security-concepts-lightning-talk 1of2.pptx10-security-concepts-lightning-talk 1of2.pptx
10-security-concepts-lightning-talk 1of2.pptx
DivyanshGupta922023
 
Introduction to Directed Acyclic Graphs.pptx
Introduction to Directed Acyclic Graphs.pptxIntroduction to Directed Acyclic Graphs.pptx
Introduction to Directed Acyclic Graphs.pptx
DivyanshGupta922023
 
Ad

Recently uploaded (20)

ICSE 2025 Keynote: Software Sustainability and its Engineering: How far have ...
ICSE 2025 Keynote: Software Sustainability and its Engineering: How far have ...ICSE 2025 Keynote: Software Sustainability and its Engineering: How far have ...
ICSE 2025 Keynote: Software Sustainability and its Engineering: How far have ...
patricialago3459
 
Setup & Implementation of OutSystems Cloud Connector ODC
Setup & Implementation of OutSystems Cloud Connector ODCSetup & Implementation of OutSystems Cloud Connector ODC
Setup & Implementation of OutSystems Cloud Connector ODC
outsystemspuneusergr
 
THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...
THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...
THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...
ASHISHKUMAR504404
 
APEC - POWER POINT.pptxtrabajo de investig
APEC - POWER POINT.pptxtrabajo de investigAPEC - POWER POINT.pptxtrabajo de investig
APEC - POWER POINT.pptxtrabajo de investig
MyriamRaquelCoronado
 
Yellow and Black Modern Minimalist Workshop Presentation.pptx
Yellow and Black Modern Minimalist Workshop Presentation.pptxYellow and Black Modern Minimalist Workshop Presentation.pptx
Yellow and Black Modern Minimalist Workshop Presentation.pptx
alibabattying
 
Hartcliffe Betrayed Bristol Radical History Festival April 2025.pptx
Hartcliffe Betrayed Bristol Radical History Festival April 2025.pptxHartcliffe Betrayed Bristol Radical History Festival April 2025.pptx
Hartcliffe Betrayed Bristol Radical History Festival April 2025.pptx
Paul Smith
 
CAE. final pptx.pptx h
CAE. final pptx.pptx                        hCAE. final pptx.pptx                        h
CAE. final pptx.pptx h
Test761
 
Key Elements of a Procurement Plan.docx.
Key Elements of a Procurement Plan.docx.Key Elements of a Procurement Plan.docx.
Key Elements of a Procurement Plan.docx.
NeoRakodu
 
2025-05-04 A New Day Dawns 03 (shared slides).pptx
2025-05-04 A New Day Dawns 03 (shared slides).pptx2025-05-04 A New Day Dawns 03 (shared slides).pptx
2025-05-04 A New Day Dawns 03 (shared slides).pptx
Dale Wells
 
The Business Dynamics of Quick Commerce.pdf
The Business Dynamics of Quick Commerce.pdfThe Business Dynamics of Quick Commerce.pdf
The Business Dynamics of Quick Commerce.pdf
RDinuRao
 
Sermon_How To Change Your Life For Better_2.0.pptx
Sermon_How To Change Your Life For Better_2.0.pptxSermon_How To Change Your Life For Better_2.0.pptx
Sermon_How To Change Your Life For Better_2.0.pptx
oxofoegbu
 
Profit Growth Drivers for Small Business.pdf
Profit Growth Drivers for Small Business.pdfProfit Growth Drivers for Small Business.pdf
Profit Growth Drivers for Small Business.pdf
TheodoreHawkins
 
NASIG ISSN 2025 updated for the_4-30meeting.pptx
NASIG ISSN 2025 updated for the_4-30meeting.pptxNASIG ISSN 2025 updated for the_4-30meeting.pptx
NASIG ISSN 2025 updated for the_4-30meeting.pptx
reine1
 
Bidding World Conference 2027 - Ghana.pptx
Bidding World Conference 2027 - Ghana.pptxBidding World Conference 2027 - Ghana.pptx
Bidding World Conference 2027 - Ghana.pptx
ISGF - International Scout and Guide Fellowship
 
Basic.pptxsksdjsdjdvkfvfvfvfvfvfvfvfvfvvvv
Basic.pptxsksdjsdjdvkfvfvfvfvfvfvfvfvfvvvvBasic.pptxsksdjsdjdvkfvfvfvfvfvfvfvfvfvvvv
Basic.pptxsksdjsdjdvkfvfvfvfvfvfvfvfvfvvvv
hkthmrz42n
 
Testing-Special-Populations-Infants-and-Preschoolers.pptx
Testing-Special-Populations-Infants-and-Preschoolers.pptxTesting-Special-Populations-Infants-and-Preschoolers.pptx
Testing-Special-Populations-Infants-and-Preschoolers.pptx
TayyabaSiddiqui13
 
2025-04-27 A New Day Dawns 02 (shared slides).pptx
2025-04-27 A New Day Dawns 02 (shared slides).pptx2025-04-27 A New Day Dawns 02 (shared slides).pptx
2025-04-27 A New Day Dawns 02 (shared slides).pptx
Dale Wells
 
Microsoft Azure Data Fundamentals (DP-900) Exam Dumps & Questions 2025.pdf
Microsoft Azure Data Fundamentals (DP-900) Exam Dumps & Questions 2025.pdfMicrosoft Azure Data Fundamentals (DP-900) Exam Dumps & Questions 2025.pdf
Microsoft Azure Data Fundamentals (DP-900) Exam Dumps & Questions 2025.pdf
MinniePfeiffer
 
kurtlewin theory of motivation -181226082203.pptx
kurtlewin theory of motivation -181226082203.pptxkurtlewin theory of motivation -181226082203.pptx
kurtlewin theory of motivation -181226082203.pptx
TayyabaSiddiqui12
 
Speech 3-A Vision for Tomorrow for GE2025
Speech 3-A Vision for Tomorrow for GE2025Speech 3-A Vision for Tomorrow for GE2025
Speech 3-A Vision for Tomorrow for GE2025
Noraini Yunus
 
ICSE 2025 Keynote: Software Sustainability and its Engineering: How far have ...
ICSE 2025 Keynote: Software Sustainability and its Engineering: How far have ...ICSE 2025 Keynote: Software Sustainability and its Engineering: How far have ...
ICSE 2025 Keynote: Software Sustainability and its Engineering: How far have ...
patricialago3459
 
Setup & Implementation of OutSystems Cloud Connector ODC
Setup & Implementation of OutSystems Cloud Connector ODCSetup & Implementation of OutSystems Cloud Connector ODC
Setup & Implementation of OutSystems Cloud Connector ODC
outsystemspuneusergr
 
THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...
THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...
THE SEXUAL HARASSMENT OF WOMAN AT WORKPLACE (PREVENTION, PROHIBITION & REDRES...
ASHISHKUMAR504404
 
APEC - POWER POINT.pptxtrabajo de investig
APEC - POWER POINT.pptxtrabajo de investigAPEC - POWER POINT.pptxtrabajo de investig
APEC - POWER POINT.pptxtrabajo de investig
MyriamRaquelCoronado
 
Yellow and Black Modern Minimalist Workshop Presentation.pptx
Yellow and Black Modern Minimalist Workshop Presentation.pptxYellow and Black Modern Minimalist Workshop Presentation.pptx
Yellow and Black Modern Minimalist Workshop Presentation.pptx
alibabattying
 
Hartcliffe Betrayed Bristol Radical History Festival April 2025.pptx
Hartcliffe Betrayed Bristol Radical History Festival April 2025.pptxHartcliffe Betrayed Bristol Radical History Festival April 2025.pptx
Hartcliffe Betrayed Bristol Radical History Festival April 2025.pptx
Paul Smith
 
CAE. final pptx.pptx h
CAE. final pptx.pptx                        hCAE. final pptx.pptx                        h
CAE. final pptx.pptx h
Test761
 
Key Elements of a Procurement Plan.docx.
Key Elements of a Procurement Plan.docx.Key Elements of a Procurement Plan.docx.
Key Elements of a Procurement Plan.docx.
NeoRakodu
 
2025-05-04 A New Day Dawns 03 (shared slides).pptx
2025-05-04 A New Day Dawns 03 (shared slides).pptx2025-05-04 A New Day Dawns 03 (shared slides).pptx
2025-05-04 A New Day Dawns 03 (shared slides).pptx
Dale Wells
 
The Business Dynamics of Quick Commerce.pdf
The Business Dynamics of Quick Commerce.pdfThe Business Dynamics of Quick Commerce.pdf
The Business Dynamics of Quick Commerce.pdf
RDinuRao
 
Sermon_How To Change Your Life For Better_2.0.pptx
Sermon_How To Change Your Life For Better_2.0.pptxSermon_How To Change Your Life For Better_2.0.pptx
Sermon_How To Change Your Life For Better_2.0.pptx
oxofoegbu
 
Profit Growth Drivers for Small Business.pdf
Profit Growth Drivers for Small Business.pdfProfit Growth Drivers for Small Business.pdf
Profit Growth Drivers for Small Business.pdf
TheodoreHawkins
 
NASIG ISSN 2025 updated for the_4-30meeting.pptx
NASIG ISSN 2025 updated for the_4-30meeting.pptxNASIG ISSN 2025 updated for the_4-30meeting.pptx
NASIG ISSN 2025 updated for the_4-30meeting.pptx
reine1
 
Basic.pptxsksdjsdjdvkfvfvfvfvfvfvfvfvfvvvv
Basic.pptxsksdjsdjdvkfvfvfvfvfvfvfvfvfvvvvBasic.pptxsksdjsdjdvkfvfvfvfvfvfvfvfvfvvvv
Basic.pptxsksdjsdjdvkfvfvfvfvfvfvfvfvfvvvv
hkthmrz42n
 
Testing-Special-Populations-Infants-and-Preschoolers.pptx
Testing-Special-Populations-Infants-and-Preschoolers.pptxTesting-Special-Populations-Infants-and-Preschoolers.pptx
Testing-Special-Populations-Infants-and-Preschoolers.pptx
TayyabaSiddiqui13
 
2025-04-27 A New Day Dawns 02 (shared slides).pptx
2025-04-27 A New Day Dawns 02 (shared slides).pptx2025-04-27 A New Day Dawns 02 (shared slides).pptx
2025-04-27 A New Day Dawns 02 (shared slides).pptx
Dale Wells
 
Microsoft Azure Data Fundamentals (DP-900) Exam Dumps & Questions 2025.pdf
Microsoft Azure Data Fundamentals (DP-900) Exam Dumps & Questions 2025.pdfMicrosoft Azure Data Fundamentals (DP-900) Exam Dumps & Questions 2025.pdf
Microsoft Azure Data Fundamentals (DP-900) Exam Dumps & Questions 2025.pdf
MinniePfeiffer
 
kurtlewin theory of motivation -181226082203.pptx
kurtlewin theory of motivation -181226082203.pptxkurtlewin theory of motivation -181226082203.pptx
kurtlewin theory of motivation -181226082203.pptx
TayyabaSiddiqui12
 
Speech 3-A Vision for Tomorrow for GE2025
Speech 3-A Vision for Tomorrow for GE2025Speech 3-A Vision for Tomorrow for GE2025
Speech 3-A Vision for Tomorrow for GE2025
Noraini Yunus
 
Ad

Fundamentals and basics of Git and commands

  • 1. Fundamentals of Git By Zachary Ling 29th, Aug, 2011 1
  • 2. Outline • History of Git • Distributed V.S Centralized Version Control • Getting started • Branching and Merging • Working with remote • Summary 2
  • 3. A Brief History of Git • Linus uses BitKeeper to manage Linux code • Ran into BitKeeper licensing issue – Liked functionality – Looked at CVS as how not to do things • April 5, 2005 - Linus sends out email showing first version • June 15, 2005 - Git used for Linux version control 3
  • 4. Git is Not an SCM Never mind merging. It's not an SCM, it's a distribution and archival mechanism. I bet you could make a reasonable SCM on top of it, though. Another way of looking at it is to say that it's really a content-addressable filesystem, used to track directory trees. Linus Torvalds, 7 Apr 2005 http://lkml.org/lkml/2005/4/8/9 4
  • 5. Centralized Version Control • Traditional version control system – Server with database – Clients have a working version • Examples – CVS – Subversion – Visual Source Safe • Challenges – Multi-developer conflicts – Client/server communication 5
  • 6. Distributed Version Control • Authoritative server by convention only • Every working checkout is a repository • Get version control even when detached • Backups are trivial • Other distributed systems include – Mercurial – BitKeeper – Darcs – Bazaar 6
  • 7. 7
  • 8. 8
  • 9. 9
  • 10. 10
  • 11. Git Advantages • Resilience – No one repository has more data than any other • Speed – Very fast operations compared to other VCS (I’m looking at you CVS and Subversion) • Space – Compression can be done across repository not just per file – Minimizes local size as well as push/pull data transfers • Simplicity – Object model is very simple • Large userbase with robust tools 11
  • 12. Some GIT Disadvantages • Definite learning curve, especially for those used to centralized systems – Can sometimes seem overwhelming to learn • Conceptual difference • Huge amount of commends 12
  • 13. Getting Started • Git use snapshot storage 13
  • 14. Getting Started • Three trees of Git – The HEAD • last commit snapshot, next parent – Index • Proposed next commit snapshot – Working directory • Sandbox 14
  • 15. Getting Started • A basic workflow – (Possible init or clone) Init a repo – Edit files – Stage the changes – Review your changes – Commit the changes 15
  • 16. Getting Started • Init a repository • Git init zachary@zachary-desktop:~/code/gitdemo$ git init Initialized empty Git repository in /home/zachary/code/gitdemo/.git/ zachary@zachary-desktop:~/code/gitdemo$ ls -l .git/ total 32 drwxr-xr-x 2 zachary zachary 4096 2011-08-28 14:51 branches -rw-r--r-- 1 zachary zachary 92 2011-08-28 14:51 config -rw-r--r-- 1 zachary zachary 73 2011-08-28 14:51 description -rw-r--r-- 1 zachary zachary 23 2011-08-28 14:51 HEAD drwxr-xr-x 2 zachary zachary 4096 2011-08-28 14:51 hooks drwxr-xr-x 2 zachary zachary 4096 2011-08-28 14:51 info drwxr-xr-x 4 zachary zachary 4096 2011-08-28 14:51 objects drwxr-xr-x 4 zachary zachary 4096 2011-08-28 14:51 refs 16
  • 17. Getting Started • A basic workflow – Edit files – Stage the changes – Review your changes – Commit the changes • Use your favorite editor 17
  • 18. Getting Started • A basic workflow – Edit files – Stage the changes – Review your changes – Commit the changes • Git add filename zachary@zachary-desktop:~/code/gitdemo$ git status # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: hello.txt # no changes added to commit (use "git add" and/or "git commit -a") 18
  • 19. Getting Started • A basic workflow – Edit files – Stage the changes – Review your changes – Commit the changes • Git status zachary@zachary-desktop:~/code/gitdemo$ git add hello.txt zachary@zachary-desktop:~/code/gitdemo$ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: hello.txt # 19
  • 20. Getting Started • A basic workflow – Edit files – Stage the changes – Review your changes – Commit the changes • Git commit # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: hello.txt # 20
  • 21. Getting Started • A basic workflow – Edit files – Stage the changes – Review your changes – Commit the changes 21
  • 22. Getting Started • View changes • Git diff – Show the difference between working directory and staged • Git diff --cached – Show the difference between staged and the HEAD • View history • Git log zachary@zachary-desktop:~/code/gitdemo$ git log commit efb3aeae66029474e28273536a8f52969d705d04 Author: Zachary Ling <[email protected]> Date: Sun Aug 28 15:02:08 2011 +0800 Add second line commit 453914143eae3fc5a57b9504343e2595365a7357 Author: Zachary Ling <[email protected]> Date: Sun Aug 28 14:59:13 2011 +0800 Initial commit 22
  • 23. Getting Started • Revert changes (Get back to a previous version) – Git checkout commit_hash zachary@zachary-desktop:~/code/gitdemo$ git log commit efb3aeae66029474e28273536a8f52969d705d04 Author: Zachary Ling <[email protected]> Date: Sun Aug 28 15:02:08 2011 +0800 Add second line commit 453914143eae3fc5a57b9504343e2595365a7357 Author: Zachary Ling <[email protected]> Date: Sun Aug 28 14:59:13 2011 +0800 Initial commit zachary@zachary-desktop:~/code/gitdemo$ git checkout 4539 Note: checking out '4539'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b new_branch_name HEAD is now at 4539141... Initial commit 23
  • 24. Branching • Git sees commit this way… • Branch annotates which commit we are working on 24
  • 26. 26
  • 27. 27
  • 28. 28
  • 29. 29
  • 30. 30
  • 31. 31
  • 32. 32
  • 33. 33
  • 34. Merging • What do we do with this mess? – Merge them 34
  • 35. Merging • Steps to merge two branch – Checkout the branch you want to merge onto – Merge the branch you want to merge 35
  • 36. 36
  • 37. 37
  • 38. 38
  • 39. 39
  • 40. 40
  • 41. 41
  • 42. Branching and Merging • Why this is cool? – Non-linear development clone the code that is in production create a branch for issue #53 (iss53) work for 10 minutes someone asks for a hotfix for issue #102 checkout ‘production’ create a branch (iss102) fix the issue checkout ‘production’, merge ‘iss102’ push ‘production’ checkout ‘iss53’ and keep working 42
  • 43. Working with remote • Use git clone to replicate repository • Get changes with – git fetch – git pull (fetches and merges) • Propagate changes with – git push • Protocols – Local filesystem (file://) – SSH (ssh://) – HTTP (http:// https://) – Git protocol (git://) 43
  • 44. Working with remote Local filesystem • Pros – Simple – Support existing access control – NFS enabled • Cons – Public share is difficult to set up – Slow on top of NFS 44
  • 45. Working with remote SSH • Pros – Support authenticated write access – Easy to set up as most system provide ssh toolsets – Fast • Compression before transfer • Cons – No anonymous access • Not even for read access 45
  • 46. Working with remote GIT • Pros – Fastest protocal – Allow public anonymous access • Cons – Lack of authentication – Difficult to set up – Use port 9418 • Not standard port • Can be blocked 46
  • 47. Working with remote HTTP/HTTPS • Pros – Very easy to set up – Unlikely to be blocked • Using standard port • Cons – Inefficient 47
  • 48. Working with remote • One person project – Local repo is enough – No need to bother with remote • Small team project – SSH write access for a few core developers – GIT public read access 48
  • 49. Working with remote • Use git remote add to add an remote repository Git remote add origin [email protected]:FreezingGod/vimcfg.git zachary@zachary-desktop:~/.vim_runtime$ git remote origin 49
  • 50. Working with remote • Remote branching – Branch on remote are different from local branch 50
  • 51. Working with remote • Remote branching – Branch on remote are different from local branch – Git fetch origin to get remote changes – Git pull origin try to fetch reomte changes and merge it onto current branch 51
  • 52. Working with remote • Git push remote_name branch_name – Share your work done on branch_name to remote remote_name 52
  • 53. Summary • We covered fundamentals of Git – Three trees of git • HEAD, INDEX and working directory – Basic work flow • Modify, stage and commit cycle – Branching and merging • Branch and merge – Remote • Add remote, push, pull, fetch – Other commands • Revert change, history view 53
  • 54. Summary • However, this is by no means a complete portray of git, some advanced topics are skipped: – Rebasing – Commit amend – Distributed workflow • For more information, consult – Official document – Pro Git • Free book available at http://progit.org/book/ 54
  • 56. References • Some of the slides are adopted from “Introduction to Git” available at http://innovationontherun.com/presentation- files/Introduction%20To%20GIT.ppt • Some of the figure are adopted from Pro GIT by Chacon, which is available at http://progit.org/book/ • Some of the slides are adopted from “Git 101” available at http://assets.en.oreilly.com/1/event/45/Git%201 01%20Tutorial%20Presentation.pdf 56