Creating Local SVN Repository (Home Repository)

In this tutorial I will explain how to create a local Subversion (SVN) repository, intended for a single user. I assume that you already know the benefits of keeping track of old revision of projects or important documents such as a resume or a thesis you have been writing. Subversion offers you a very convenient yet strong method to do so, and the easiest way to do so with Subversion (SVN) is to create a local, home, repository intended for a single user – you.

The repository we are going to create will be used by a single user, working locally on the machine. In this tutorial I will assume the repository will be created for a project called “project1”. “project1” can be a real project you are doing, a paper you are writing or any thing else that can be stored under revision control (that almost everything).

Creating the repository

We will start by creating the repository. From the command line do the following:

$ mkdir /home/user/svnrep
$ cd ~/svnrep
$ svnadmin create project1

In the first line we create a directory to house all of your repositories (I assume you are working under the username “user”). I prefer to use different repositories for different projects that are unrelated, no matter how small they are. Because I use many repositories, I prefer to have a single directory underneath all repositories will reside in an organized way (i.e. no junk files or any other kind of stuff except directories). Next thing, is to cd into the directory we created, and actually create the repository using the svnadmin command. To repository we’ve created is called “project1”.

The brand new “project1” repository is currently empty and in revision 0. This will change once we put some data in it. The first thing you do with a new repository is to import initial project data into it.

$ svn import /home/user/project1 file:///home/user/svnrep/project1/trunk -m "Initial import of project1"

Will import the current project1’s file into the repository (assuming that project1 indeed resides in /home/user/project1). The trunk appended to the end of the repository URL, is part of the directory layout convention used by many Subversion users. The last part of the command is the message that will be attached to the import in the SVN log.

Now the repository holds data and you are ready to checkout the code from it, and start working.

Checkout a Working Copy and Start Working

When using SVN (as well as in most revision control systems) you don’t work directly on the repository. Instead you checkout a working copy from it, and work on this copy. To checkout a working copy from the repository, use:

$ svn co file:///home/user/svnrep/project1/trunk /home/user/project1_work

This will create a working copy of the repository under /home/user/project1_work. You can edit this copy safely.

After you’ve done editing your working copy, you will want to commit those changes back to the repository. Assuming you are already inside the directory of the working copy, just do:

$ svn commit -m "Some log message"

This will send you changes back to the repository and store them there. Change the “Some log message” to some useful short description of the changes you’ve made.

Some Useful Commands

To view a list of log messages that were attached to the operations on the repository, use:

$ svn log
$ svn log -r 5:HEAD

The first command will print all log messages. The second command will print the log messages from revision 5 to the latest revision. You can substitute the HEAD with a number to get the log messages of the revisions up to a specific one.

To view the changes you made before committing your code, use:

$ svn diff

Another important command is the one to update your working copy with the latest revision from the repository. This can be done using:

$ svn update

However, since your are the only user of the local repository, you won’t have to use this function often (if at all), unless you use two, or more, working copies for your project.

This concludes this tutorial. I hope you know by now how to create and use, a single user local SVN repository.

67 thoughts on “Creating Local SVN Repository (Home Repository)”

  1. @ Yuri
    M not sure, m also stuck in importing the file. but looking at your input command i think it should b

    $svn import /home/yuri/project1 file:///home/yuri/svnrep/project1/trunk -m ” Initial import”

    But again , m not sure..just thought might b helpful

  2. Thank u so much. it wasn’t working before because my user name had a space in it(danny roy). that was the reason it wasnt working but now that i changed it, its working just fine.
    thank ya’ll

  3. Thank you Guy, even-though I used svn in past 5 years but when I wanted to get back to it, I couldn’t find a simple and fast tutorial for local repository like yours.

  4. hi, is there a way to access this local repository through your network? i was thinking of sharing this local repository to my network.
    thanks…

  5. @Guy thanks for reply, but what i mean is my local repository will acts as a server repository on my network. So other people on my network can do SVN to my computer.

  6. I had an issue where I could commit, but other users could not commit to the local SVN repository. They had errors “readonly” repository. I had to use the following to get it to work

    cd /db
    chmod g+w rep-cache.db

  7. Thank you for the awesome tutorial! Do you find using command line better than using a client for SVN? And what are your thoughts on using a web GUI for the SVN repositories?

  8. Thanks Guy, this tutorial needs to be appearing higher in Google results since it is the only example I’ve found that actually does what it says… really appreciate the clear language and attention to detail.

  9. I’d been stuck in importing my directory to the repository for a while and even after watching quite a few YouTube videos, it still didn’t help much. This article gave me the much needed clarity. Still valid in 2022! Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.