What do “branch”, “tag” and “trunk” mean in Subversion repositories?

In SVN a tag and branch are really similar(Can say, but not really. Read the next answer for more understanding).

Tag = a defined slice in time, usually used for releases

Branch = also a defined slice in time that development can continue on, usually used for major versions like 1.0, 1.5, 2.0, etc, then when you release you tag the branch. This allows you to continue to support a production release while moving forward with breaking changes in the trunk

Trunk = development workspace, this is where all development should happen, and then changes merged back from branch releases.

What do “branch”, “tag” and “trunk” mean in Subversion repositories?

Hmm, not sure I agree with the answer above about a tag being similar to a branch. A tag is just a marker

  • Trunk would be the main body of development, originating from the start of the project until the present.
  • Branch will be a copy of code derived from a certain point in the trunk that is used for applying major changes to the code while preserving the integrity of the code in the trunk. If the major changes work according to plan, they are usually merged back into the trunk.
  • Tag will be a point in time on the trunk or a branch that you wish to preserve. The two main reasons for preservation would be that either this is a major release of the software, whether alpha, beta, RC or RTM, or this is the most stable point of the software before major revisions on the trunk were applied.

In open-source projects, major branches that are not accepted into the trunk by the project stakeholders can become the basis for forks — e.g., totally separate projects that share a common origin with other source code.

The branch and tag subtrees are distinguished from the trunk in the following ways:

Subversion allows sysadmins to create hook scripts that are triggered for execution when certain events occur; for instance, committing a change to the repository. It is very common for a typical Subversion repository implementation to treat any path containing “/tag/” to be write-protected after creation; the net result is that tags, once created, are immutable (at least to “ordinary” users). This is done via the hook scripts, which enforce the immutability by preventing further changes if the tag is a parent node of the changed object.

Subversion also has added features, since version 1.5, relating to “branch merge tracking” so that changes committed to a branch can be merged back into the trunk with support for incremental, “smart” merging.

Answer #3:

In SVN the directory names themselves mean nothing — “trunk, branches, and tags” are simply a common convention that is used by most repositories. Not all projects use all of the directories (it’s reasonably common not to use “tags” at all), and in fact, nothing is stopping you from calling them anything you’d like, though breaking convention is often confusing.

I’ll describe probably the most common usage scenario of branches and tags, and give an example scenario of how they are used.

  • Trunk: The main development area. This is where your next major release of the code lives, and generally has all the newest features.
  • Branches: Every time you release a major version, it gets a branch created. This allows you to do bug fixes and make a new release without having to release the newest – possibly unfinished or untested – features.
  • Tags: Every time you release a version (final release, release candidates (RC), and betas) you make a tag for it. This gives you a point-in-time copy of the code as it was at that state, allowing you to go back and reproduce any bugs if necessary in a past version, or re-release a past version exactly as it was. Branches and tags in SVN are lightweight – on the server, it does not make a full copy of the files, just a marker saying “these files were copied at this revision” that only takes up a few bytes. With this in mind, you should never be concerned about creating a tag for any released code. As I said earlier, tags are often omitted and instead, a changelog or other document clarifies the revision number when a release is made.

For example, let’s say you start a new project. You start working in “trunk”, on what will eventually be released as version 1.0.

  • trunk/ – development version, soon to be 1.0
  • branches/ – empty

Once 1.0.0 is finished, you branch trunk into a new “1.0” branch, and create a “1.0.0” tag. Now work on what will eventually be 1.1 continues in trunk.

  • trunk/ – development version, soon to be 1.1
  • branches/1.0 – 1.0.0 release version
  • tags/1.0.0 – 1.0.0 release version

You come across some bugs in the code, and fix them in trunk, and then merge the fixes over to the 1.0 branch. You can also do the opposite, and fix the bugs in the 1.0 branch and then merge them back to trunk, but commonly projects stick with merging one-way only to lessen the chance of missing something. Sometimes a bug can only be fixed in 1.0 because it is obsolete in 1.1. It doesn’t really matter: you only want to make sure that you don’t release 1.1 with the same bugs that have been fixed in 1.0.

  • trunk/ – development version, soon to be 1.1
  • branches/1.0 – upcoming 1.0.1 release
  • tags/1.0.0 – 1.0.0 release version

Once you find enough bugs (or maybe one critical bug), you decide to do a 1.0.1 release. So you make a tag “1.0.1” from the 1.0 branch, and release the code. At this point, trunk will contain what will be 1.1, and the “1.0” branch contains 1.0.1 code. The next time you release an update to 1.0, it would be 1.0.2.

  • trunk/ – development version, soon to be 1.1
  • branches/1.0 – upcoming 1.0.2 release
  • tags/1.0.0 – 1.0.0 release version
  • tags/1.0.1 – 1.0.1 release version

Eventually you are almost ready to release 1.1, but you want to do a beta first. In this case, you likely do a “1.1” branch, and a “1.1beta1” tag. Now, work on what will be 1.2 (or 2.0 maybe) continues in trunk, but work on 1.1 continues in the “1.1” branch.

  • trunk/ – development version, soon to be 1.2
  • branches/1.0 – upcoming 1.0.2 release
  • branches/1.1 – upcoming 1.1.0 release
  • tags/1.0.0 – 1.0.0 release version
  • tags/1.0.1 – 1.0.1 release version
  • tags/1.1beta1 – 1.1 beta 1 release version

Once you release 1.1 final, you do a “1.1” tag from the “1.1” branch.

You can also continue to maintain 1.0 if you’d like, porting bug fixes between all three branches (1.0, 1.1, and trunk). The important takeaway is that for every main version of the software you are maintaining, you have a branch that contains the latest version of code for that version.

Another use of branches is for features. This is where you branch trunk (or one of your release branches) and work on a new feature in isolation. Once the feature is completed, you merge it back in and remove the branch.

  • trunk/ – development version, soon to be 1.2
  • branches/1.1 – upcoming 1.1.0 release
  • branches/ui-rewrite – experimental feature branch

The idea of this is when you’re working on something disruptive (that would hold up or interfere with other people from doing their work), something experimental (that may not even make it in), or possibly just something that takes a long time (and you’re afraid if it holding up a 1.2 release when you’re ready to branch 1.2 from trunk), you can do it in isolation in branch. Generally you keep it up to date with trunk by merging changes into it all the time, which makes it easier to re-integrate (merge back to trunk) when you’re finished.

Answer #4:

They don’t really have any formal meaning. A folder is a folder to SVN. They are a generally accepted way to organize your project.

  • The trunk is where you keep your main line of developmemt. The branch folder is where you might create, well, branches, which are hard to explain in a short post.
  • A branch is a copy of a subset of your project that you work on separately from the trunk. Maybe it’s for experiments that might not go anywhere, or maybe it’s for the next release, which you will later merge back into the trunk when it becomes stable.
  • And the tags folder is for creating tagged copies of your repository, usually at release checkpoints.

But like I said, to SVN, a folder is a folder. branchtrunk and tag are just a convention.

I’m using the word ‘copy’ liberally. SVN doesn’t actually make full copies of things in the repository.

“branch”, “tag” and “trunk” in SVN:

The trunk is the development line that holds the latest source code and features. It should have the latest bug fixes in it as well as the latest features added to the project.

The branches are usually used to do something away from the trunk (or other development line) that would otherwise break the build. New features are often built in a branch and then merged back into the trunk. Branches often contain code that are not necessarily approved for the development line it branched from. For example, a programmer could try an optimization on something in a branch and only merge back in the development line once the optimization is satisfactory.

The tags are snapshots of the repository at a particular time. No development should occur on these. They are most often used to take a copy of what was released to a client so that you can easily have access to what a client is using.

Answer #6:

Now that’s the thing about software development, there’s no consistent knowledge about anything, everybody seems to have it their own way, but that’s because it is a relatively young discipline anyway.

Here’s my plain simple way,

trunk – The trunk directory contains the most current, approved, and merged body of work. Contrary to what many have confessed, my trunk is only for clean, neat, approved work, and not a development area, but rather a release area.

At some given point in time when the trunk seems all ready to release, then it is tagged and released.

branches – The branches directory contains experiments and ongoing work. Work under a branch stays there until is approved to be merged into the trunk. For me, this is the area where all the work is done.

For example: I can have an iteration-5 branch for a fifth round of development on the product, maybe a prototype-9 branch for a ninth round of experimenting, and so on.

tags – The tags directory contains snapshots of approved branches and trunk releases. Whenever a branch is approved to merge into the trunk, or a release is made of the trunk, a snapshot of the approved branch or trunk release is made under tags.

I suppose with tags I can jump back and forth through time to points interest quite easily.

Answer #7:

Tag = a defined slice in time, usually used for releases

I think this is what one typically means by “tag”. But in Subversion:

They don’t really have any formal meaning. A folder is a folder to SVN.

which I find rather confusing: a revision control system that knows nothing about branches or tags. From an implementation point of view, I think the Subversion way of creating “copies” is very clever, but me having to know about it is what I’d call a leaky abstraction.

Or perhaps I’ve just been using CVS far too long.

Hope you learned something from this post.

Follow Programming Articles for more!

About ᴾᴿᴼᵍʳᵃᵐᵐᵉʳ

Linux and Python enthusiast, in love with open source since 2014, Writer at programming-articles.com, India.

View all posts by ᴾᴿᴼᵍʳᵃᵐᵐᵉʳ →