Source

slides / use-version-control / use-version-control.md

Full commit

!SLIDE

Using Version Control Will Make You Happy

!SLIDE

Hi, I'm Steve Losh

!SLIDE

Senior Software Engineer at

Dumbwaiter Design

!SLIDE

These slides are at slides.stevelosh.com if you want to follow along now or check them out later.

!SLIDE

We need to talk about version control.

!SLIDE

What kind of things are you working on right now?

!SLIDE

Maybe something like:

  • A website
  • Some blog posts
  • A thesis
  • A book
  • An iPhone app

!SLIDE

Version control can make your life easier.

!SLIDE

So what is version control?

!SLIDE

A version control system keeps track of versions of files on your computer.

!SLIDE

You've probably all seen some kind of version control.

!SLIDE images

Dropbox

Dropbox example

!SLIDE images

Writeboard

Writeboard example

!SLIDE images

Time Machine

Time Machine example

!SLIDE images

Wikipedia

Wikipedia example

!SLIDE

All of those sites keep track of versions of your files.

!SLIDE

You can go back in time to any version and see what the file looked like at that point.

!SLIDE

What if you don't want to put your files online?

 

What about files on your own computer?

 

What about keeping track of whole folders?

!SLIDE

Wouldn't it be nice to be able to keep track of your important files without uploading them somewhere?

!SLIDE

You could just copy the files, right?

!SLIDE omg

NO

!SLIDE omg

STOP

!SLIDE images

Let go of the Ctrl and C keys.

!SLIDE images

This is unacceptable.

Not Version Control, Not Even a Little Bit

!SLIDE

We can do better.

!SLIDE

This is a version control system:

Mercurial

 

And so is this:

Git

!SLIDE

Why should you care?

!SLIDE images

Let's look at an example. Here's my website:

stevelosh.com

!SLIDE

Wouldn't it look cool if I staggered the navigation?

!SLIDE

… code for 30 minutes …

!SLIDE images

Hmm, I'm not sure about this

stevelosh.com staggered

Wait a second…

!SLIDE images

Oh god what was I thinking?

stevelosh.com staggered blog

!SLIDE

How do you go back to the good version?

!SLIDE

Without version control:

  1. Pour a glass of whiskey
  2. Code for 30 more minutes

!SLIDE

With version control:

  1. hg revert --all or git reset --hard

!SLIDE

Version control just saved you:

  1. 30 minutes
  2. A glass of whiskey

!SLIDE

Whiskey is expensive, so let's all use version control, okay?

!SLIDE

Let's take a closer look.

!SLIDE

You're working on a website (or a book, or anything else).

 

You "check in" your changes as you work.

!SLIDE

This gives you a record of your changes.

 

It also lets you blow away bad ideas easily.

!SLIDE

So how does it work?

!SLIDE images

You've got a folder containing your project.

Normal website folder

!SLIDE images

Now add another folder inside it, containing a magic kitten.

Version controlled website folder

!SLIDE

The kitten will keep track of each version of your project.

!SLIDE

How does it really work?

!SLIDE

Every time you "commit" the current state of your project is recorded by the kitten.

 

"Commit" means "tell the kitten to remember this version of the project."

!SLIDE images

After committing five times, your folder looks like this:

Reality

!SLIDE

Suppose you make some changes and decide you don't really like them.

!SLIDE

Now you can say:

 

"Kitten, I was foolish! <br/> Please restore my project to how it looked when I last committed!"

!SLIDE images

The kitten will then restore your files.

Restore latest

!SLIDE

Of course, you could also say:

&nbsp;

"Kitten, restore my project to version 2!"

!SLIDE images

The kitten will then restore your files to how they looked in version 2.

Restore v2

!SLIDE

You can use version control to restore any committed version.

!SLIDE

How else can version control help?

!SLIDE

What if you're collaborating on a book with someone else?

!SLIDE

You each have a copy of the book.

!SLIDE

Your friend makes a change to chapter 2.

!SLIDE

How do you get that change into your own copy?

&nbsp;

Copy the entire file that holds chapter 2?

!SLIDE omg

NO

!SLIDE

What if you made your own changes to chapter 2?

!SLIDE

Copying the file over would overwrite your changes.

!SLIDE

You could ask them what they changed, and make those changes in your own copy by hand.

!SLIDE

But that sucks.

!SLIDE

It's 2010, we have computers now.

!SLIDE

They can do this kind of work for us&hellip;

!SLIDE

If you're both using version control.

!SLIDE

How?

!SLIDE

You make some changes to your book and "commit" those changes.

!SLIDE

Meanwhile, your friend is doing the same thing.

!SLIDE

You can "pull" your changes from their computer onto yours.

!SLIDE

Now you can "merge" their changes with yours.

!SLIDE

As long as you haven't both changed the same line, the computer can automatically combine their changes with yours.

!SLIDE

Instead of spending 15 minutes with your friend figuring out what you both changed, you'll spend 10 seconds "merging."

!SLIDE

We all have better things to do than trying to figure out what changes we made.

!SLIDE

Let's all use version control to do the busywork for us.

!SLIDE

I haven't talked about how to use version control.

!SLIDE

Unfortunately we don't have enough time to do it right now.

!SLIDE

There are two main version control systems that are popular right now.

!SLIDE

Mercurial

&nbsp;

and

&nbsp;

Git

!SLIDE

It doesn't matter which one you use.

!SLIDE

Try both.

&nbsp;

Pick the one you prefer.

!SLIDE

You'll probably find another one called "Subversion" or "SVN."

!SLIDE

Don't use it.

!SLIDE

Trust me.

!SLIDE

Mercurial and Git are both far better.

&nbsp;

Come talk to me if you want to know why.

!SLIDE

Learn More about Mercurial

!SLIDE

Learn More about Git

!SLIDE

Questions?

!SLIDE

Credits