Avoiding svn import

The usual workflow for Subversion when putting an existing project under version control, and the one documented in the popular Version Control with Subversion book, is using svn import:

$ svn import /home/you/yourproject svn://vcs.network/yourproject/trunk -m "Import."

This gets the results you need, but realistically it often happens that you’ve already started your project, and in some cases it may even be live to some extent. This means that if you want the instance of the project that you just imported to also become a working copy of the project, you need to do something like this:

$ cd /home/you
$ mv yourproject yourproject.imported
$ svn checkout svn://vcs.network/yourproject/trunk yourproject

Or possibly this:

$ cd /home/you/yourproject
$ svn checkout --force svn://vcs.network/yourproject/trunk .

There’s a tidier way of managing this that completely avoids the use of the import command, turning the imported copy directly into your first working copy, and also allows you finer-grained control over which files should be included in the repository. Create an empty repository on your server, check its trunk out directly inside the existing project directory, add everything you want to add (including svn:ignore for files you don’t, among other properties), and commit it:

$ svn mkdir svn://vcs.network/yourproject/{branches,tags,trunk} -m "Recommended structure"
$ cd /home/you/yourproject
$ svn checkout svn://vcs.network/yourproject/trunk .
$ svn add file1.c file1.h README.txt
$ svn propset svn:ignore '*.o' .
$ svn commit -m "First commit."

Using this means in most cases you can completely eschew the use of svn import, and you might well find that you don’t miss it.