SlideShare ist ein Scribd-Unternehmen logo
1 von 47
Downloaden Sie, um offline zu lesen
An Introduction to Git
Hiroyuki Vincent Yamazaki
2016-03-06
Target
• Version Control System (VCS) and Git beginners
• Developers using Git commands without knowing
what’s actually happening
Goal
• Familiar with VCS
• Basic understanding of how Git operates
• Can use basic Git commands and know what they
do to the filesystem
Content
• Version Control (VC)
• About Git
• Git in practice
What’s VC about?
- It’s about file history
> touch foo.js // Create a new file
… // Edit
> cp foo.js bar.js // Create a backup
… // Do something horrible
> cp bar.js foo.js // Revert to backup
File
Create foo.js
Time
Add Hello World
Remove unused functions
Clean up comments
The state of the file at 

a certain point in time
Current state
File
Current state
Time
The state of the file at 

a certain point in time
Create foo.js
Add Hello World
Remove unused functions
Clean up comments
File(s)
Time
A snapshot of the states of the

files at a certain point in time
Current state
Git
Git
Git ( ) is a VCS, a program that is run from
the CLI
> git <command>
First Git
Start a new project
> git init
Download an existing project
> git clone <url>
Overview
add
commit
checkout
Index / 

Staging

area
Local

repository
Local computer
Working
directory
add
commit
checkout
Index / 

Staging

area
Local

repository
Local computer
Working
directory
Files on your computer (file system)
Working
directory
add
commit
checkout
Local

repository
Local computer
Set of files to be included in the next
snapshot ( = snapshot )
Index / 

Staging

area
Index / 

Staging

area
Working
directory
add
commit
checkout
Local computer
Database of snapshots
Local

repository
add
commit
checkout
Index / 

Staging

area
Local

repository
Local computer
Working
directory
Add
Tell Git that a file is to be
included in the next snapshot
by adding it to the index /
staging area
> git add foo.js
foo.js
Index / 

Staging area
Commit
Take a new snapshot of the 

state of the files in the
staging area (append it to
the previous commit)
Store a snapshot in the local
repository
> git commit
Previous commit
New commitfoo.js
References
Git only creates new files when a file is modified
Files are not stored in a commit, but rather
references to files
foo.jsfoo.js
File foo.js Reference to foo.js
foo.js
v1
bar.js
v1
foo.js
v2
bar.js
v1
foo.js
v1
foo.js
v2
bar.js
v1
Files (blob)
They point to the same old file
(Only references)
Repository Commit

history
Inside a Commit
Commit Reference (SHA-1 checksum)

Author

Date

Message

Reference to parent commit(s)

Tree

Inside a Commit
Commit Reference (SHA-1 checksum)

Author

Date

Message

Reference to parent commit(s)

Tree

Includes the references to 

all the files in the snapshot
add
commit
checkout
Index / 

Staging

area
Local

repository
Local computer
Working
directory
Get the data from the
repository into the working
directory
Again, not the files but the
references to the files from a
commit
> git checkout <commit>
Checkout
Working

directory
Local

repository
Collaboration
Working
directory
Index / 

Staging

area
Local

repository
Local computer
add
commit
checkout
Working
directory
Index / 

Staging

area
Local

repository
Local computer
add
commit
checkout
Remote

repository
Hosted on a
remote server
push
fetch
Remote Repository
A copy of the local repository, hosted on a network
Other people can join a project, by cloning its
remote repository
Note: GitHub is a service that provides this remote
repository hosting
Demo
1. Create a new local repository
2. Create a file and make a new commit to the local
repository
3. Associate the local repository with a remote
repository
4. Push it to the remote repository

Branch
Branch
A branch is a pointer
to a commit
master, is the name of
the default branch
master
master
new 

feature
Initial commit
Example with 3 branches
Time
bug fix
master
new 

feature
bug fix
Initial commit
Example with 3 branches
Time
HEAD
A special type of branch

that always points to the 

currently active branch / commit



Points to the master branch 

when a repository is initialized



A checkout just changes the HEAD pointee
Demo Cont.
1. Clone an existing repository
2. Create a new branch
3. Make a commit to the new branch
4. Switch between branches (checkout and change
HEAD), see the changes in the local filesystem
5. Push the new branch to the remote repository

Merge
Merge two commits together
Can be used to merge branches
May cause conflicts between commits that need to
be resolved manually
// Merge <commit> into HEAD pointee
> git merge <commit>

A
B
master
develop
bug fix
Initial commit
Time
AB
Merge-commit

of A and B
B
HEAD
Summary
Version Control
Series of commits
Three components
Working directory

Index / Staging area

Repository, local and remote
Commit
Snapshot of file references (and other metadata)
Branch /
Just a pointer to a commit
HEAD
Working
directory
Index / 

Staging

area
Local

repository
Thank you for listening 

🙇
More Git Features
Reset, --soft, --mixed, --hard
Revert
Fast-Forward / No Fast-Forward merge
Rebase
Cherrypick
Further Readings
Git Documentation 

https://git-scm.com/doc
Pro Git

https://git-scm.com/book/en/v2
Git Cheatsheet 

http://ndpsoftware.com/git-cheatsheet.html#loc=local_repo
Cheatsheet 💯
> git init
> git status
> git branch [-a] [-v]
> git remote add <name> <url>
> git fetch
> git add <file>
> git commit -m “<message>”
> git push <repository> <branch>
> git pull <repository> <branch>
> git checkout [-b] <branch> -- <file>
> git log [--graph]
> git merge
> git --help
> git revert <commit>
> git reset --hard HEAD
* Actually not even close to 100

実は満点からはほど遠い
*
Install Git
Linux 

> sudo apt-get install git-all
OS X 

Included in Xcode Command Line Tools
Windows

Binary installer
https://git-scm.com/book/en/v2/Getting-Started-Installing-Git

Weitere ähnliche Inhalte

Was ist angesagt?

Quick Introduction to git
Quick Introduction to gitQuick Introduction to git
Quick Introduction to git
Joel Krebs
 

Was ist angesagt? (20)

Understanding GIT and Version Control
Understanding GIT and Version ControlUnderstanding GIT and Version Control
Understanding GIT and Version Control
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
 
Source control
Source controlSource control
Source control
 
Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash Course
 
Quick Introduction to git
Quick Introduction to gitQuick Introduction to git
Quick Introduction to git
 
Giới thiệu git
Giới thiệu gitGiới thiệu git
Giới thiệu git
 
Git vs svn
Git vs svnGit vs svn
Git vs svn
 
A Practical Introduction to git
A Practical Introduction to gitA Practical Introduction to git
A Practical Introduction to git
 
Git and Github Session
Git and Github SessionGit and Github Session
Git and Github Session
 
Git in 10 minutes
Git in 10 minutesGit in 10 minutes
Git in 10 minutes
 
Git and Github
Git and GithubGit and Github
Git and Github
 
Git e GitHub
Git e GitHubGit e GitHub
Git e GitHub
 
Git 101 for Beginners
Git 101 for Beginners Git 101 for Beginners
Git 101 for Beginners
 
Git training v10
Git training v10Git training v10
Git training v10
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
 
Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
Introduction to Git and GitHub
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
 

Ähnlich wie An Introduction to Git

Ähnlich wie An Introduction to Git (20)

Version control with GIT
Version control with GITVersion control with GIT
Version control with GIT
 
Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
Introduction to Git and GitHub
 
Getting Started with Git: A Primer for SVN and TFS Users
Getting Started with Git: A Primer for SVN and TFS UsersGetting Started with Git: A Primer for SVN and TFS Users
Getting Started with Git: A Primer for SVN and TFS Users
 
Roslyn on GitHub
Roslyn on GitHubRoslyn on GitHub
Roslyn on GitHub
 
Git training (basic)
Git training (basic)Git training (basic)
Git training (basic)
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
Git slide
Git slideGit slide
Git slide
 
Git_new.pptx
Git_new.pptxGit_new.pptx
Git_new.pptx
 
What the Git? - WordCamp Atlanta
What the Git? - WordCamp AtlantaWhat the Git? - WordCamp Atlanta
What the Git? - WordCamp Atlanta
 
Git SCM
Git SCMGit SCM
Git SCM
 
Git workshop 33degree 2011 krakow
Git workshop 33degree 2011 krakowGit workshop 33degree 2011 krakow
Git workshop 33degree 2011 krakow
 
Git hub_pptx
Git hub_pptxGit hub_pptx
Git hub_pptx
 
Git and GitHub (1).pptx
Git and GitHub (1).pptxGit and GitHub (1).pptx
Git and GitHub (1).pptx
 
Intro to Git and Github
Intro to Git and GithubIntro to Git and Github
Intro to Git and Github
 
git.ppt.pdf
git.ppt.pdfgit.ppt.pdf
git.ppt.pdf
 
Git&GitHub.pptx
Git&GitHub.pptxGit&GitHub.pptx
Git&GitHub.pptx
 
Version controll.pptx
Version controll.pptxVersion controll.pptx
Version controll.pptx
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
Version Control with Git & GitHub
Version Control with Git & GitHubVersion Control with Git & GitHub
Version Control with Git & GitHub
 
Git 101
Git 101Git 101
Git 101
 

Kürzlich hochgeladen

DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
MayuraD1
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 

Kürzlich hochgeladen (20)

Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdf
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic Marks
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 

An Introduction to Git