Hello, my name is Robert Lee-Cann and I’m a web developer. In this talk I’ll be introducing you to the basic concepts of version control - what it is, how it works and the benefits it will bring to your development workflow.
Hello, my name is Robert Lee-Cann and I’m a web developer. In this talk I’ll be introducing you to the basic concepts of version control - what it is, how it works and the benefits it will bring to your development workflow.
Beginner’s Guide to Version Control with GitPresentation Transcript
G it’s the way
to do it!
G it’s the way
to do it!
A Beginnerʼs Guide to
Version Control with Git.
What is
Version Control?
What is
Version Control?
• Allows you to keep a history of every change
within a project.
What is
Version Control?
• Allows you to keep a history of every change
within a project.
• Allows multiple people to collaborate on the
same project, without evil stuff happening.
What is
Version Control?
• Allows you to keep a history of every change
within a project.
• Allows multiple people to collaborate on the
same project, without evil stuff happening.
• All files (and historical versions) are backed-
up automatically.
What is Git?
What is Git?
• Created by Linus Torvalds.
What is Git?
• Created by Linus Torvalds.
• Run locally, with no server needed.
What is Git?
• Created by Linus Torvalds.
• Run locally, with no server needed.
• Works offline.
What is Git?
• Created by Linus Torvalds.
• Run locally, with no server needed.
• Works offline.
• Command-line or GUI.
Installation
Installation
• Windows:
http://code.google.com/p/msysgit/
• Mac OSX:
http://code.google.com/p/git-osx-installer/
• Linux:
Packages available for most distros, or build from
source.
Configuring Git
• Configure your name and email address.
git config --global user.name = ‘leeky’
git config --global user.email = ‘leeky@leeky.org.uk’
• Using ‘--global’ makes these the default value
for all projects.
Starting a New
Git-Managed Project
Starting a New
Git-Managed Project
• Create directory for project.
Starting a New
Git-Managed Project
• Create directory for project.
• cd into project directory.
Starting a New
Git-Managed Project
• Create directory for project.
• cd into project directory.
• Type git init to initialise Git for this
project.
Starting a New
Git-Managed Project
• Create directory for project.
• cd into project directory.
• Type git init to initialise Git for this
project.
Initialized empty Git repository in /git/demo/.git/
Terminology
• Repository - where the current and historical
file data is stored.
• Working copy - the local copy of files from a
repository, at a specific time or revision.
• Commit - copy files from your working copy to
the repository.These changes are stored together
as an individual revision.
Basic Git Workflow
1. Add, edit and delete files in your project in
the normal way, using your favourite editor
(e.g. TextMate,Vi, Dreamweaver etc).
2. Tell Git which file(s) are to be saved into the
new commit using git add
3. Commit files to repository using git commit.
Demo
Git Commands
• git status - View status of working copy.
• git add - Add unstaged changes.
- git add {filename} {filename} ...
- git add .
• git commit - Commit changes to repository.
- git commit -m “{message}”
More Git Commands
• git diff- Shows differences between
working copy and last revision.
• git log - Shows the history log.
- git log {filename} - Restrict log to file(s)
• git blame {filename} - Shows when/who
made changes to a file.
Git GUI
• Launch by running git gui in your project’s
directory.
• Gives you ability to add files and create
commits without using the command line!
Gitk
• Launch by running gitk in your project’s
directory.
• Allows you to browse the entire history of
your project and see when and by whom
files were changed.
Gitk
• Launch by running gitk in your project’s
directory.
• Allows you to browse the entire history of
your project and see when and by whom
files were changed.
Branching
• Allows experimental features to be
developed separately, without affecting stable
code.
Branching
• Allows experimental features to be
developed separately, without affecting stable
code.
• Branches can be easily created and later
merged together.
Branching
• Allows experimental features to be
developed separately, without affecting stable
code.
• Branches can be easily created and later
merged together.
Master Master
Branching
• Allows experimental features to be
developed separately, without affecting stable
code.
• Branches can be easily created and later
merged together.
Master Master
git branch Branch Branch
Branching
• Allows experimental features to be
developed separately, without affecting stable
code.
• Branches can be easily created and later
merged together.
Master Master Master Master
git branch Branch Branch
Branching
• Allows experimental features to be
developed separately, without affecting stable
code.
• Branches can be easily created and later
merged together.
Master Master Master Master Master
git branch Branch Branch git merge
Working with Branches
Working with Branches
• git branch
- git branch - View branches.
- git branch {branchname} - Create a new
branch.
Working with Branches
• git branch
- git branch - View branches.
- git branch {branchname} - Create a new
branch.
• git checkout {branchname} - Switch to
another branch.
Working with Branches
• git branch
- git branch - View branches.
- git branch {branchname} - Create a new
branch.
• git checkout {branchname} - Switch to
another branch.
• git checkout -b {branchname} - Create new
branch and immediately switch to it.
Merging Branches
Merging Branches
Merge otherbranch into mainbranch:
Merging Branches
Merge otherbranch into mainbranch:
• git checkout {mainbranch}
Conflict Resolution
CONFLICT (add/add): Merge conflict in foo
Automatic merge failed; fix conflicts and
then commit the result.
Conflict Resolution
D O N ʼT
CONFLICT (add/add): Merge conflict in foo
IC !
Automatic merge failed; fix conflicts and
then commit the result.
N
PA
Conflict Resolution
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 1 and 1 different commit(s) each, respectively.
#
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
#
# unmerged: foo
# no changes added to commit (use "git add" and/or "git commit -a")
Conflict Resolution
la la la
<<<<<<< HEAD:foo
wish
dog
cow
cat
=======
moo cow
fish
>>>>>>> 0cb13d1ceabf7e579b423815d8314fca0475ab7f:foo
Conflict Resolution
• Merge manually.
• Commit the merge.
In this talk I’ll be introducing you to the basic concepts of version control - what it is, how it works and the benefits it will bring to your development workflow.
In this talk I’ll be introducing you to the basic concepts of version control - what it is, how it works and the benefits it will bring to your development workflow.