How to link a database to a Git repository

With the help of dbForge Studio for SQL Server, you can version-control database schemas and data, roll back unwanted changes, handle static data conflicts, and maintain the integrity of the database. Using the tool, you can link your database to Git, a distributed version control system.

Note

In dbForge Studio for SQL Server 6.0 and later, a new Git client is implemented - Git for Windows. Therefore, you can work with all possible connection and authentication types, as this task is delegated to the Git client. Before trying to connect your database to Git, make sure that you have a Git for Windows client installed on your machine. To link a database to a remote repository, you must have a cloned copy of the remote repository, which may be hosted on platforms such as GitHub or GitLab or created locally using the git init --bare Git command.

See the following how-to topics to learn how to link a database to a Git repository:

When dbForge Studio connects to a Git repository, is the connection secure? In other words, is TLS enabled?

dbForge Studio connects to Git using the standard Git client for Windows, which supports current security protocols, including TLS 1.2. Secure connections are established when the server both supports them and requires them. For instance, if a repository’s address begins with HTTPS and the server stipulates TLS, the connection will comply with these security requirements. The choice of security protocol is determined by the server’s configuration, not by dbForge settings.

Work with a local Git repository

dbForge Source Control does not support direct connections to remote repositories. You must first clone the remote repository to your PC and then link it to Source Control.

To work with a local Git repository, perform the following steps:

1. Create an empty folder on the disk of your computer where the local repository will be stored.

2. Start Windows Command Prompt (CMD).

Note

In the Command Prompt, use the cd command to change the disk drive and navigate to the empty folder you created.

3. Type git init --bare to create the main repository locally.

4. Navigate to the folder you’ve created in Step 1 to clone the local repository using git clone <pathToMainRepo>. Make sure to 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.

Note

<pathToMainRepo> is the path to the main repository you created locally when executing the git init --bare command.

5. Execute these CMD commands in the folder in question:

  • git commit --allow-empty -m initial to make an initial commit
  • git push to push the changes to the remote repository

Work with a local Git repository

6. Link source control to that folder in the following order:

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

Alternatively, select Database > Link Database to Source Control on the ribbon.

  • In the Source Control Repository Properties dialog, do the following:

    • From the Source control system dropdown list, select Git.
    • In the Repository folder field, click More options icon More to select the repository folder.
    • Optional: The Repository name is automatically derived from the name of the repository folder. However, you can specify a different name of the repository.

Select the repository folder

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

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

7. Select a database development model: shared or dedicated.

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

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

Linked DB

Additionally, to get more information on how to create a local Git repository and link your database to it with the help of Source Control, watch this video.

Download dbForge Studio for SQL Server and try it absolutely free for 30 days!

After linking a database to the GitLab repository

If you are the first person to link this database, add the database objects to source control in an ‘initial commit’: go to the Local changes section, select the objects, and click Commit. For more information, see Commit changes.

If you linked a database that is already in source control, update your database to the latest version: go to the Remote changes section, select the objects, and click Get Latest, which is available only in the dedicated model. For more details, see Get the latest version.

Want to Find out More?

Overview

Overview

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

All features

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

Request a demo

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