1
CSE 391
Lecture 9
Version control with Git
slides created by Ruth Anderson & Marty Stepp, images from

2
Problems Working Alone
•
Ever done one of the following?
Had code that worked, made a bunch of changes and saved it, which
broke the code, and now you just want the working version back…
Accidentally deleted a critical file, hundreds of lines of code gone…
Somehow messed up the structure/contents of your code base, and want
to just “undo” the crazy action you just did
Hard drive crash!!!! Everything’s gone, the day before deadline.
•
Possible options:
Save as (MyClass-v1.java)
•
Ugh.
Just ugh.
And now a single line change results in duplicating the entire
file…

3
Problems Working in teams
Whose computer stores the "official" copy of the project?
•
Can we store the project files in a neutral "official" location?
Will we be able to read/write each other's changes?
•
Do we have the right file permissions?
•
Lets just email changed files back and forth! Yay!
What happens if we both try to edit the same file?•Bill just overwrote a file I worked on for 6 hours!What happens if we make a mistake and corrupt an important file?•Is there a way to keep backups of our project files?How do I know what code each teammate is working on?

4
Solution: Version Control
•
version control system
: Software that tracks and manages changes
to a set of files and resources.
•
You use version control all the time
Built into word processors/spreadsheets/presentation software
•
The magical “undo” button takes you back to “the version before my last
action”
Wiki’s
•
Wiki’s are all about version control, managing updates, and allowing
rollbacks to previous versions

5
Software Version control
•
Many version control systems are designed and used especially for
software engineering projects
examples: CVS, Subversion (SVN),
Git
, Monotone, BitKeeper, Perforce
•
helps teams to work together on code projects
a shared copy of all code files that all users can access
keeps current versions of all files, and backups of past versions
can see what files others have modified and view the changes
manages conflicts when multiple users modify the same file
not particular to source code; can be used for papers, photos, etc.
•
but often works best with plain text/code files

6
Repositories
•
Repository (aka “repo”)
: a location storing a copy of all files.
you don't edit files directly in the repo;
you edit a local
working copy
or “working tree”
then you
commit
your edited files into the repo
•
There may be only one repository that all users share (CVS,
Subversion)
•
Or each user could also have their own copy of the repository (Git,
Mercurial)
•
Files in your working directory must be
add
ed to the repo in order to
be tracked.

7
