Undefined Rants

Code, Ramen and Avocado

Local SVN Repository Workflow

This tutorial will outline the simple workflow to create a SVN local repository. Of course you can get a free online repository from website like assembla. However for simplicity and first time, I will just create a repository on local machine.

Installing

If you do not have SVN installed on your machine, you can go and grab it here according to your OS.

1
2
3
# for Ubuntu/Debian user
$ apt-get install subversion
$ apt-get install libapache2-svn

Create repository

Let’s start by creating a new repository. (Substitude user with your username or you can use ~/ to replace /home/user/)

1
2
3
$ mkdir /home/user/repo                  # Creates a directory 'repo'
$ cd /home/user/repo
$ svnadmin create alpha_project           # Creates a repository 'alpha_project'

The svnadmin program is the repository administrator’s best friend. In this case, we used it to create a new Subversion repository, but this program can also be used to preform several maintenance operations.

Import project

The new created alpha_project repository is empty. So let’s import some project into it. Let’s say we had some project in our /home/user/code directory.

1
2
3
$ svn import /home/user/code` file:///home/user/repo/alpha_project/trunk -m "Init alpha_project"
...
Committed revision 1.

This command import our project in /home/user/code into the repository. Notice that we store our data in another folder trunk by following SVN repository layout convention.

Most projects have a recognizable “main line”, or trunk, of development; some branches, which are divergent copies of development lines; and some tags, which are named, stable snapshots of a particular line of development.

And normally here is what it looks like in a SVN single project.

1
2
3
4
$ svn list file:///home/user/repo/alpha_project
trunk/
branches/
tags/

This tutorial won’t talk much about tags and branches (It’s ok to not create these 2 files). And for the message inside double quotations after -m is called commit. Commit is a message to record who and when created the change and who committed it. You can think of it as a message to describe the changes.

Checkout

Now we have our project in the repository, but we are not going to do our work there. Instead, we create another directory by checkout from it, and work on this directory.

1
2
3
$ svn checkout file:///home/user/repo/alpha_project/trunk /home/user/alpha_project_copy
...
Checkout revision 1.

This duplicate a working copy of the repository into alpha_project_copy directory. We’ll do our work here. After we’ve done our work, we will commit these changes back to the repository.

1
2
3
4
$ svn commit -m "Fixed bugs in footer"
...
...
Committed revision 2.

Always commit your message with short and meaningful description. Let’s say if we have another collaborator who is doing this project together. She made some changes to the project and commit it to the repository. For instance, in this case a revision 3 is committed but our working copy remains revision 2. To update our working copy to the latest changes,

1
$ svn update

I concluded the basic workflow of SVN in this tutorial. There are still a lot SVN can do.

Resource

Comments