Link a database to a Git repository in BitBucket

BitBucket is a web-based version control solution designed for software development teams. It supports Git repositories to help users manage and collaborate on their projects. Also, developers can track and revert changes, and work on different branches simultaneously. BitBucket offers a range of services, including code review, issue tracking, continuous integration and deployment, and integrations with other software development tools like Jira and Confluence.

Prerequisites

Make sure that you have:

  • Git for a Windows client installed on the machine.
  • Git repository created locally or cloned from the remote repository. If not, Step 2 provides a step-by-step procedure to clone a repository using the command line.
  • BitBucket account.

The guide covers the following topics:

Step 1: Create a repository on Bitbucket

1. Sign in to your Bitbucket account.

2. At the top of the page, click Create > Repository. Alternatively, you can click Create repository either in the Recent repositories or Welcome sections.

Create a new repository on BitBucket

3. On the Create a new repository page that opens, add the repository details:

  • In the Project dropdown list, choose an existing project or specify a name for a new project. It is required because workshop repositories are grouped into projects.
  • In the Repository name field, enter a repository name.
  • Select an access level. By default, Private repository is selected, which restricts access to specific users. If you want to make the repository visible for everyone on the Internet, clear the checkbox.
  • In the Include a README? dropdown list, choose the option either Yes, with a tutorial (for beginners) or Yes, with template to create a readme file or No to exclude a readme file.
  • In the Default branch name field, specify a default branch name.
  • In the Include .gitignore dropdown list, select Yes, recommended to include a .gitignore file or No to exclude the file.

4. Click Create repository to create the new repository on Bitbucket.

Create a new repository on BitBucket

Step 2: Clone a repository using the command line

1. Create an empty folder on the disk of your computer to store the local repository. For example, a bitbucket folder stored on the drive D.

2. Sign in to your BitBucket account, navigate to Repositories on top of the page, and then select the repository you want to clone to your computer.

3. In the upper-right corner of the repository page, click Clone.

Clone a repository on BitBucket

4. In the Clone this repository window that opens, select either HTTPS or SSH as the connection protocol, and copy the clone command with the repository URL. HTTPS, which is a default option, supports user/password authentication, and SSH - public key authentication. In our example, we use HTTPS.

Note

When cloning over SSH from a Bitbucket repository, the user’s public key needs to be added to the Bitbucket account and saved on the local computer they are using to clone the repository. This allows for secure authentication between the local computer and the Bitbucket server.

5. Start Windows Command Prompt (CMD). If you need to change the disk drive and navigate to the empty folder you created, in the Command Prompt, use the cd command.

6. In the Command Prompt, paste the clone command with the repository URL to create a cloned copy of the repository in the local folder (bitbucket in our case). Since the HTTPS protocol has been selected, you will be prompted to enter the username and password to your BitBucket account.

Note

Place a dot at the end of the command to clone the repository to the folder you have created. Otherwise, another subfolder will be created.

If you didn’t add any files to the repository when you created it for the first time, execue the following commands:

  • git commit --allow-empty -m initial

  • git push

Clone a repository on BitBucket

After you cloned the remote repository to the folder on your local computer, you can link the database to source control using the dbForge Source Control add-in for SSMS.

1. In SSMS Object Explorer, right-click the database you want to link to source control and select Source Control > Link Database to Source Control.

2. In the Link Database to Source Control dialog that opens, click + in the Source control repository field.

3. In the Source Control Repository Properties dialog that opens, do the following:

  • From the Source Control system dropdown list, select Git as a source control system.
  • In the Repository folder field, click More options icon More to add the repository folder. In the Select Folder window that opens, select the folder, which is a local copy of your Bitbucket remote repository, and then click Select Folder.
  • Optional: In the Repository name field, you can change the name of the repository folder.

Select the repository folder

5. Optional: Click Test to verify that the database has successfully been connected to source control.

6. Click OK to apply the changes and close the Source Control Repository Properties dialog.

7. In the Link Database to Source Control dialog, select a database development model: dedicated or shared.

7. Click Link to establish the connection between the database and source control.

Link a database to source control

The Refresh progress window opens automatically, showing the stages of the refresh operation. The linked database gets the following icon in Object Explorer.

Linked DB

Step 4: After linking a database to the BitBucket repository

If you are the first person who links this database, you must make an initial commit. For this, in Source Control Manager, go to the Local changes section, select the database objects to commit, and then click Commit.

If you linked a database that is already in source control, you can update your database to the latest version. For this, in Source Control Manager, go to the Remote changes section, select the objects, and click Get Latest, which is available only in the dedicated model but not in the shared model.

Want to Find out More?

Overview

Overview

Take a quick tour to learn all about the key benefits delivered by dbForge Source Control for SQL Server.
All Features

All features

Get acquainted with the rich features and capabilities of the Source Control in less than 5 minutes.
Request a demo

Request a demo

If you consider employing the Source Control for your business, request a demo to see it in action.
Ready to start using dbForge Source Control for SQL Server?