Branching and merging
Published 23 March 2022
Many development projects involve creating branches (or "forks") for a feature, release, or other development milestone. A branch is essentially a copy of the code base that shares its history. Reincorporating the changes from a branch is known as merging.
Development projects typically have:
- a trunk, the main code base, and branches which diverge from it
- one or more branches, copies that diverge from the trunk
For more information about the concepts behind branching and merging, see:
- Branching and merging with Team Foundation Server
- Branching and merging with Subversion
- Branching and merging with Git
For a general introduction to source control concepts, we recommend Version Control by Example (free PDF) by SourceGear founder Eric Sink.
Working with branches in Source Control for Oracle
You can work with branches in Source Control for Oracle, but you can't create or merge branches. To branch with Source Control for Oracle, you need to create the branch using your source control system.
Subversion and TFS
Link to the appropriate branch in a Source Control for Oracle project. Then choose one of the two approaches below:
Unlink and relink the branch from the source control project
In this approach, you continue working on the same schema, but link it to the branch in your source control system.
Once the branch is created, remove the source control project from Source Control for Oracle, then link the schema again in a new Source Control for Oracle project. In step 2 of the new source control project wizard, specify the location of the branch in source control.
Create a new database for the branch
In this approach, you create the branch in your source control system, then create a new schema to link with it.
Create a new empty schema, and link it to source control in a Source Control for Oracle project. When you link, specify the location of the branch in source control, then on the Get latest tab, update the schema with the latest version from source control.
Git
Switch between branches using the drop-down menu in the top right of the Source Control for Oracle window:
Merging
Source Control for Oracle doesn't provide automatic or line-by-line merging. You can use Source Control for Oracle or Schema Compare for Oracle to merge at an object level, but not choose line-by-line changes.
When you merge with Source Control for Oracle or Schema Compare for Oracle, you choose a version of each object to keep. For example, you might keep the trunk version of a table and the branch version of a view.
There are three approaches to merging:
Merging using your source control system
You can manually merge the branch changes back into the trunk using your source control system as you would for application code.
We recommend this approach if the merge is complex, or if there are conflicts; for example, if the same object has been modified in both the branch and the trunk.
When merging manually, make sure referential integrity is maintained or the database may be left in an invalid state.
Your source control system may include auto-merging functionality that simplifies manual line-by-line merges.
Merging using Source Control for Oracle
This method of merging is not yet possible with Git.
If you don't need to do a line-by-line merge, you can merge with Source Control for Oracle.
To do this:
- In Source Control for Oracle, make sure you have a schema linked to the branch in your source control repository.
- Get the latest version and check in any outstanding changes.
- Remove the source control project on the right-click menu.
- Create a new source control project linking the schema to the trunk.
- Go to the Check in tab.
The tab shows the changes to the branch as changes to check in.
If there are conflicts, choose Use database version to override the trunk with the objects from the branch. - Check in the changes.
The trunk is updated with the branch changes.
Merging using Schema Compare for Oracle
If there are no conflicting changes between the branch and the trunk, you can merge automatically using Schema Compare for Oracle.
To merge branch changes into the trunk with Schema Compare for Oracle:
- In Source Control for Oracle, make sure you have a database linked to the trunk.
- Use your source control system to create a local copy of the latest branch version (for example, by running an SVN checkout).
In Schema Compare for Oracle, create a new project. Set the local copy of the branch as the source, and the trunk database as the target.
For more information, see Setting data sources.- Compare the data sources.
Schema Compare shows the differences between the branch and the trunk.
- In the Results pane, select the objects from the branch that you want to merge into the trunk, and run the deployment wizard to Using the Deployment Wizard
The trunk is updated with the changes from the branch. - In Source Control for Oracle, on the Check in tab, check in the trunk changes to source control.