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
Thanks for this i’m using it for a project in netbeans
and everything is fine.
my home folder is looking much simpler
john
28 Sep 10 at 00:36
Exactly what I needed… the official docs at:
http://svnbook.red-bean.com/en/1.5/svn.tour.importing.html
somehow make this simple process quite obscure.
Derek
14 Dec 10 at 10: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.
John
2 Mar 11 at 17:18
Thanks a lot for such a well written guide.
Worked like a charm and saved me a lot of trouble.
May the force be with you.
Aniket Thakkar
3 Mar 11 at 14:49
[...] Today I have create the svn repository for my project by referring the blog http://www.guyrutenberg.com/2007/10/29/creating-local-svn-repository-home-repository/ [...]
Created SVN repo for our diagnosis project | Tux Coder
1 Apr 11 at 13:11
Thanks bro. Good one. Now I’m thinking of a web interface to for the repo. Any ideas?
Hamid
11 Jun 11 at 09:17
I’ll have to recommend Trac, it’s pretty simple to use, has nice feature set and large users base.
Guy
11 Jun 11 at 10:17
[...] (this is half of the first step from this tutorial). [...]
Creating a New Local SVN Repository for Subclipse « See-Why
13 Jul 11 at 22:45
Thanks for the time to post this – having the world moving on from cs to svn its time for myself on my personal systems.
Gregg
14 Aug 11 at 09:46
Great explanation, well shown steps, thank you very much!
macias
22 Aug 11 at 09:19
simple and superb tutorial, i was looking for this and it works great. so many thanks!
nur
23 Aug 11 at 01: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
mike_bronson
19 Sep 11 at 18:39
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.
Guy
19 Sep 11 at 19:15
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?
mike_bronson
23 Sep 11 at 11:44
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.
mike_bronson
23 Sep 11 at 17:22
Well, so what about Windows’s user
?
kachwahed
1 Dec 11 at 19:53
[...] Rutemberg on Creating Local SVN Repository (with svn command line [...]
Version Control in Flash Builder: installation and setup | Davide Barranca
22 Dec 11 at 00:20
[...] Rutemberg blog, Creating Local SVN Repository (con il tool a riga di comando [...]
Subclipse Version Control in Flash Builder: installazione e setup | Davide Barranca
23 Dec 11 at 01:15
Thanks for the tutorial! Very useful and to the point.
Cheers!
Ever
2 Jan 12 at 16:32