Branching

When you create a branch, CVS effectively creates another copy of a file or files and lets you edit either version. CVS keeps track of which changes apply to which version.

The main development stream in CVS is called the head. You could decide to develop new features on the head branch and create separate branches for released software.

Figure 1. Branching a file in CVS.

For example, let's suppose you're releasing version 1.0 of your new product, Stella, and that this product includes a file called foo.c. You can create a branch for this release like this:

cvs tag -b "Stella_1.0" foo.c

The tag, Stella_1.0, is a sticky tag; any changes that you make in your sandbox are associated with the Stella_1.0 branch, not the head. If you want to work on the head, you can update your sandbox, specifying the -A option, which clears the sticky tags:

cvs update -A

or:

cvs up -A

What if you need to have both versions checked out? You could keep updating your sandbox to use the head (as shown above) and the branch (cvs update -r Stella_1.0), but keeping track of which version you're working on could be difficult. Instead, you can check out the branch in another directory:

cd ~/cvs
mkdir version1.0
cd version1.0
cvs checkout -r Stella_1.0 path_to_the_files