Best Practices for Initializing Trunk, Branches and Tags in a New SVN Repository


5 views

When setting up a new Subversion (SVN) repository, creating the standard directory structure (trunk, branches, and tags) is crucial for proper version control workflow. These directories serve distinct purposes:

  • Trunk: Main development line
  • Branches: Parallel development paths
  • Tags: Snapshots of specific states

The best practice is to create these directories immediately after repository creation, before any project files are added. This ensures clean version history and proper organization from the start.

Instead of creating each directory separately, you should create them all in a single atomic commit:

svn mkdir -m "Initial repository structure" \
file:///path/to/repo/trunk \
file:///path/to/repo/branches \
file:///path/to/repo/tags

This approach has several advantages:

  • Single revision (1) for the entire structure
  • Clean history without intermediate states
  • Atomic operation ensures consistency

Another method is to create a temporary local directory with the desired structure and import it:

mkdir temp-repo-structure
mkdir temp-repo-structure/trunk
mkdir temp-repo-structure/branches
mkdir temp-repo-structure/tags
svn import -m "Initial repository layout" \
temp-repo-structure file:///path/to/repo
rm -rf temp-repo-structure

After creation, verify the structure with:

svn ls file:///path/to/repo

You should see:

branches/
tags/
trunk/
  • Creating directories separately (results in multiple revisions)
  • Adding project files before establishing structure
  • Using non-standard naming conventions

Once created, standard workflow patterns apply:

# Checkout trunk
svn checkout file:///path/to/repo/trunk my-project

# Create a branch
svn copy file:///path/to/repo/trunk \
file:///path/to/repo/branches/feature-x \
-m "Creating feature branch"

When you create a new Subversion (SVN) repository using svnadmin create, you're essentially creating an empty container. The standard practice is to immediately set up the trunk, branches, and tags directory structure - this is known as repository "skeleton" creation.

The cleanest method is to create the entire structure in a single revision (revision 1). Here's the precise sequence:

svn mkdir file:///path/to/repo/trunk \
    file:///path/to/repo/branches \
    file:///path/to/repo/tags \
    -m "Creating initial repository structure"

Creating all three directories in one atomic commit:

  • Maintains repository cleanliness
  • Follows SVN best practices from the start
  • Prevents confusion about directory purposes
  • Makes future operations like branching simpler

For projects with existing code, you might prefer:

# Create local directory structure
mkdir project-structure
mkdir -p project-structure/{trunk,branches,tags}

# Import into repository
svn import project-structure file:///path/to/repo \
    -m "Initial import of project structure"

I've seen developers make these mistakes:

  • Creating directories separately (resulting in multiple revisions)
  • Placing project files directly in repository root
  • Using non-standard directory names like "branch" instead of "branches"

For a Python project, your first checkout would look like:

svn checkout file:///path/to/repo/trunk myproject
cd myproject
# Add your initial code files here
svn add *.py
svn commit -m "Initial project files"

While the standard layout is recommended, some organizations modify it. For example:

svn mkdir file:///path/to/repo/projects \
    file:///path/to/repo/projects/myproject \
    file:///path/to/repo/projects/myproject/trunk \
    file:///path/to/repo/projects/myproject/branches \
    file:///path/to/repo/projects/myproject/tags \
    -m "Creating project-specific structure"