SlideShare uma empresa Scribd logo
1 de 41
Git
A distributed version control system
Nov 15, 2016
2
3
4
5
6
History
Created by Linus Torvalds for work on the
Linux kernel ~2005
Some of the companies that use git:
Getting Started
 Three trees of Git
 The HEAD

last commit snapshot, next parent
 Index

Proposed next commit snapshot
 Working directory

Sandbox
8
Version control systems
 Version control (or revision control, or source control) is all
about managing multiple versions of documents, programs, web
sites, etc.
 Almost all “real” projects use some kind of version control
 Essential for team projects, but also very useful for individual projects
 Some well-known version control systems are CVS, Subversion,
Mercurial, and Git
 CVS and Subversion use a “central” repository; users “check out” files,
work on them, and “check them in”
 Mercurial and Git treat all repositories as equal
 Distributed systems like Mercurial and Git are newer and are
gradually replacing centralized systems like CVS and Subversion
9
Centralized VC vs. Distributed VC
Central Server
Remote Server
Getting Started
 A basic workflow
 (Possible init or clone) Init a repo
 Edit files
 Stage the changes
 Review your changes
 Commit the changes
11
Why version control?
 For working by yourself:
 Gives you a “time machine” for going back to earlier versions
 Gives you great support for different versions (standalone,
web app, etc.) of the same basic project
 For working with others:
 Greatly simplifies concurrent work, merging changes
 For getting an internship or job:
 Any company with a clue uses some kind of version control
 Companies without a clue are bad places to work
12
Download and install Git
 There are online materials that are better than any that I could
provide
 Here’s the standard one:
http://git-scm.com/downloads
 Here’s one from StackExchange:
http://stackoverflow.com/questions/315911/git-for-beginners-the-def
 Note: Git is primarily a command-line tool
 I prefer GUIs over command-line tools, but…
 The GIT GUIs are more trouble than they are worth (YMMV)
13
Introduce yourself to Git
 Enter these lines (with appropriate changes):
 git config --global user.name "John Smith"
 git config --global user.email jsmith@seas.upenn.edu
 You only need to do this once
 If you want to use a different name/email address for a
particular project, you can change it for just that project
 cd to the project directory
 Use the above commands, but leave out the --global
14
Create and fill a repository
1. cd to the project directory you want to use
2. Type in git init
 This creates the repository (a directory named .git)
 You seldom (if ever) need to look inside this directory
1. Type in git add .
 The period at the end is part of this command!
 Period means “this directory”
 This adds all your current files to the repository
1. Type in git commit –m "Initial commit"
 You can use a different commit message, if you like
15
Clone a repository from elsewhere
 git clone URL
 git clone URL mypath
 These make an exact copy of the repository at the given URL
 git clone git://github.com/rest_of_path/file.git
 Github is the most popular (free) public repository
 All repositories are equal
 But you can treat some particular repository (such as one on Github) as
the “master” directory
 Typically, each team member works in his/her own repository,
and “merges” with other repositories as appropriate
16
The repository
 Your top-level working directory contains everything about
your project
 The working directory probably contains many subdirectories—source
code, binaries, documentation, data files, etc.
 One of these subdirectories, named .git, is your repository
 At any time, you can take a “snapshot” of everything (or selected
things) in your project directory, and put it in your repository
 This “snapshot” is called a commit object
 The commit object contains (1) a set of files, (2) references to the
“parents” of the commit object, and (3) a unique “SHA1” name
 Commit objects do not require huge amounts of memory
 You can work as much as you like in your working directory, but
the repository isn’t updated until you commit something
17
init and the .git repository
 When you said git init in your project directory, or
when you cloned an existing project, you created a
repository
 The repository is a subdirectory named .git containing
various files
 The dot indicates a “hidden” directory
 You do not work directly with the contents of that directory;
various git commands do that for you
 You do need a basic understanding of what is in the repository
18
Making commits
 You do your work in your project directory, as usual
 If you create new files and/or folders, they are not tracked by Git unless you
ask it to do so
 git add newFile1 newFolder1 newFolder2 newFile2
 Committing makes a “snapshot” of everything being tracked into your
repository
 A message telling what you have done is required
 git commit –m “Uncrevulated the conundrum bar”
 git commit

This version opens an editor for you the enter the message

To finish, save and quit the editor
 Format of the commit message
 One line containing the complete summary
 If more than one line, the second line must be blank
19
Commits and graphs
 A commit is when you tell git that a change (or addition) you
have made is ready to be included in the project
 When you commit your change to git, it creates a commit object
 A commit object represents the complete state of the project, including all
the files in the project
 The very first commit object has no “parents”
 Usually, you take some commit object, make some changes, and create a
new commit object; the original commit object is the parent of the new
commit object

Hence, most commit objects have a single parent
 You can also merge two commit objects to form a new one

The new commit object has two parents
 Hence, commit objects form a directed graph
 Git is all about using and manipulating this graph
20
Working with your own repository
 A head is a reference to a commit object
 The “current head” is called HEAD (all caps)
 Usually, you will take HEAD (the current commit object), make
some changes to it, and commit the changes, creating a new
current commit object
 This results in a linear graph: A  B  C  … HEAD
 You can also take any previous commit object, make changes to
it, and commit those changes
 This creates a branch in the graph of commit objects
 You can merge any previous commit objects
 This joins branches in the commit graph
21
Commit messages
 In git, “Commits are cheap.” Do them often.
 When you commit, you must provide a one-line
message stating what you have done
 Terrible message: “Fixed a bunch of things”
 Better message: “Corrected the calculation of median scores”
 Commit messages can be very helpful, to yourself as
well as to your team members
 You can’t say much in one line, so commit often
22
Typical workflow
 git pull remote_repository
 Get changes from a remote repository and merge them into
your own repository
 git status
 See what Git thinks is going on
 Use this frequently!
 Work on your files (remember to add any new ones)
 git commit –m “What I did”
 git push
23
Multiple versions
24
Initial commit
Second commit
Third commit
Bob gets a copy
Fourth commit
Merge
Bob’s commit
Initialization
C:> mkdir CoolProject
C:> cd CoolProject
C:CoolProject > git init
Initialized empty Git repository in
C:/CoolProject/.git
C:CoolProject > notepad README.txt
C:CoolProject > git add .
C:CoolProject > git commit -m 'my first
commit'
[master (root-commit) 7106a52] my first commit
1 file changed, 1 insertion(+)
create mode 100644 README.txt
Branches Illustrated
master
A
> git commit –m ‘my first commit’> git commit –m ‘my first commit’
Branches Illustrated
master
> git commit (x2)> git commit (x2)
A B C
Branches Illustrated
bug123
master
> git checkout –b bug123> git checkout –b bug123
A B C
Branches Illustrated
master
> git commit (x2)> git commit (x2)
A B C
D E
bug123
Branches Illustrated
master
> git checkout master> git checkout master
A B C
D E
bug123
Branches Illustrated
bug123
master
> git merge bug123> git merge bug123
A B C D E
Branches Illustrated
master
> git branch -d bug123> git branch -d bug123
A B C D E
Branches Illustrated
master
A B C D E
F G
bug456
Branches Illustrated
master
A B C D E
F G
bug456
> git checkout master> git checkout master
Branches Illustrated
master
A B C D E
F G
> git merge bug456> git merge bug456
H
bug456
Branches Illustrated
master
A B C D E
F G
> git branch -d bug456> git branch -d bug456
H
Branches Illustrated
master
A B C D E
F G
bug456
Branches Illustrated
master
A B C D E
> git rebase master> git rebase master
F’
G
’
bug456
Branches Illustrated
master
A B C D E
> git checkout master
> git merge bug456
> git checkout master
> git merge bug456
F’
G
’
bug456
Keeping it simple
 If you:
 Make sure you are current with the central repository
 Make some improvements to your code
 Update the central repository before anyone else does
 Then you don’t have to worry about resolving conflicts or
working with multiple branches
 All the complexity in git comes from dealing with these
 Therefore:
 Make sure you are up-to-date before starting to work
 Commit and update the central repository frequently
 If you need help: https://help.github.com/
40
The End
41
When I say I hate CVS with a passion, I have to also
say that if there are any SVN [Subversion] users in
the audience, you might want to leave. Because my
hatred of CVS has meant that I see Subversion as
being the most pointless project ever started. The
slogan of Subversion for a while was "CVS done
right", or something like that, and if you start with
that kind of slogan, there's nowhere you can go.
There is no way to do CVS right.
--Linus Torvalds, as quoted in Wikipedia

Mais conteúdo relacionado

Mais procurados (19)

Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
Introduction to Git and GitHub
 
The everyday developer's guide to version control with Git
The everyday developer's guide to version control with GitThe everyday developer's guide to version control with Git
The everyday developer's guide to version control with Git
 
Introduction to git and github
Introduction to git and githubIntroduction to git and github
Introduction to git and github
 
Basics of git
Basics of gitBasics of git
Basics of git
 
Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
Introduction to Git and GitHub
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
Git introduction
Git introductionGit introduction
Git introduction
 
Git hub ppt presentation
Git hub ppt presentationGit hub ppt presentation
Git hub ppt presentation
 
A Practical Introduction to git
A Practical Introduction to gitA Practical Introduction to git
A Practical Introduction to git
 
Git
GitGit
Git
 
Git Version Control System
Git Version Control SystemGit Version Control System
Git Version Control System
 
Git
GitGit
Git
 
GitHub Basics - Derek Bable
GitHub Basics - Derek BableGitHub Basics - Derek Bable
GitHub Basics - Derek Bable
 
Inside GitHub with Chris Wanstrath
Inside GitHub with Chris WanstrathInside GitHub with Chris Wanstrath
Inside GitHub with Chris Wanstrath
 
Git 101
Git 101Git 101
Git 101
 
Grokking opensource with github
Grokking opensource with githubGrokking opensource with github
Grokking opensource with github
 
Github
GithubGithub
Github
 
Git
GitGit
Git
 
Github
GithubGithub
Github
 

Destaque

Destaque (11)

Neoplasms
NeoplasmsNeoplasms
Neoplasms
 
Soirée Conférence*Concert
Soirée Conférence*Concert  Soirée Conférence*Concert
Soirée Conférence*Concert
 
Emmi Arias Raposo 1º A
Emmi Arias Raposo 1º AEmmi Arias Raposo 1º A
Emmi Arias Raposo 1º A
 
Update Resume
Update ResumeUpdate Resume
Update Resume
 
Undergraduate Senior Design Brief - Climate Change Impact Assesment - Infrast...
Undergraduate Senior Design Brief - Climate Change Impact Assesment - Infrast...Undergraduate Senior Design Brief - Climate Change Impact Assesment - Infrast...
Undergraduate Senior Design Brief - Climate Change Impact Assesment - Infrast...
 
Fotos da escola
Fotos da escolaFotos da escola
Fotos da escola
 
Slide3
Slide3Slide3
Slide3
 
Teste de blogs
Teste de blogsTeste de blogs
Teste de blogs
 
Barracuda Diving & Marine Service Profile Nov 16 (L)
Barracuda Diving & Marine Service Profile Nov 16 (L)Barracuda Diving & Marine Service Profile Nov 16 (L)
Barracuda Diving & Marine Service Profile Nov 16 (L)
 
Investment Presentation
Investment PresentationInvestment Presentation
Investment Presentation
 
Linkdin
LinkdinLinkdin
Linkdin
 

Semelhante a Git

Semelhante a Git (20)

git.ppt
git.pptgit.ppt
git.ppt
 
Git
GitGit
Git
 
A Tutorial for GitHub.pdf
A Tutorial for GitHub.pdfA Tutorial for GitHub.pdf
A Tutorial for GitHub.pdf
 
A Tutorial for GitHub.pdf
A Tutorial for GitHub.pdfA Tutorial for GitHub.pdf
A Tutorial for GitHub.pdf
 
Git for developers
Git for developersGit for developers
Git for developers
 
Git Init (Introduction to Git)
Git Init (Introduction to Git)Git Init (Introduction to Git)
Git Init (Introduction to Git)
 
git2.ppt
git2.pptgit2.ppt
git2.ppt
 
1-Intro to VC & GIT PDF.pptx
1-Intro to VC & GIT PDF.pptx1-Intro to VC & GIT PDF.pptx
1-Intro to VC & GIT PDF.pptx
 
Git hub
Git hubGit hub
Git hub
 
Source control
Source controlSource control
Source control
 
Git training (basic)
Git training (basic)Git training (basic)
Git training (basic)
 
Git and Github.pptx
Git and Github.pptxGit and Github.pptx
Git and Github.pptx
 
Git slides
Git slidesGit slides
Git slides
 
16 Git
16 Git16 Git
16 Git
 
Mastering git - Workflow
Mastering git - WorkflowMastering git - Workflow
Mastering git - Workflow
 
Git 101 for Beginners
Git 101 for Beginners Git 101 for Beginners
Git 101 for Beginners
 
setting up a repository using GIT
setting up a repository using GITsetting up a repository using GIT
setting up a repository using GIT
 
Extra bit with git
Extra bit with gitExtra bit with git
Extra bit with git
 
Introduction to git hub
Introduction to git hubIntroduction to git hub
Introduction to git hub
 
[2015/2016] Collaborative software development with Git
[2015/2016] Collaborative software development with Git[2015/2016] Collaborative software development with Git
[2015/2016] Collaborative software development with Git
 

Último

Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfayushiqss
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationShrmpro
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durbanmasabamasaba
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 

Último (20)

Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 

Git

  • 1. Git A distributed version control system Nov 15, 2016
  • 2. 2
  • 3. 3
  • 4. 4
  • 5. 5
  • 6. 6
  • 7. History Created by Linus Torvalds for work on the Linux kernel ~2005 Some of the companies that use git:
  • 8. Getting Started  Three trees of Git  The HEAD  last commit snapshot, next parent  Index  Proposed next commit snapshot  Working directory  Sandbox 8
  • 9. Version control systems  Version control (or revision control, or source control) is all about managing multiple versions of documents, programs, web sites, etc.  Almost all “real” projects use some kind of version control  Essential for team projects, but also very useful for individual projects  Some well-known version control systems are CVS, Subversion, Mercurial, and Git  CVS and Subversion use a “central” repository; users “check out” files, work on them, and “check them in”  Mercurial and Git treat all repositories as equal  Distributed systems like Mercurial and Git are newer and are gradually replacing centralized systems like CVS and Subversion 9
  • 10. Centralized VC vs. Distributed VC Central Server Remote Server
  • 11. Getting Started  A basic workflow  (Possible init or clone) Init a repo  Edit files  Stage the changes  Review your changes  Commit the changes 11
  • 12. Why version control?  For working by yourself:  Gives you a “time machine” for going back to earlier versions  Gives you great support for different versions (standalone, web app, etc.) of the same basic project  For working with others:  Greatly simplifies concurrent work, merging changes  For getting an internship or job:  Any company with a clue uses some kind of version control  Companies without a clue are bad places to work 12
  • 13. Download and install Git  There are online materials that are better than any that I could provide  Here’s the standard one: http://git-scm.com/downloads  Here’s one from StackExchange: http://stackoverflow.com/questions/315911/git-for-beginners-the-def  Note: Git is primarily a command-line tool  I prefer GUIs over command-line tools, but…  The GIT GUIs are more trouble than they are worth (YMMV) 13
  • 14. Introduce yourself to Git  Enter these lines (with appropriate changes):  git config --global user.name "John Smith"  git config --global user.email jsmith@seas.upenn.edu  You only need to do this once  If you want to use a different name/email address for a particular project, you can change it for just that project  cd to the project directory  Use the above commands, but leave out the --global 14
  • 15. Create and fill a repository 1. cd to the project directory you want to use 2. Type in git init  This creates the repository (a directory named .git)  You seldom (if ever) need to look inside this directory 1. Type in git add .  The period at the end is part of this command!  Period means “this directory”  This adds all your current files to the repository 1. Type in git commit –m "Initial commit"  You can use a different commit message, if you like 15
  • 16. Clone a repository from elsewhere  git clone URL  git clone URL mypath  These make an exact copy of the repository at the given URL  git clone git://github.com/rest_of_path/file.git  Github is the most popular (free) public repository  All repositories are equal  But you can treat some particular repository (such as one on Github) as the “master” directory  Typically, each team member works in his/her own repository, and “merges” with other repositories as appropriate 16
  • 17. The repository  Your top-level working directory contains everything about your project  The working directory probably contains many subdirectories—source code, binaries, documentation, data files, etc.  One of these subdirectories, named .git, is your repository  At any time, you can take a “snapshot” of everything (or selected things) in your project directory, and put it in your repository  This “snapshot” is called a commit object  The commit object contains (1) a set of files, (2) references to the “parents” of the commit object, and (3) a unique “SHA1” name  Commit objects do not require huge amounts of memory  You can work as much as you like in your working directory, but the repository isn’t updated until you commit something 17
  • 18. init and the .git repository  When you said git init in your project directory, or when you cloned an existing project, you created a repository  The repository is a subdirectory named .git containing various files  The dot indicates a “hidden” directory  You do not work directly with the contents of that directory; various git commands do that for you  You do need a basic understanding of what is in the repository 18
  • 19. Making commits  You do your work in your project directory, as usual  If you create new files and/or folders, they are not tracked by Git unless you ask it to do so  git add newFile1 newFolder1 newFolder2 newFile2  Committing makes a “snapshot” of everything being tracked into your repository  A message telling what you have done is required  git commit –m “Uncrevulated the conundrum bar”  git commit  This version opens an editor for you the enter the message  To finish, save and quit the editor  Format of the commit message  One line containing the complete summary  If more than one line, the second line must be blank 19
  • 20. Commits and graphs  A commit is when you tell git that a change (or addition) you have made is ready to be included in the project  When you commit your change to git, it creates a commit object  A commit object represents the complete state of the project, including all the files in the project  The very first commit object has no “parents”  Usually, you take some commit object, make some changes, and create a new commit object; the original commit object is the parent of the new commit object  Hence, most commit objects have a single parent  You can also merge two commit objects to form a new one  The new commit object has two parents  Hence, commit objects form a directed graph  Git is all about using and manipulating this graph 20
  • 21. Working with your own repository  A head is a reference to a commit object  The “current head” is called HEAD (all caps)  Usually, you will take HEAD (the current commit object), make some changes to it, and commit the changes, creating a new current commit object  This results in a linear graph: A  B  C  … HEAD  You can also take any previous commit object, make changes to it, and commit those changes  This creates a branch in the graph of commit objects  You can merge any previous commit objects  This joins branches in the commit graph 21
  • 22. Commit messages  In git, “Commits are cheap.” Do them often.  When you commit, you must provide a one-line message stating what you have done  Terrible message: “Fixed a bunch of things”  Better message: “Corrected the calculation of median scores”  Commit messages can be very helpful, to yourself as well as to your team members  You can’t say much in one line, so commit often 22
  • 23. Typical workflow  git pull remote_repository  Get changes from a remote repository and merge them into your own repository  git status  See what Git thinks is going on  Use this frequently!  Work on your files (remember to add any new ones)  git commit –m “What I did”  git push 23
  • 24. Multiple versions 24 Initial commit Second commit Third commit Bob gets a copy Fourth commit Merge Bob’s commit
  • 25. Initialization C:> mkdir CoolProject C:> cd CoolProject C:CoolProject > git init Initialized empty Git repository in C:/CoolProject/.git C:CoolProject > notepad README.txt C:CoolProject > git add . C:CoolProject > git commit -m 'my first commit' [master (root-commit) 7106a52] my first commit 1 file changed, 1 insertion(+) create mode 100644 README.txt
  • 26. Branches Illustrated master A > git commit –m ‘my first commit’> git commit –m ‘my first commit’
  • 27. Branches Illustrated master > git commit (x2)> git commit (x2) A B C
  • 28. Branches Illustrated bug123 master > git checkout –b bug123> git checkout –b bug123 A B C
  • 29. Branches Illustrated master > git commit (x2)> git commit (x2) A B C D E bug123
  • 30. Branches Illustrated master > git checkout master> git checkout master A B C D E bug123
  • 31. Branches Illustrated bug123 master > git merge bug123> git merge bug123 A B C D E
  • 32. Branches Illustrated master > git branch -d bug123> git branch -d bug123 A B C D E
  • 34. Branches Illustrated master A B C D E F G bug456 > git checkout master> git checkout master
  • 35. Branches Illustrated master A B C D E F G > git merge bug456> git merge bug456 H bug456
  • 36. Branches Illustrated master A B C D E F G > git branch -d bug456> git branch -d bug456 H
  • 38. Branches Illustrated master A B C D E > git rebase master> git rebase master F’ G ’ bug456
  • 39. Branches Illustrated master A B C D E > git checkout master > git merge bug456 > git checkout master > git merge bug456 F’ G ’ bug456
  • 40. Keeping it simple  If you:  Make sure you are current with the central repository  Make some improvements to your code  Update the central repository before anyone else does  Then you don’t have to worry about resolving conflicts or working with multiple branches  All the complexity in git comes from dealing with these  Therefore:  Make sure you are up-to-date before starting to work  Commit and update the central repository frequently  If you need help: https://help.github.com/ 40
  • 41. The End 41 When I say I hate CVS with a passion, I have to also say that if there are any SVN [Subversion] users in the audience, you might want to leave. Because my hatred of CVS has meant that I see Subversion as being the most pointless project ever started. The slogan of Subversion for a while was "CVS done right", or something like that, and if you start with that kind of slogan, there's nowhere you can go. There is no way to do CVS right. --Linus Torvalds, as quoted in Wikipedia

Notas do Editor

  1. Git was originally created by Linus for work on the Linux kernel right around 2005. Although git has its origins in the Open source community, git is being used within close source projects also. This is just some of the many companies that are using git for both oss and closed sourced projects.
  2. This is over simplifying the story, but the basics are that centralized version control system define a central authority. I am not saying one system is better that the other, it is just that each model that its benefits. In the distributed model by definition everything is expected to be off line. To have a system that expects everything to be offline, you have to build in several local capabilities that are not required in a centralized model. Such as local branching. And to make branching fast and lightweight you better make merging great also. I won’t go into the guts of git that enables some of this capability in this talk, but if you are interested I will highlight some resources at the end of the talk where you can go deeper.
  3. After you install git on your machine to get started you will need to initialize a repository. You can do this by going into your file system, creating a folder and doing git init within the folder. All the magic happens in the Dot Git folder. This folder IS GIT. You can copy this folder to another machine and it will work. When I first started playing with git, I had setup a new machine, and was having a hell of a time trying to figure out how I should move my git projects over to the new machine. It was kind of embarrassing. Eventually I just tried to copy it over and it worked. At this point you really don’t have much. You need to do your first commit to make this light up. You create a file. When then stage it, but telling git the track this file. In this case I told git to add all files. Then I was able to commit with a message say this is my first commit.
  4. Now lets see what this visually looks like. On my first commit I have A. The default branch that gets created with git is a branch names Master. This is just a default name. As I mentioned before, most everything in git is done by convention. Master does not mean anything special to git.
  5. We make a set of commits, moving master and our current pointer (*) along
  6. Suppose we want to work on a bug. We start by creating a local “story branch” for this work. Notice that the new branch is really just a pointer to the same commit (C) but our current pointer (*) is moved.
  7. Now we make commits and they move along, with the branch and current pointer following along.
  8. We can “checkout” to go back to the master branch. This is where I was freaked out the first time I did this. My IDE removed the changes I just made. It can be pretty startling, but don’t worry you didn’t lose anything.
  9. And then merge from the story branch, bringing those change histories together.
  10. And since we’re done with the story branch, we can delete it. This all happened locally, without affecting anyone upstream.
  11. Let’s consider another scenario. Here we created our bug story branch back off of (C). But some changes have happened in master (bug 123 which we just merged) since then. And we made a couple of commits in bug 456.
  12. Again, to merge, we checkout back to master which moves our (*) pointer.
  13. And now we merge, connecting the new (H) to both (E) and (G). Note that this merge, especially if there are conflicts, can be unpleasant to perform.
  14. Now we delete the branch pointer. But notice the structure we have now. This is very non-linear. That will make it challenging to see the changes independently. And it can get very messy over time.
  15. Rebase flow - Let’s go back in time and look at another approach that git enables. So here we are ready to merge.
  16. Instead of merging, we “rebase”. What this means is something like this: 1. Take the changes we had made against (C) and undo them, but remember what they were 2. Re-apply them on (E) instead
  17. Now when we merge them, we get a nice linear flow. Also, the actual changeset ordering in the repository mirrors what actually happened. (F’) and (G’) come after E rather than in parallel to it. Also, there is one fewer snapshots in the repository.