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.

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

  1. some people like pain. why use the command line client and memorize commands when there are plenty of graphic clients that will do everything for you at a click of a mouse?

  2. Tsahi,

    command line clients aren’t pain. One of the greatest strengths (in my opinion) of SVN over CVS is much more convenient command line interface.

    I checked several graphic interfaces for SVN and didn’t like them, SVN commands are so elegant, it’s actually fun using them.

  3. Excellent….I have been looking for tutorial to create an SVN repository and yours just works… I don’t really need svn for my little project but I want to learn more about svn…

    Tsahi: use GUI if you like but let us use command line if we like it…

  4. Philippe,
    I’m glad you found what you looked for.
    Small project tend to grow with time and svn repositories are easy to setup and maintain. I use a local repository for every project that passes some initial state (and has couple of files), and it’s really no hassle, you can always get rid of the repository later.

  5. Hey, thanks for this great article. I’ve always used svn for big official work projects, but it’s so nice to have streamlined versions of offhand stuff, instead of an ugly mass of slightly-differently named files.

    Note to people like Tsahi: if you become One with the Unix Way, you will gain simplicity and peace of mind. Using small, unbreakable parts to do routine low-level tasks cultivates the right mindset for programming: although the simplest way may seem the most difficult, simplicity prevails in all things, and we should strive thus after Nature. 🙂

  6. Regardless of whether you prefer a GUI or not, knowing the terminal commands is still useful: for example, I’m working on a project at school, and I don’t have access to any SVN GUIs. Hence, this tutorial is very useful to me.

    Thanks, Guy!

  7. Thanks very much for this tutorial. I’ve been looking for this for ages, because I was told that you *need* an Apache to do this. Now I know better.

    Thanks.

  8. Nice tutorial. I was planning to implement a backup script for my pendrive, but svn works like a charm!
    Thank you!

  9. I like your guide as it also works as a beginner’s guide to subversioning. Finally I got around myself to learn the basics. I was going to mention about the use of version control systems with other works than code, but you already did it. Writing thesis has never been so wonderful when the old revisions are there in safe.

  10. Very useful! I set up a local repo for a PHP-based project that utilizes BuddyPress (a set of social networking plugins that sits on top of WordPress)…now if I can just figure out how to layer in three trunks (WordPress, BuddyPress, and my local trunk) into one build… 🙂

  11. “some people like pain…”

    Although I in general tend to avoid command line programs and go for GUIs, I actually prefer SVN command line commands to the SVN GUI clients I’ve tried.

    I find typing some commands like “svn merge ^/trunk” (updating branch in current dir from changes in trunk) way easier than in the corresponding GUI versions…

  12. yes, you can configure access via ssh, you just need to give users the right permission to the repository dir.

  13. > some people like pain.
    > why use the command line client …

    Becouse often in my work I have to use only console access to production server.

    In addition, it trains the memory 🙂

  14. Thanks, man. A simple and objective article. I’ve been working with SVN a year ago, but was forgetting a lot of things.

  15. Thanks for this i’m using it for a project in netbeans
    and everything is fine.

    my home folder is looking much simpler

  16. I found it works great with dropbox. Simply create the repository in your Dropbox folder and it will automatically sync whenever you check something in and you’ll always have the repo on dropbox if you ever lose your local store.

  17. Thanks bro. Good one. Now I’m thinking of a web interface to for the repo. Any ideas?

  18. I’ll have to recommend Trac, it’s pretty simple to use, has nice feature set and large users base.

  19. Thanks for the time to post this – having the world moving on from cs to svn its time for myself on my personal systems.

  20. simple and superb tutorial, i was looking for this and it works great. so many thanks!

  21. How do I update the original project’s files?

    I did as described above:
    mkdir ~/svnrepo/; cd ~/svnrepo
    svnadmin create www-repo
    svn import /var/www/current-website file:///home/user/svnrepo/www-repo/trunk
    svn co file:///home/user/svnrepo/www-repo/trunk ~/work-in-progress/www

    I made changes.

    svn commit ~/work-in-progress/www -m ‘Users registration now with Ajax’

    But my /var/www/current-website isn’t in the repository therefore I can’t update it to revision 2 like this:

    cd /var/www/current-website
    svn update

  22. You can’t check out to the current-website, as it isn’t a working copy. There are two solutions you could consider. Either you cd into current-website and checkout from the repository, thus turning the dir into a working copy, or else, overwrite changed files using svn export.

  23. One more question – will checking out to the current-website directory redownload all the files from the repo? Or does it somehow compare those?

    What’s the difference between checking out and exporting?

  24. OK, I got it. I can:

    svn import /var/www/current-website file:///home/user/svnrepo/www-repo/trunk
    svn co –force file:///home/user/svnrepo/www-repo/trunk /var/www/current-website

    then I will have a WC in my current-website directory and I can cd and just:

    svn up

    anytime I want to pull the newest revision on production.

  25. Thanks! Simple and useful.

    “Well, so what about Windows’s user?”

    @kachwahed: Install Cygwin (linux tools for windows). http://www.cygwin.com/. While you are installing, choose “subversion” as one of the packages you wish to install.

  26. Hey !! I will let you know the complete steps from creating a svn repo to finally committing your code back.
    $ mkdir /home/admin/svnrepo
    $ cd ~/svnrepo
    $ svnadmin create svn_projects
    $ svn checkout https:/192.168.1.(…)/svn/SevyaMM/Projects/harsh_svnrepo /home/admin/svnrepo/svn_projects/mynewstuff
    $ cd mynewstuff/
    $ mkdir lab1
    $ svn add lab1
    $ cd lab1/
    $ mkdir trunk branches tags
    $ ls
    branches tags trunk
    $ cd trunk
    pwd
    /home/admin/svn_repo/svn_projects/mynewstuff/lab1/trunk$ vi helloworld.c
    $ cd .. ; # Very important step
    $ pwd
    /home/admin/svn_repo/svn_projects/mynewstuff/lab1
    $ svn add *
    $ svn commit -m “Initial checkout done !!”
    $ svn update
    ————Done—————————–

  27. At first, thank all of you for the excellent initiative. I really believe that start using repositories will be of great benefit to me.

    Still, I am having problems in proceeding the step 3:

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

    I have, of course, created a /home/yuri/svnrep/project1 directory, with a plain text file for sample called “first_file”, still, when I perform this step, the following error message shows up:

    svn: Unable to open an ra_local session to URL
    svn: Unable to open repository 'file:///home/yuri/project1/trunk'

    Do anyone here have any idea of what am I doing wrong?

    Grateful for your attention.

  28. i did everything as above but its giving me an error message. using cygwin.
    svn: E205000: Try ‘svn help’ for more info
    svn: E205000: Too many arguments to import command

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.