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.
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?
Tsahi
30 Oct 07 at 22:49
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.
Guy
30 Oct 07 at 23:16
Thanks for the post!
I’ve just set up the same directory layout as yours for all my important projects. Looks great!
László Monda
14 Nov 07 at 01:01
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…
Philippe
13 Mar 08 at 00:15
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.
Guy
13 Mar 08 at 12:13
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.
jared
14 Apr 08 at 16:02
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!
Nimnio
13 May 08 at 21:49
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.
Hansen
24 Nov 08 at 12:08
[...] Creating Local SVN Repository (Home Repository) at Guy Rutenberg free-software tutorial, tips and projects [...]
crawlspace|media » Blog Archive » Daily Ma.gnolia Links for January 09
10 Jan 09 at 10:03
Nice tutorial. I was planning to implement a backup script for my pendrive, but svn works like a charm!
Thank you!
guilherme
9 Apr 09 at 13:58
Nice tutorial, really simple and good. Thanks for taking your time!
Paulo
29 Sep 09 at 10:00
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.
Myke
13 Nov 09 at 18:10
[...] googlasin vähän tietoa, kuinka luoda lokaali svn-repository lokaaliin käyttöön. Onneksi se oli helppoa, kyllä [...]
Rakenteisuuden perässä « progon progoilut
15 Nov 09 at 17:22
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…
American Yak
2 Jan 10 at 19:36
“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…
Petter
19 Jan 10 at 20:58
Hi,
Can we access svn repository in a local intranet?
Thanks.
Harpreet Singh
Harpreet Singh
17 Feb 10 at 13:36
yes, you can configure access via ssh, you just need to give users the right permission to the repository dir.
Guy
17 Feb 10 at 22:17
Thanks a lot. That’s simple & handy !
Fedir
6 Apr 10 at 18:31
you’re my hero! thank you so much for the tips!!
pixelblender
25 Apr 10 at 06:46
> 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
paul
27 Apr 10 at 00:31
Thanks, man. A simple and objective article. I’ve been working with SVN a year ago, but was forgetting a lot of things.
Eduardo
22 Aug 10 at 07:11