SlideShare ist ein Scribd-Unternehmen logo
1 von 76
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (19)

Mastering git - Workflow
Mastering git - WorkflowMastering git - Workflow
Mastering git - Workflow
 
Git and Version Control at Atlogys
Git and Version Control at AtlogysGit and Version Control at Atlogys
Git and Version Control at Atlogys
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Git Basic
Git BasicGit Basic
Git Basic
 
Git & Github
Git & GithubGit & Github
Git & Github
 
Mastering GIT
Mastering GITMastering GIT
Mastering GIT
 
GIT_In_90_Minutes
GIT_In_90_MinutesGIT_In_90_Minutes
GIT_In_90_Minutes
 
Improving your workflow with git
Improving your workflow with gitImproving your workflow with git
Improving your workflow with git
 
Git n git hub
Git n git hubGit n git hub
Git n git hub
 
Git Introduction
Git IntroductionGit Introduction
Git Introduction
 
Git essentials
Git essentialsGit essentials
Git essentials
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
How to Really Get Git
How to Really Get GitHow to Really Get Git
How to Really Get Git
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Git in 10 minutes
Git in 10 minutesGit in 10 minutes
Git in 10 minutes
 
SCM for Android Developers Using Git
SCM for Android Developers Using GitSCM for Android Developers Using Git
SCM for Android Developers Using Git
 
Git real slides
Git real slidesGit real slides
Git real slides
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
An Introduction to Git (even for non-developers)
An Introduction to Git (even for non-developers)An Introduction to Git (even for non-developers)
An Introduction to Git (even for non-developers)
 

Ähnlich wie Introduction to git, an efficient distributed version control system

Git, GitHub and Open Source
Git, GitHub and Open SourceGit, GitHub and Open Source
Git, GitHub and Open SourceLorna Mitchell
 
Git and Github slides.pdf
Git and Github slides.pdfGit and Github slides.pdf
Git and Github slides.pdfTilton2
 
Git and Github workshop ppt slide by slide
Git and Github workshop ppt slide by slideGit and Github workshop ppt slide by slide
Git and Github workshop ppt slide by slideRaghavendraVattikuti1
 
Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitRobert Lee-Cann
 
[PUBLIC] Git – Concepts and Workflows.pdf
[PUBLIC] Git – Concepts and Workflows.pdf[PUBLIC] Git – Concepts and Workflows.pdf
[PUBLIC] Git – Concepts and Workflows.pdfChimaEzeamama1
 
The Basics of Open Source Collaboration With Git and GitHub
The Basics of Open Source Collaboration With Git and GitHubThe Basics of Open Source Collaboration With Git and GitHub
The Basics of Open Source Collaboration With Git and GitHubBigBlueHat
 
Collaborative development with Git | Workshop
Collaborative development with Git | WorkshopCollaborative development with Git | Workshop
Collaborative development with Git | WorkshopAnuchit Chalothorn
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notesglen_a_smith
 
Introduction to git, a version control system
Introduction to git, a version control systemIntroduction to git, a version control system
Introduction to git, a version control systemKumaresh Chandra Baruri
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hubVenkat Malladi
 
Git session Dropsolid.com
Git session Dropsolid.comGit session Dropsolid.com
Git session Dropsolid.comdropsolid
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to GitLukas Fittl
 

Ähnlich wie Introduction to git, an efficient distributed version control system (20)

Git, GitHub and Open Source
Git, GitHub and Open SourceGit, GitHub and Open Source
Git, GitHub and Open Source
 
3 Git
3 Git3 Git
3 Git
 
Git and Github slides.pdf
Git and Github slides.pdfGit and Github slides.pdf
Git and Github slides.pdf
 
Git and Github workshop ppt slide by slide
Git and Github workshop ppt slide by slideGit and Github workshop ppt slide by slide
Git and Github workshop ppt slide by slide
 
Git Init (Introduction to Git)
Git Init (Introduction to Git)Git Init (Introduction to Git)
Git Init (Introduction to Git)
 
Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with Git
 
[PUBLIC] Git – Concepts and Workflows.pdf
[PUBLIC] Git – Concepts and Workflows.pdf[PUBLIC] Git – Concepts and Workflows.pdf
[PUBLIC] Git – Concepts and Workflows.pdf
 
The Basics of Open Source Collaboration With Git and GitHub
The Basics of Open Source Collaboration With Git and GitHubThe Basics of Open Source Collaboration With Git and GitHub
The Basics of Open Source Collaboration With Git and GitHub
 
Talk to git
Talk to gitTalk to git
Talk to git
 
Collaborative development with Git | Workshop
Collaborative development with Git | WorkshopCollaborative development with Git | Workshop
Collaborative development with Git | Workshop
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
 
Introduction to git, a version control system
Introduction to git, a version control systemIntroduction to git, a version control system
Introduction to git, a version control system
 
Git Tech Talk
Git  Tech TalkGit  Tech Talk
Git Tech Talk
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
Techoalien git
Techoalien gitTechoalien git
Techoalien git
 
Techoalien git
Techoalien gitTechoalien git
Techoalien git
 
Techoalien git
Techoalien gitTechoalien git
Techoalien git
 
Git session Dropsolid.com
Git session Dropsolid.comGit session Dropsolid.com
Git session Dropsolid.com
 
Git basic
Git basicGit basic
Git basic
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 

Mehr von AlbanLevy

Envelope coding in the cochlear nucleus: a data mining approach
Envelope coding in the cochlear nucleus: a data mining approachEnvelope coding in the cochlear nucleus: a data mining approach
Envelope coding in the cochlear nucleus: a data mining approachAlbanLevy
 
Cracking the neural code
Cracking the neural codeCracking the neural code
Cracking the neural codeAlbanLevy
 
Object Oriented Programming in Matlab
Object Oriented Programming in Matlab Object Oriented Programming in Matlab
Object Oriented Programming in Matlab AlbanLevy
 
Data mining with Weka
Data mining with WekaData mining with Weka
Data mining with WekaAlbanLevy
 
Matlab for a computational PhD
Matlab for a computational PhDMatlab for a computational PhD
Matlab for a computational PhDAlbanLevy
 
Mathematics for neuroscience - a gentle introduction (in French)
Mathematics for neuroscience - a gentle introduction (in French)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 engineersStorytelling for research software engineers
Storytelling for research software engineersAlbanLevy
 

Mehr von AlbanLevy (7)

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

Kürzlich hochgeladen

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 

Kürzlich hochgeladen (20)

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 

Introduction to git, an efficient distributed version control system

  • 1. I H S C Introduction to git: An Efficient Distributed Version Control System pmxal9@nottingham.ac.uk 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 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
  • 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