Create a New Git Repository and Set up SQL Source Control for Bitbucket

The article provides instructions about how to create and clone the remote repository using a Git command, and then to version-control SQL Server databases with Bitbucket using the dbForge Source Control add-in.

Bitbucket is a Git-based version control software that helps developers develop, test, deploy, and mutually work on their code and projects in multiple repositories. After linking a database to the Bitbucket repository, users can perform the following operations:

  • Commit and revert changes
  • Get the latest changes from a remote repository
  • View and resolve conflicts
  • View changes history
  • Link and unlink static data

Step 1: Create a repository in Bitbucket

Prior to linking a SQL database to a Bitbucket remote repository, you should install Git on the local machine for a Windows client, and clone the remote repository.

To add a new Bitbucket repository, sign in to the Bitbucket account and on the global sidebar, click Create > Repository, and fill in repository's details: a project name (on Bitbucket repositories are grouped in projects), a repository name, indicate the access level (either private or public), include a README and a .gitignore file, and add a default name of the branch. After adding information, click Create repository.

dbForge Source Control - Create a new repository on the Bitbucket version control tool

Step 2: Clone a Bitbucket repository

On Bitbucket, users can clone repositories using HTTPS (default option) and SSH. In our case, we will use the HTTPS protocol.

Note: Cloning over SSH requires your public key to be on Bitbucket and be saved to the local computer to which you are cloning the repository.

On your computer, create an empty folder for the cloned repository: for example, a bitbucket folder stored at the D disk. Then, in your Bitbucket account, on the Repositories dashboard, select the repository you want to connect to your computer, click Clone in the upper-right corner of the page, and copy the clone command. To move on, launch the command prompt, indicate the directory to the folder, and paste the clone command. After that, a subfolder named as the cloned repository appears in the bitbucket folder.

dbForge Source Control - Clone a repository to the local machine

Step 3: Link a SQL Server database to source control

After we cloned the remote repository to the computer, we can get started with linking the database to source control using the dbForge Source Control add-in for SSMS.

To link the database to source control, in Object Explorer, right-click the database you want to connect and select Source Control > Link Database to Source Control.

Note: dbForge Source Control supports Git for a Windows client so you can work with Bitbucket authentication type, as it is triggered by Git.

dbForge Source Control - Link a database to Source Control

Step 4. Select a Bitbucket source control repository

In the Link Database to Source Control wizard that opens, specify a server connection and select the database you want to connect to source control. In the Source Control repository field, click + to select the repository folder.

In the Source Control Repository Properties window, select Git as a source control system and enter a directory to the folder on your computer, which is a local copy of your Bitbucket remote repository, and then click OK. On the Link tab, select the database development model and click Link. For more information about database models, see Shared vs Dedicated Development Models: Key Differences.

dbForge Source Control - Select a Bitbucket source source control repository

Step 5: Make an initial commit

After the database is linked to a source control system, the database Source Control Manager document opens. The Local changes section displays all the changes you make locally. Since the remote repository does not have any files yet, commit them by selecting all files in the Local changes section. Then, enter a commit comment and click Commit.

During a commit in progress, dbForge Source Control will ask you to sign in to your Bitbucket account. Once logged in, click Ok in the Commit progress dialog box.

To reverse commit changes, select them and click Undo.

dbForge Source Control - Make an Initial Commit to Bitbucket

Get remote changes

With the dbForge Source Control add-in, you can easily update your local copy of the repository by merging database changes made by other developers from the remote repository. All these changes are displayed in the Remote changes section of the Source Control Manager.

The left-bottom pane of the Source Control Manager displays the highlighted syntax of the changes made by other developers, while the right-bottom pane shows your local copy.

To get the changes from the remote repository, in the Remote changes section, select the changes and click Get Latest.

Source Control - Get remote changes from Bitbucket

Resolve conflicts

When applying changes to the same database object, developers may face conflicts. In dbForge Source Control, they appear in the Conflicts section of the Source Control Manager document. The bottom panes of the document display the highlighted syntax of the DDL local (left pane) and remote (right pane) differences.

To resolve a conflict, select the conflict you want to resolve, and click Get Local to accept your changes and, thus, overwrite remote ones, or click Get Remote to merge remote changes and, thus, overwrite your local changes with the remote ones.

Source Control - Resolve conflicts


The article provides a step-by-step tutorial that learns how to create a new repository in Bitbucket and how to link a SQL Server database to the remote Bitbucket repository with the help of dbForge Source Control. It is the advanced tool aimed at version-controlling database schemas, database objects, and data. The tool allows developers to synchronize their work, avoid data loss, track and manage changes, resolve conflicts, and link to all popular source control systems.

Get Source Control as part of dbForge SQL Tools

SQL Tools is an extensive pack of advanced tools and SSMS add-ins