SlideShare a Scribd company logo
I H S C
Introduction to git:
An Efficient Distributed Version Control System
pmxal9@nottingham.ac.uk
18th November 2016
Introduction
git alone
git + server
Complementary
1
Version Control System
Stand-alone application managing changes to documents.
Bad Example
Good Example, using Git branches
2
Version Control System
Stand-alone application managing changes to documents.
Bad Example
thesis.pdf
thesis_V1.pdf
thesis_V2.pdf
thesis_V2bis.pdf
thesis_V3_withChris_comments.pdf
thesis_V4_withChris_commentsV2.pdf
Good Example, using Git branches
2
Version Control System
Stand-alone application managing changes to documents.
Bad Example
thesis.pdf
thesis_V1.pdf
thesis_V2.pdf
thesis_V2bis.pdf
thesis_V3_withChris_comments.pdf
thesis_V4_withChris_commentsV2.pdf
Good Example, using Git branches
thesis.pdf
2
Think of nodes as points in time pointing towards their past:
3
Think of nodes as points in time pointing towards their past:
What is the history of H?
3
Think of nodes as points in time pointing towards their past:
What is the history of H? H G F B A
3
Think of nodes as points in time pointing towards their past:
What is the history of H? H G F B A
What is the history of E?
3
Think of nodes as points in time pointing towards their past:
What is the history of H? H G F B A
What is the history of E? E D C B A
3
Think of nodes as points in time pointing towards their past:
What is the history of H? H G F B A
What is the history of E? E D C B A
What is the history of K? K J I C B A
3
Think of nodes as points in time pointing towards their past:
What is the history of H? H G F B A
What is the history of E? E D C B A
What is the history of K? K J I C B A
Each branch is a parallel universe.
Each branch shares a part of its past with other branches.
3
Think of nodes as points in time pointing towards their past:
← nobrexit
← master
← notrump
What is the history of H? H G F B A
What is the history of E? E D C B A
What is the history of K? K J I C B A
Each branch is a parallel universe.
Each branch shares a part of its past with other branches.
→ Depending on where you start, some nodes are unreachable.
3
4
Git Tools
This seminar is about
• init
• add
• branch
• status
• commit
• merge
• clone
• push
• fetch
• pull
and behind the scene
5
Git Tools
This seminar is about
• init
• add
• branch
• status
• commit
• merge



to use git alone
• clone
• push
• fetch
• pull
and behind the scene
5
Git Tools
This seminar is about
• init
• add
• branch
• status
• commit
• merge
• clone
• push
• fetch
• pull



to use git with a server
and behind the scene
5
Git Tools
This seminar is about
• init
• add
• branch
• status
• commit
• merge
• clone
• push
• fetch
• pull
and behind the scene



to use git on collaborative projects
5
Goals
• Create new repo(sitory)
• Put some code in remote server
• Use GitX to check things work as wanted
• Wait for collaborators to change the code
• Get the changes on my computer
• Experiment in a different branch
6
Requirements
Terminal/Command Prompt
Depending on you Operating System
Command-Line Basics
• pwd Current working directory
• cd <d> Change directory to <d>
• ls <d> List out directory <d>
• cp <a> <fd> Copy <a> to <fd>
• echo <s> Display input <s>
• cat <f> Display file <f>
• rm <f> Remove <f>
Text Editor
vim, nano, emacs...
7
Introduction
git alone
git + server
Complementary
8
$HOME alone
Most of your workflow with git is on your local computer
9
git States
git has 3 main states files can reside in:
• Commited: data is safely stored in your local database
• Modified: file has been changed but not committed yet
• Staged: file marked as going into next commit snapshot
10
git States
git has 3 main states files can reside in:
• Commited: data is safely stored in your local database
• Modified: file has been changed but not committed yet
• Staged: file marked as going into next commit snapshot
leading to three main sections of a Git project:
• git directory,
• working directory,
• staging area.
Pro Git, Chacon&Straub
10
git States
Pro Git, Chacon&Straub
At any moment, a file is in one of these states:
Untracked Modified: Staged: Commited:
: > a echo a >> lol git add lol git commit -m "l"
git status git status git status git status
11
A Basic Workflow
Edit files vim <file>
Stage the changes git add <file>
Review your changes git status / git diff
Commit the changes git commit -m "<msg>"
Edit files .....
Stage ............
Commit ........
12
Commit → Safety
Commited data (stored in the repo) is fairly hard to remove.
It makes it hard to lose your work once it’s commited.
Commit:
• Create snapshot of whole repo + history
• Add a diff in database
• Generate SHA-1 40 bytes hexadecimal string of it
$ git log --pretty=oneline
71c1395efd640a476ab78d62c3da13caa9388065 Work git seminar
96b4cfa3158141bf0e0321780876358114e7c229 Testing gitignore
0c4efa32205c8f2faef415dd7cc0f484bfdab1e2 some changes
7d8bfb1b04fefc641e9556933ee7a45b956086e6 rm DS_Stores
76b68b6f2fb82f3cfbc1cc52b31f217267d85ce9 Commit
f683feade8ba48bda78fabc20ce4aceba4563470 First commit
13
Branches
Branching means you diverge from the main line of development
and continue to do work without messing with that main line.
Git’s killer feature is its branching model
14
Working with Branches
Creating a branch...
15
Working with Branches
Creating a branch...
takes 41 bytes,
15
Working with Branches
Creating a branch...
takes 41 bytes,
is virtually instantaneous,
15
Working with Branches
Creating a branch...
takes 41 bytes,
is virtually instantaneous,
creates a reference easy to come back to.
15
Working with Branches
Creating a branch...
takes 41 bytes,
is virtually instantaneous,
creates a reference easy to come back to.
A branch is simply a pointer to a commit.
Pro Git, Chacon&Straub
15
Working with Branches
Creating a branch...
takes 41 bytes,
is virtually instantaneous,
creates a reference easy to come back to.
A branch is simply a pointer to a commit.
Pro Git, Chacon&Straub
Creating a branch is like saving the game before battling a boss.
Plato, about Git, 429 BC
15
References make commits reachable
Attaching your modifications to a branch enables you to go back
to them by following pointers.
16
References make commits reachable
Attaching your modifications to a branch enables you to go back
to them by following pointers.
← featureX
← master
← issue539
16
Working with Branches
git branch newB to create a new branch,
git checkout coolFeature to move to coolFeature branch,
git checkout -b newB locally create a new branch & switch to.
To check in which branch you are: git status / git branch
17
Experimenting in New Branch
By default, original branch is called master.
HEAD is a symbolic reference to the branch you are currently in.
18
Experimenting in New Branch
By default, original branch is called master.
HEAD is a symbolic reference to the branch you are currently in.
Workflow:
• Create new branch, git branch nB
18
Experimenting in New Branch
By default, original branch is called master.
HEAD is a symbolic reference to the branch you are currently in.
Workflow:
• Create new branch, git branch nB
• Checkout to this branch, git checkout -b nB
18
Experimenting in New Branch
By default, original branch is called master.
HEAD is a symbolic reference to the branch you are currently in.
Workflow:
• Create new branch, git branch nB
• Checkout to this branch, git checkout -b nB
• Develop new features in it, git add/commit/add/commit..
18
Experimenting in New Branch
By default, original branch is called master.
HEAD is a symbolic reference to the branch you are currently in.
Workflow:
• Create new branch, git branch nB
• Checkout to this branch, git checkout -b nB
• Develop new features in it, git add/commit/add/commit..
• Merge, git checkout B; git merge nB
18
Experimenting in New Branch
By default, original branch is called master.
HEAD is a symbolic reference to the branch you are currently in.
Workflow:
• Create new branch, git branch nB
• Checkout to this branch, git checkout -b nB
• Develop new features in it, git add/commit/add/commit..
• Merge, git checkout B; git merge nB
• Delete branch. git branch -d nB
18
Merging
Git has two strategies for merging, depending on reachability:
Reachable: Fast-forward merging, just moves a pointer.
19
Merging
Git has two strategies for merging, depending on reachability:
Reachable: Fast-forward merging, just moves a pointer.
Pro Git, Chacon&Straub 19
Merging
Git has two strategies for merging, depending on reachability:
Reachable: Fast-forward merging, just moves a pointer.
Unreachable: Recursive merging, commit with two parents.
Pro Git, Chacon&Straub
19
Merging
Git has two strategies for merging, depending on reachability:
Reachable: Fast-forward merging, just moves a pointer.
Unreachable: Recursive merging, commit with two parents.
Pro Git, Chacon&Straub
19
Hands-on: just on your machine
Five minutes to use on your computer:
• git init Initialise a git skeleton inside chosen folder
• git add <F> Start tracking or stage changes <F>
• git commit -m "<M>" Commit changes with msg <M>
• git status Get general state information
• git diff Get patch stage information
• git branch <B> Create a new branch
• git checkout <B> Switch to branch <B>
• git merge <B> Merge branch <B> with current branch
20
Introduction
git alone
git + server
Complementary
21
Remote Server
Download git repo located at given url into new directory
git clone <url>
Fetch the current version of current repo on remote server
git fetch
Push your current git repo to remote server
git push
Check your remote servers:
git remote -v
22
Quicker than fetching + merging
git pull = ‘git fetch‘ + ‘git merge FETCH_HEAD‘
23
Hands-on: Let’s Collaborate
• create an empty repo "ourRepo" using a web browser
• git clone to local computer
• git add a README.md file with information for users
• git add to start tracking files, git commit, git push
• Users git pull (first clone), apply some changes and git push
(pull request since you don’t have the authorisations)
• Do pull request 24
Hands-on: Let’s Collaborate
• create an empty repo "ourRepo" using a web browser
cd path/to/myRepos
• git clone to local computer
git clone git@bitbucket.org:allevity/ourRepo.git
• git add a README.md file with information for users
a="Clone project and follow README instructions"
echo $a > ourRepo/letsPlayAGame
cp Seminars/git/introGit.pdf ourRepo/introGit.pdf
• git add to start tracking files, git commit, git push
git add -A; git commit -m "First commit"; git push
• Users git pull (first clone), apply some changes and git push
(pull request since you don’t have the authorisations)
Fork to your account yourName
git clone git@bitbucket.org:yourName/ourRepo.git
git add -A; git commit -m "your msg"; git push
• Do pull request 24
Checking Commits since 3y 4m 5h 6s ago
Literally...
git log --since="3 years 4 months 5 hours 6 seconds ago"
Check what your collaborators have commited during your sleep:
git log --since="15 hours ago"
25
Tagging
Tags are pointers towards a fixed commit:
git tag -a V1.4 -m "Thesis_V1.4 with Chris comments"
To list all tags or look at a specific one:
git tag
git show V1.4
26
How does git work?
...
27
XKCD 28
Introduction
git alone
git + server
Complementary
29
Workflows in Centralised VS Distributed Systems
Centralised Integration Manager Benevolent Dictator
Pro Git, Chacon&Straub
Centralised
server special, merges difficult, communication slow & necessary.
Distributed
server is just copy, easy to merge, most work is local.
https://www.youtube.com/watch?v=_yQlKEq-Ueg
30
Which Web-based Git Repository Hosting Service?
Short answer:
• GitHub is the biggest player, but no private repo for free*
• Bitbucket has free private repos, but visualisation and
traffic info missing
* Just tried https://education.github.com/ to get free repos.
They say it might take a few weeks...
31
gitignore
A .gitignore file forces git to not track some files or folders,
according to regular expression patterns.
Example
$ cat .gitignore
# Don’t keep this sub repository
mySubRepo/*
# Data too big to fit on server
data/*
# LaTeX minitoc, generated when executing LaTex code
*.mlt
*.mtc[0-9]*
# No .txt in log/, except thisisimportant.txt
log/**/*.txt
!log/thisisimportant.txt
Use templates:
https://github.com/github/gitignore 32
Raising & Solving Issues
When you spot a problem in Git-based project, raise an issue.
33
Dealing with Conflicts
When you change a line of code that a collaborator changed
before you, git will refuse your push.
Hence, always git pull before starting to work.
34
Deleting Branches
Safe (checks commit remains reachable):
git branch -d myBranch
Unsafe (may make commits unreachable):
git branch -D myBranch
35
Deleting Branches
Even if a commit is not reachable, knowing its SHA-1 is enough
to get it back in our graph.
To create a branch pointing to a commit that was not reachable:
git branch -D myBranch
# Deleted branch myBranch (was e11cd74).
git branch myBranchBack e11cd74
36
Changing the past
It is considered rude to change the history of a public project.
But if you need to, git rebase moves commits in the graph.
37
A Word About Security
Thanks to its checksum-based implementation, Git is secure:
• Delete project, only keep its last commit SHA-1 (41 bytes),
• Download a copy from a completely insecure source,
• Check its SHA-1 is the same as yours.
You can trust this is exactly your project: no corruption on it.
38
A Word About Security
Thanks to its checksum-based implementation, Git is secure:
• Delete project, only keep its last commit SHA-1 (41 bytes),
• Download a copy from a completely insecure source,
• Check its SHA-1 is the same as yours.
You can trust this is exactly your project: no corruption on it.
Maybe your projects aren’t that important.
My projects, they’re important.
There’s a reason I care.
Linus Torvalds, speaking to Google about Git, 2007.
38
Some useful commands
Tracking Files: some options
• Add all files
git add -a
• Add a given file/folder
git add myFile src/myFolder/
• Choose what changes to add manually (‘y’ or ‘n’ changes)
git add -p
39
Some useful commands
Skip staging area, staging all files already tracked:
git commit -am "<M>"
Unstage a file (reset without option only changes staging area):
git add lol
git reset HEAD lol
Change a commit:
git commit -m ’initial commit’
git add forgotten_file
git commit --amend
40
Some useful commands
Remove changes done to a tracked & modified & unstaged file:
echo "new change" >> lol
git checkout -- lol # SOME DATA IS LOST!
Check what you commit:
git diff
git status -s with two columns: staging area & working area
41
Some useful commands
Search in repo:
git grep ’some string’
Show list of commits:
git log # All commits
git log -S ’some stuff’ # Search string
git log --author ’supervisor’ # Did he work?
git log --oneline --abbrev-commit --all --graph --decorate
Make aliases:
git config --global alias.lol 
"log --oneline --graph --decorate"
42
Some useful tools
GitX to visualise your git tree
43
Summary
git init git checkout
git clone git merge
git add git push
git status git fetch
git commit git pull
git branch git log
44
Remerciements
Thank you for your attention
Linus for awesome work
Scott Chacon for wonderful Git material
GitHub & Bitbucket for free repos
45
References
Online Hands-on
https://try.github.io
Introduction to Git with Scott Chacon of GitHub, 2011:
https://www.youtube.com/watch?v=ZDR433b0HJY
Linus Torvald, Google HQ, 2007:
https://www.youtube.com/watch?v=4XpnKHJAok8
A gentle intro:
http://think-like-a-git.net/
Scott Chacon’s free e-book
https://git-scm.com/book/en/v2
46
Ad

Recommended

Git & GitHub WorkShop
Git & GitHub WorkShop
SheilaJimenezMorejon
 
Git and GitHub
Git and GitHub
James Gray
 
Git and git workflow best practice
Git and git workflow best practice
Majid Hosseini
 
Advanced Git
Advanced Git
Sergiu-Ioan Ungur
 
Introduction to Git (Greg Lonnon)
Introduction to Git (Greg Lonnon)
Boise Web Technologies Group
 
Git: from Novice to Expert
Git: from Novice to Expert
Goddy Zhao
 
Git - The Incomplete Introduction
Git - The Incomplete Introduction
rschwietzke
 
Learn Git Fundamentals
Learn Git Fundamentals
Jatin Sharma
 
Mastering git - Workflow
Mastering git - Workflow
Tahsin Abrar
 
Git and Version Control at Atlogys
Git and Version Control at Atlogys
Atlogys Technical Consulting
 
Git tutorial
Git tutorial
Pham Quy (Jack)
 
Git Basic
Git Basic
Luke Luo
 
Git & Github
Git & Github
Aman Lalpuria
 
Mastering GIT
Mastering GIT
Hasnaeen Rahman
 
GIT_In_90_Minutes
GIT_In_90_Minutes
vimukthirandika
 
Improving your workflow with git
Improving your workflow with git
Dídac Ríos
 
Git n git hub
Git n git hub
Jiwon Baek
 
Git Introduction
Git Introduction
Gareth Hall
 
Git essentials
Git essentials
Otto Kekäläinen
 
Git tutorial
Git tutorial
mobaires
 
How to Really Get Git
How to Really Get Git
Susan Tan
 
Introduction to Git
Introduction to Git
Colin Su
 
Git in 10 minutes
Git in 10 minutes
Safique Ahmed Faruque
 
SCM for Android Developers Using Git
SCM for Android Developers Using Git
Tony Hillerson
 
Git real slides
Git real slides
Lucas Couto
 
Introduction to Git
Introduction to Git
Yan Vugenfirer
 
An Introduction to Git (even for non-developers)
An Introduction to Git (even for non-developers)
John Anderson
 
Git, GitHub and Open Source
Git, GitHub and Open Source
Lorna Mitchell
 
3 Git
3 Git
Fabio Fumarola
 
Git and Github slides.pdf
Git and Github slides.pdf
Tilton2
 

More Related Content

What's hot (19)

Mastering git - Workflow
Mastering git - Workflow
Tahsin Abrar
 
Git and Version Control at Atlogys
Git and Version Control at Atlogys
Atlogys Technical Consulting
 
Git tutorial
Git tutorial
Pham Quy (Jack)
 
Git Basic
Git Basic
Luke Luo
 
Git & Github
Git & Github
Aman Lalpuria
 
Mastering GIT
Mastering GIT
Hasnaeen Rahman
 
GIT_In_90_Minutes
GIT_In_90_Minutes
vimukthirandika
 
Improving your workflow with git
Improving your workflow with git
Dídac Ríos
 
Git n git hub
Git n git hub
Jiwon Baek
 
Git Introduction
Git Introduction
Gareth Hall
 
Git essentials
Git essentials
Otto Kekäläinen
 
Git tutorial
Git tutorial
mobaires
 
How to Really Get Git
How to Really Get Git
Susan Tan
 
Introduction to Git
Introduction to Git
Colin Su
 
Git in 10 minutes
Git in 10 minutes
Safique Ahmed Faruque
 
SCM for Android Developers Using Git
SCM for Android Developers Using Git
Tony Hillerson
 
Git real slides
Git real slides
Lucas Couto
 
Introduction to Git
Introduction to Git
Yan Vugenfirer
 
An Introduction to Git (even for non-developers)
An Introduction to Git (even for non-developers)
John Anderson
 

Similar to Introduction to git, an efficient distributed version control system (20)

Git, GitHub and Open Source
Git, GitHub and Open Source
Lorna Mitchell
 
3 Git
3 Git
Fabio Fumarola
 
Git and Github slides.pdf
Git and Github slides.pdf
Tilton2
 
Git and Github workshop ppt slide by slide
Git and Github workshop ppt slide by slide
RaghavendraVattikuti1
 
Git Init (Introduction to Git)
Git Init (Introduction to Git)
GDSC UofT Mississauga
 
Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with Git
Robert Lee-Cann
 
[PUBLIC] Git – Concepts and Workflows.pdf
[PUBLIC] Git – Concepts and Workflows.pdf
ChimaEzeamama1
 
The Basics of Open Source Collaboration With Git and GitHub
The Basics of Open Source Collaboration With Git and GitHub
BigBlueHat
 
Git and GitHub Workshop of GDG on Campus UNSTPB
Git and GitHub Workshop of GDG on Campus UNSTPB
AmaraCostachiu
 
Git-guidance for beginner- IT support.pptx.pptx
Git-guidance for beginner- IT support.pptx.pptx
vietnguyen1989
 
Git-guidance for beginner- IT support.pptx
Git-guidance for beginner- IT support.pptx
vietnguyen1989
 
Talk to git
Talk to git
YenTing Chen
 
Collaborative development with Git | Workshop
Collaborative development with Git | Workshop
Anuchit Chalothorn
 
Git & GitHub 101farwsfrwvnfuvnvjvvv.pptx
Git & GitHub 101farwsfrwvnfuvnvjvvv.pptx
sihoxe6756
 
Git One Day Training Notes
Git One Day Training Notes
glen_a_smith
 
tech winter break workshop on git &git hub.pptx
tech winter break workshop on git &git hub.pptx
ashishraulin
 
Introduction to git, a version control system
Introduction to git, a version control system
Kumaresh Chandra Baruri
 
Git and GitHub Presentation of GDG on Campus UNSTPB
Git and GitHub Presentation of GDG on Campus UNSTPB
AmaraCostachiu
 
Git Tech Talk
Git Tech Talk
Chris Johnson
 
Git and GitHub Workshop of GDG on Campus UNSTPB
Git and GitHub Workshop of GDG on Campus UNSTPB
AmaraCostachiu
 
Git, GitHub and Open Source
Git, GitHub and Open Source
Lorna Mitchell
 
Git and Github slides.pdf
Git and Github slides.pdf
Tilton2
 
Git and Github workshop ppt slide by slide
Git and Github workshop ppt slide by slide
RaghavendraVattikuti1
 
Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with Git
Robert Lee-Cann
 
[PUBLIC] Git – Concepts and Workflows.pdf
[PUBLIC] Git – Concepts and Workflows.pdf
ChimaEzeamama1
 
The Basics of Open Source Collaboration With Git and GitHub
The Basics of Open Source Collaboration With Git and GitHub
BigBlueHat
 
Git and GitHub Workshop of GDG on Campus UNSTPB
Git and GitHub Workshop of GDG on Campus UNSTPB
AmaraCostachiu
 
Git-guidance for beginner- IT support.pptx.pptx
Git-guidance for beginner- IT support.pptx.pptx
vietnguyen1989
 
Git-guidance for beginner- IT support.pptx
Git-guidance for beginner- IT support.pptx
vietnguyen1989
 
Collaborative development with Git | Workshop
Collaborative development with Git | Workshop
Anuchit Chalothorn
 
Git & GitHub 101farwsfrwvnfuvnvjvvv.pptx
Git & GitHub 101farwsfrwvnfuvnvjvvv.pptx
sihoxe6756
 
Git One Day Training Notes
Git One Day Training Notes
glen_a_smith
 
tech winter break workshop on git &git hub.pptx
tech winter break workshop on git &git hub.pptx
ashishraulin
 
Introduction to git, a version control system
Introduction to git, a version control system
Kumaresh Chandra Baruri
 
Git and GitHub Presentation of GDG on Campus UNSTPB
Git and GitHub Presentation of GDG on Campus UNSTPB
AmaraCostachiu
 
Git and GitHub Workshop of GDG on Campus UNSTPB
Git and GitHub Workshop of GDG on Campus UNSTPB
AmaraCostachiu
 
Ad

More from AlbanLevy (7)

Envelope coding in the cochlear nucleus: a data mining approach
Envelope coding in the cochlear nucleus: a data mining approach
AlbanLevy
 
Cracking the neural code
Cracking the neural code
AlbanLevy
 
Object Oriented Programming in Matlab
Object Oriented Programming in Matlab
AlbanLevy
 
Data mining with Weka
Data mining with Weka
AlbanLevy
 
Matlab for a computational PhD
Matlab for a computational PhD
AlbanLevy
 
Mathematics for neuroscience - a gentle introduction (in French)
Mathematics for neuroscience - a gentle introduction (in French)
AlbanLevy
 
Storytelling for research software engineers
Storytelling for research software engineers
AlbanLevy
 
Envelope coding in the cochlear nucleus: a data mining approach
Envelope coding in the cochlear nucleus: a data mining approach
AlbanLevy
 
Cracking the neural code
Cracking the neural code
AlbanLevy
 
Object Oriented Programming in Matlab
Object Oriented Programming in Matlab
AlbanLevy
 
Data mining with Weka
Data mining with Weka
AlbanLevy
 
Matlab for a computational PhD
Matlab for a computational PhD
AlbanLevy
 
Mathematics for neuroscience - a gentle introduction (in French)
Mathematics for neuroscience - a gentle introduction (in French)
AlbanLevy
 
Storytelling for research software engineers
Storytelling for research software engineers
AlbanLevy
 
Ad

Recently uploaded (20)

Values Education 10 Quarter 1 Module .pptx
Values Education 10 Quarter 1 Module .pptx
JBPafin
 
English 3 Quarter 1_LEwithLAS_Week 1.pdf
English 3 Quarter 1_LEwithLAS_Week 1.pdf
DeAsisAlyanajaneH
 
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT Kharagpur Quiz Club
 
Peer Teaching Observations During School Internship
Peer Teaching Observations During School Internship
AjayaMohanty7
 
LDMMIA Yoga S10 Free Workshop Grad Level
LDMMIA Yoga S10 Free Workshop Grad Level
LDM & Mia eStudios
 
Paper 106 | Ambition and Corruption: A Comparative Analysis of ‘The Great Gat...
Paper 106 | Ambition and Corruption: A Comparative Analysis of ‘The Great Gat...
Rajdeep Bavaliya
 
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
Kweku Zurek
 
VCE Literature Section A Exam Response Guide
VCE Literature Section A Exam Response Guide
jpinnuck
 
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
KaryanaTantri21
 
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
jutaydeonne
 
Gladiolous Cultivation practices by AKL.pdf
Gladiolous Cultivation practices by AKL.pdf
kushallamichhame
 
List View Components in Odoo 18 - Odoo Slides
List View Components in Odoo 18 - Odoo Slides
Celine George
 
How to use search fetch method in Odoo 18
How to use search fetch method in Odoo 18
Celine George
 
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
Ultimatewinner0342
 
M&A5 Q1 1 differentiate evolving early Philippine conventional and contempora...
M&A5 Q1 1 differentiate evolving early Philippine conventional and contempora...
ErlizaRosete
 
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Rajdeep Bavaliya
 
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
SHERAZ AHMAD LONE
 
Filipino 9 Maikling Kwento Ang Ama Panitikang Asiyano
Filipino 9 Maikling Kwento Ang Ama Panitikang Asiyano
sumadsadjelly121997
 
CRYPTO TRADING COURSE BY FINANCEWORLD.IO
CRYPTO TRADING COURSE BY FINANCEWORLD.IO
AndrewBorisenko3
 
Great Governors' Send-Off Quiz 2025 Prelims IIT KGP
Great Governors' Send-Off Quiz 2025 Prelims IIT KGP
IIT Kharagpur Quiz Club
 
Values Education 10 Quarter 1 Module .pptx
Values Education 10 Quarter 1 Module .pptx
JBPafin
 
English 3 Quarter 1_LEwithLAS_Week 1.pdf
English 3 Quarter 1_LEwithLAS_Week 1.pdf
DeAsisAlyanajaneH
 
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT Kharagpur Quiz Club
 
Peer Teaching Observations During School Internship
Peer Teaching Observations During School Internship
AjayaMohanty7
 
LDMMIA Yoga S10 Free Workshop Grad Level
LDMMIA Yoga S10 Free Workshop Grad Level
LDM & Mia eStudios
 
Paper 106 | Ambition and Corruption: A Comparative Analysis of ‘The Great Gat...
Paper 106 | Ambition and Corruption: A Comparative Analysis of ‘The Great Gat...
Rajdeep Bavaliya
 
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
Kweku Zurek
 
VCE Literature Section A Exam Response Guide
VCE Literature Section A Exam Response Guide
jpinnuck
 
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
KaryanaTantri21
 
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
jutaydeonne
 
Gladiolous Cultivation practices by AKL.pdf
Gladiolous Cultivation practices by AKL.pdf
kushallamichhame
 
List View Components in Odoo 18 - Odoo Slides
List View Components in Odoo 18 - Odoo Slides
Celine George
 
How to use search fetch method in Odoo 18
How to use search fetch method in Odoo 18
Celine George
 
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
Ultimatewinner0342
 
M&A5 Q1 1 differentiate evolving early Philippine conventional and contempora...
M&A5 Q1 1 differentiate evolving early Philippine conventional and contempora...
ErlizaRosete
 
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Rajdeep Bavaliya
 
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
SHERAZ AHMAD LONE
 
Filipino 9 Maikling Kwento Ang Ama Panitikang Asiyano
Filipino 9 Maikling Kwento Ang Ama Panitikang Asiyano
sumadsadjelly121997
 
CRYPTO TRADING COURSE BY FINANCEWORLD.IO
CRYPTO TRADING COURSE BY FINANCEWORLD.IO
AndrewBorisenko3
 
Great Governors' Send-Off Quiz 2025 Prelims IIT KGP
Great Governors' Send-Off Quiz 2025 Prelims IIT KGP
IIT Kharagpur Quiz Club
 

Introduction to git, an efficient distributed version control system

  • 1. I H S C Introduction to git: An Efficient Distributed Version Control System [email protected] 18th November 2016
  • 2. Introduction git alone git + server Complementary 1
  • 3. Version Control System Stand-alone application managing changes to documents. Bad Example Good Example, using Git branches 2
  • 4. Version Control System Stand-alone application managing changes to documents. Bad Example thesis.pdf thesis_V1.pdf thesis_V2.pdf thesis_V2bis.pdf thesis_V3_withChris_comments.pdf thesis_V4_withChris_commentsV2.pdf Good Example, using Git branches 2
  • 5. Version Control System Stand-alone application managing changes to documents. Bad Example thesis.pdf thesis_V1.pdf thesis_V2.pdf thesis_V2bis.pdf thesis_V3_withChris_comments.pdf thesis_V4_withChris_commentsV2.pdf Good Example, using Git branches thesis.pdf 2
  • 6. Think of nodes as points in time pointing towards their past: 3
  • 7. Think of nodes as points in time pointing towards their past: What is the history of H? 3
  • 8. Think of nodes as points in time pointing towards their past: What is the history of H? H G F B A 3
  • 9. Think of nodes as points in time pointing towards their past: What is the history of H? H G F B A What is the history of E? 3
  • 10. Think of nodes as points in time pointing towards their past: What is the history of H? H G F B A What is the history of E? E D C B A 3
  • 11. Think of nodes as points in time pointing towards their past: What is the history of H? H G F B A What is the history of E? E D C B A What is the history of K? K J I C B A 3
  • 12. Think of nodes as points in time pointing towards their past: What is the history of H? H G F B A What is the history of E? E D C B A What is the history of K? K J I C B A Each branch is a parallel universe. Each branch shares a part of its past with other branches. 3
  • 13. Think of nodes as points in time pointing towards their past: ← nobrexit ← master ← notrump What is the history of H? H G F B A What is the history of E? E D C B A What is the history of K? K J I C B A Each branch is a parallel universe. Each branch shares a part of its past with other branches. → Depending on where you start, some nodes are unreachable. 3
  • 14. 4
  • 15. Git Tools This seminar is about • init • add • branch • status • commit • merge • clone • push • fetch • pull and behind the scene 5
  • 16. Git Tools This seminar is about • init • add • branch • status • commit • merge    to use git alone • clone • push • fetch • pull and behind the scene 5
  • 17. Git Tools This seminar is about • init • add • branch • status • commit • merge • clone • push • fetch • pull    to use git with a server and behind the scene 5
  • 18. Git Tools This seminar is about • init • add • branch • status • commit • merge • clone • push • fetch • pull and behind the scene    to use git on collaborative projects 5
  • 19. Goals • Create new repo(sitory) • Put some code in remote server • Use GitX to check things work as wanted • Wait for collaborators to change the code • Get the changes on my computer • Experiment in a different branch 6
  • 20. Requirements Terminal/Command Prompt Depending on you Operating System Command-Line Basics • pwd Current working directory • cd <d> Change directory to <d> • ls <d> List out directory <d> • cp <a> <fd> Copy <a> to <fd> • echo <s> Display input <s> • cat <f> Display file <f> • rm <f> Remove <f> Text Editor vim, nano, emacs... 7
  • 21. Introduction git alone git + server Complementary 8
  • 22. $HOME alone Most of your workflow with git is on your local computer 9
  • 23. git States git has 3 main states files can reside in: • Commited: data is safely stored in your local database • Modified: file has been changed but not committed yet • Staged: file marked as going into next commit snapshot 10
  • 24. git States git has 3 main states files can reside in: • Commited: data is safely stored in your local database • Modified: file has been changed but not committed yet • Staged: file marked as going into next commit snapshot leading to three main sections of a Git project: • git directory, • working directory, • staging area. Pro Git, Chacon&Straub 10
  • 25. git States Pro Git, Chacon&Straub At any moment, a file is in one of these states: Untracked Modified: Staged: Commited: : > a echo a >> lol git add lol git commit -m "l" git status git status git status git status 11
  • 26. A Basic Workflow Edit files vim <file> Stage the changes git add <file> Review your changes git status / git diff Commit the changes git commit -m "<msg>" Edit files ..... Stage ............ Commit ........ 12
  • 27. Commit → Safety Commited data (stored in the repo) is fairly hard to remove. It makes it hard to lose your work once it’s commited. Commit: • Create snapshot of whole repo + history • Add a diff in database • Generate SHA-1 40 bytes hexadecimal string of it $ git log --pretty=oneline 71c1395efd640a476ab78d62c3da13caa9388065 Work git seminar 96b4cfa3158141bf0e0321780876358114e7c229 Testing gitignore 0c4efa32205c8f2faef415dd7cc0f484bfdab1e2 some changes 7d8bfb1b04fefc641e9556933ee7a45b956086e6 rm DS_Stores 76b68b6f2fb82f3cfbc1cc52b31f217267d85ce9 Commit f683feade8ba48bda78fabc20ce4aceba4563470 First commit 13
  • 28. Branches Branching means you diverge from the main line of development and continue to do work without messing with that main line. Git’s killer feature is its branching model 14
  • 30. Working with Branches Creating a branch... takes 41 bytes, 15
  • 31. Working with Branches Creating a branch... takes 41 bytes, is virtually instantaneous, 15
  • 32. Working with Branches Creating a branch... takes 41 bytes, is virtually instantaneous, creates a reference easy to come back to. 15
  • 33. Working with Branches Creating a branch... takes 41 bytes, is virtually instantaneous, creates a reference easy to come back to. A branch is simply a pointer to a commit. Pro Git, Chacon&Straub 15
  • 34. Working with Branches Creating a branch... takes 41 bytes, is virtually instantaneous, creates a reference easy to come back to. A branch is simply a pointer to a commit. Pro Git, Chacon&Straub Creating a branch is like saving the game before battling a boss. Plato, about Git, 429 BC 15
  • 35. References make commits reachable Attaching your modifications to a branch enables you to go back to them by following pointers. 16
  • 36. References make commits reachable Attaching your modifications to a branch enables you to go back to them by following pointers. ← featureX ← master ← issue539 16
  • 37. Working with Branches git branch newB to create a new branch, git checkout coolFeature to move to coolFeature branch, git checkout -b newB locally create a new branch & switch to. To check in which branch you are: git status / git branch 17
  • 38. Experimenting in New Branch By default, original branch is called master. HEAD is a symbolic reference to the branch you are currently in. 18
  • 39. Experimenting in New Branch By default, original branch is called master. HEAD is a symbolic reference to the branch you are currently in. Workflow: • Create new branch, git branch nB 18
  • 40. Experimenting in New Branch By default, original branch is called master. HEAD is a symbolic reference to the branch you are currently in. Workflow: • Create new branch, git branch nB • Checkout to this branch, git checkout -b nB 18
  • 41. Experimenting in New Branch By default, original branch is called master. HEAD is a symbolic reference to the branch you are currently in. Workflow: • Create new branch, git branch nB • Checkout to this branch, git checkout -b nB • Develop new features in it, git add/commit/add/commit.. 18
  • 42. Experimenting in New Branch By default, original branch is called master. HEAD is a symbolic reference to the branch you are currently in. Workflow: • Create new branch, git branch nB • Checkout to this branch, git checkout -b nB • Develop new features in it, git add/commit/add/commit.. • Merge, git checkout B; git merge nB 18
  • 43. Experimenting in New Branch By default, original branch is called master. HEAD is a symbolic reference to the branch you are currently in. Workflow: • Create new branch, git branch nB • Checkout to this branch, git checkout -b nB • Develop new features in it, git add/commit/add/commit.. • Merge, git checkout B; git merge nB • Delete branch. git branch -d nB 18
  • 44. Merging Git has two strategies for merging, depending on reachability: Reachable: Fast-forward merging, just moves a pointer. 19
  • 45. Merging Git has two strategies for merging, depending on reachability: Reachable: Fast-forward merging, just moves a pointer. Pro Git, Chacon&Straub 19
  • 46. Merging Git has two strategies for merging, depending on reachability: Reachable: Fast-forward merging, just moves a pointer. Unreachable: Recursive merging, commit with two parents. Pro Git, Chacon&Straub 19
  • 47. Merging Git has two strategies for merging, depending on reachability: Reachable: Fast-forward merging, just moves a pointer. Unreachable: Recursive merging, commit with two parents. Pro Git, Chacon&Straub 19
  • 48. Hands-on: just on your machine Five minutes to use on your computer: • git init Initialise a git skeleton inside chosen folder • git add <F> Start tracking or stage changes <F> • git commit -m "<M>" Commit changes with msg <M> • git status Get general state information • git diff Get patch stage information • git branch <B> Create a new branch • git checkout <B> Switch to branch <B> • git merge <B> Merge branch <B> with current branch 20
  • 49. Introduction git alone git + server Complementary 21
  • 50. Remote Server Download git repo located at given url into new directory git clone <url> Fetch the current version of current repo on remote server git fetch Push your current git repo to remote server git push Check your remote servers: git remote -v 22
  • 51. Quicker than fetching + merging git pull = ‘git fetch‘ + ‘git merge FETCH_HEAD‘ 23
  • 52. Hands-on: Let’s Collaborate • create an empty repo "ourRepo" using a web browser • git clone to local computer • git add a README.md file with information for users • git add to start tracking files, git commit, git push • Users git pull (first clone), apply some changes and git push (pull request since you don’t have the authorisations) • Do pull request 24
  • 53. Hands-on: Let’s Collaborate • create an empty repo "ourRepo" using a web browser cd path/to/myRepos • git clone to local computer git clone [email protected]:allevity/ourRepo.git • git add a README.md file with information for users a="Clone project and follow README instructions" echo $a > ourRepo/letsPlayAGame cp Seminars/git/introGit.pdf ourRepo/introGit.pdf • git add to start tracking files, git commit, git push git add -A; git commit -m "First commit"; git push • Users git pull (first clone), apply some changes and git push (pull request since you don’t have the authorisations) Fork to your account yourName git clone [email protected]:yourName/ourRepo.git git add -A; git commit -m "your msg"; git push • Do pull request 24
  • 54. Checking Commits since 3y 4m 5h 6s ago Literally... git log --since="3 years 4 months 5 hours 6 seconds ago" Check what your collaborators have commited during your sleep: git log --since="15 hours ago" 25
  • 55. Tagging Tags are pointers towards a fixed commit: git tag -a V1.4 -m "Thesis_V1.4 with Chris comments" To list all tags or look at a specific one: git tag git show V1.4 26
  • 56. How does git work? ... 27
  • 58. Introduction git alone git + server Complementary 29
  • 59. Workflows in Centralised VS Distributed Systems Centralised Integration Manager Benevolent Dictator Pro Git, Chacon&Straub Centralised server special, merges difficult, communication slow & necessary. Distributed server is just copy, easy to merge, most work is local. https://www.youtube.com/watch?v=_yQlKEq-Ueg 30
  • 60. Which Web-based Git Repository Hosting Service? Short answer: • GitHub is the biggest player, but no private repo for free* • Bitbucket has free private repos, but visualisation and traffic info missing * Just tried https://education.github.com/ to get free repos. They say it might take a few weeks... 31
  • 61. gitignore A .gitignore file forces git to not track some files or folders, according to regular expression patterns. Example $ cat .gitignore # Don’t keep this sub repository mySubRepo/* # Data too big to fit on server data/* # LaTeX minitoc, generated when executing LaTex code *.mlt *.mtc[0-9]* # No .txt in log/, except thisisimportant.txt log/**/*.txt !log/thisisimportant.txt Use templates: https://github.com/github/gitignore 32
  • 62. Raising & Solving Issues When you spot a problem in Git-based project, raise an issue. 33
  • 63. Dealing with Conflicts When you change a line of code that a collaborator changed before you, git will refuse your push. Hence, always git pull before starting to work. 34
  • 64. Deleting Branches Safe (checks commit remains reachable): git branch -d myBranch Unsafe (may make commits unreachable): git branch -D myBranch 35
  • 65. Deleting Branches Even if a commit is not reachable, knowing its SHA-1 is enough to get it back in our graph. To create a branch pointing to a commit that was not reachable: git branch -D myBranch # Deleted branch myBranch (was e11cd74). git branch myBranchBack e11cd74 36
  • 66. Changing the past It is considered rude to change the history of a public project. But if you need to, git rebase moves commits in the graph. 37
  • 67. A Word About Security Thanks to its checksum-based implementation, Git is secure: • Delete project, only keep its last commit SHA-1 (41 bytes), • Download a copy from a completely insecure source, • Check its SHA-1 is the same as yours. You can trust this is exactly your project: no corruption on it. 38
  • 68. A Word About Security Thanks to its checksum-based implementation, Git is secure: • Delete project, only keep its last commit SHA-1 (41 bytes), • Download a copy from a completely insecure source, • Check its SHA-1 is the same as yours. You can trust this is exactly your project: no corruption on it. Maybe your projects aren’t that important. My projects, they’re important. There’s a reason I care. Linus Torvalds, speaking to Google about Git, 2007. 38
  • 69. Some useful commands Tracking Files: some options • Add all files git add -a • Add a given file/folder git add myFile src/myFolder/ • Choose what changes to add manually (‘y’ or ‘n’ changes) git add -p 39
  • 70. Some useful commands Skip staging area, staging all files already tracked: git commit -am "<M>" Unstage a file (reset without option only changes staging area): git add lol git reset HEAD lol Change a commit: git commit -m ’initial commit’ git add forgotten_file git commit --amend 40
  • 71. Some useful commands Remove changes done to a tracked & modified & unstaged file: echo "new change" >> lol git checkout -- lol # SOME DATA IS LOST! Check what you commit: git diff git status -s with two columns: staging area & working area 41
  • 72. Some useful commands Search in repo: git grep ’some string’ Show list of commits: git log # All commits git log -S ’some stuff’ # Search string git log --author ’supervisor’ # Did he work? git log --oneline --abbrev-commit --all --graph --decorate Make aliases: git config --global alias.lol "log --oneline --graph --decorate" 42
  • 73. Some useful tools GitX to visualise your git tree 43
  • 74. Summary git init git checkout git clone git merge git add git push git status git fetch git commit git pull git branch git log 44
  • 75. Remerciements Thank you for your attention Linus for awesome work Scott Chacon for wonderful Git material GitHub & Bitbucket for free repos 45
  • 76. References Online Hands-on https://try.github.io Introduction to Git with Scott Chacon of GitHub, 2011: https://www.youtube.com/watch?v=ZDR433b0HJY Linus Torvald, Google HQ, 2007: https://www.youtube.com/watch?v=4XpnKHJAok8 A gentle intro: http://think-like-a-git.net/ Scott Chacon’s free e-book https://git-scm.com/book/en/v2 46