Wednesday, July 28, 2021

Difference between trunk, tags and branches in SVN? Answer

SVN or Subversion is one of the popular source control systems used in the Java world for source code management. There are a lot of source control systems available e.g. Git, Perforce, CVS, ClearCase, VSS, but SVN has its own place among Java developer and open source communities. Knowledge of source control systems is a must for any professional programmer. New users of subversion are often confused between three things trunk, tags, and branches. Questions like, what is the difference between a tag and a branch in subversion is frequently asked in various Java forums and chat rooms.

In this article, we will see what is trunk, tags or branches in SVN and understand the difference between trunk, tag, and branch. In short, when you first upload your project to SVN it creates a trunk, It's analogous to the trunk of a tree. this trunk forms the main development line. 

When multiple developer works on the different functionality of project they usually create a branch from trunk and after successfully completing that functionality, they usually merge there changes to trunk. 

On the other hand tag is usually used to create read only snapshots of either trunk or branch, which has been released, for future use. You can think tag as stable snapshot of code at any point, and can be used to as backup or restore. 

Let's see the difference between branch, trunk and tag more detail in next section.




trunk vs branch vs tag in subversion or SVN

Difference between trunk, branch and tag in SVN, CVS or Subversion
Technically all three i.e. trunk, branch and tag are folders in SVN. If you are using tortoise SVN, a popular windows client for subversion, you can explore trunk, branch or tag. If you browse SVN repository using Repo browser or simply open it on any browser e.g. Internet Explorer, you will generally see three directories as trunk, branch and tags at root of project. This is actually one of SVN best practice to create this kind of directory structure. 


As I said earlier, trunk is place where main development happens, and branches are places where different developer work on different functionalities. This division is purely based on how programmer uses trunk and branches.

Similarly, tags are used to backup releases e.g. alpha release or beta release or any version of release. Main difference between branch and tag in subversion is that, tag is a read only copy of source code at any point and no further change on tag is accepted, while branch is mainly for development. 

Other source control like CVS doesn't allow modification on tags but SVN allows changes on tags, which is considered as bad practice. You should not be making any change on tag once created, it should be treated as read only copy of source code only for restore purpose.

In short
- A trunk in SVN is main development area, where major development happens.
- A branch in SVN is sub development area where parallel development on different functionalities happens. After completion of a functionality, a branch is usually merged back into trunk.
- A tag in SVN is read only copy of source code from branch or tag at any point of time. tag is mostly used to create a copy of released source code for restore and backup.

That's all on difference between trunk, branch and tags in Subversion or SVN. They are mostly categorized based upon there usage. Though trunk, branch and tag are quite common words in source control, and other SCM also uses these words, there behavior may be little different on other SCM, so don't forget to check SCM documentation.


Other Programming articles from Javarevisited Blog
Real world example of Dependency Injection and Inversion of Control design pattern

2 comments :

Wang Siang said...

Hi Guys, Can anyone please share some best practices related to svn branching and tagging? It's difficult to work in branch and then merge them back, every now and then. I am searching for best practices around that procedure, what does other people do? does they keep there Production release on branch, tag or trunk? Which one is better and why? How to make effective use of svn branch and tag etc?

Chagam Harikrishna said...

Accord to branching strategy the code release should be placed in tag only in the production.

Post a Comment