06 Version Control
06 Version Control
Agile Development
Content
Introduction
Local version control
Remote repositories
Team collaboration with Git
Branching
Version Control
Common Coding Problems
Where is my code / it's on a different computer
What has changed and when?
I’ve broken my program and can’t fix it
I need to work on a different computer
Just Remind
My team members are all working on the same file!
Who has modified the files and when?
Who has been doing to the programming?
Revision Control Systems Exam Question
Need to remember
Purpose
Stores snapshots of a project:
Complete history Need to remember
Can 'rewind' to earlier versions
Can store a copy of a project online (backup)
Allows controlled access by all team members
Control version release
Track issues
Store documentation
Key Features
Backup and Restore (rollback)
Synchronization between developers
Need to remember
Short-term undo (last-known good)
Long-term undo (jump to old version)
Track Changes (to see file evolution)
Track Ownership (blamestorming)
Sandboxing (isolate potentially damaging changes)
Why Use Version Control?
Its very easy to set up and run
Full tracking and audit of project files
It's Open Source (you can download and install it for free)
Need to remember
Git Local Workflow
git checkout Complete record
of all commits
add
new files
Working
Repository
Files
Available for
editing
git add git commit
Staged Files
A group of changes
to be added
What is a Git Repository?
A hidden directory in the project directory
Contains a complete record of all changes (commits)
Can generate a set of working files (checkout)
Each change is recorded with the originator and date/time
Just Remind
Sample .gitignore File
# Comment #
###########
*.com
modules/
temp.md
Branch Head
HEAD
MASTER
Branch Head After 1 Commit
HEAD
MASTER
Branch Head After 2 Commits
HEAD
MASTER
Takeaway
The Git versioning tool can be used to track changes to locally stored code
Changes to groups of modified files are stored and each set of changes includes a
description
Remote Repositories
Watch Recordings
Remote Repositories
Versions of your project hosted on the Internet / network.
Your repository can point to many of these.
Each remote is either read-only or read/write.
Collaborating with others means managing these.
Allowing developers to take working copies of them (clone)
Pushing and pulling data to and from them.
Git Remote Workflow
Complete record git push
git checkout of all commits
add
Repository
new
files Working
Repository
Files
git pull
Available
for editing
git add git commit
Staged
Files
A group of changes
to be added
Creating a Remote Repository
This needs to be created on the remote host (GitHub, GitLab or equivalent)
Must create a blank repository (no files)
Each repository has a unique URL
This will be used to connect to the local repository
Adding a Remote Repository
When adding a remote repository:
You need the remote url
You need to give it a name (default is origin )
Pushing to a Remote / Pulling
Once the remote has been added to the local repository
All the local commits can be pushed to this remote
Any commits that are on the remote but not locally can be pulled
Takeaway
Remote repositories allow for local code to be stored and backed up online
The remote is a complete copy of the local repository including all commits
Local commits can be pushed to the remote
Remote commits can be pulled into the local repository
Team Collaboration with Git
Sharing Code
Each member of the team clones a copy of the remote
Changes and commits are made locally
Two Scenarios:
Commits have been pushed that are not in your local repository
Two developers modify the same file
Git Clone
HEAD
origin ALICE
A B
HEAD
A B
BOB HEAD
A B
Git Commit
HEAD
origin ALICE
C
A B 1
HEAD
A B
BOB HEAD
C
A B 2
Git Push (Alice)
HEAD
origin ALICE
C
A B 1
HEAD
C
A B
1
BOB HEAD
C
A B 2
Git Push (Bob)
HEAD
origin ALICE
HEAD
C
A B 1
HEAD C
1
A B
HEAD
BOB HEAD
C
2 C
A B 2
origin
HEAD
C
A B D
1
C
2
Takeaway
Branching
Watch Recordings
What is a Branch?
A lightweight pointer to a commit
Each repository must have at least one branch
By default it's called master
HEAD
MASTER
LOGIN
HEAD
Committing to the New Branch
Commits are chained to the commit addressed by the branch addressed by the
HEAD pointer.
MASTER
LOGIN
HEAD
After the Commit...
Once the commit is made the pointer addressed by the HEAD pointer is moved to
the latest commit.
All the other branch pointers remain.
MASTER
LOGIN
HEAD
Pushing a Second Commit
This process is repeated for each commit.
MASTER
LOGIN
HEAD
Switching Branches
Switching to another existing branch moves the HEAD
This now points to the branch we switched to.
HEAD
MASTER
LOGIN
Committing to a Second Branch
As before, the new commit is chained to the HEAD
LOGIN
Merging a Branch
Process of pulling branch changes into another branch
Typically we merge back into the master branch
Once done we can delete the extra branch.
Merging a Branch
LOGIN
HEAD
MASTER
Takeaway
Branches are used to develop new features or fix bugs
This keeps the code away from the main product code until it is completed
Working code is merged back into the stable (master) branch
Further Reading