Linking a Database to Git

Source Control is a Microsoft SQL Server Management Studio (SSMS) add-in that is designed to manage database changes in most well-known version control systems. With the help of the tool, you can version-control database schemas and data, roll back unwanted changes, handle static data conflicts, and maintain the integrity of the database. Via Source Control, you can link your database to Git, which is a distributed version control system. Git is aimed at coordinating the work of multiple programmers and provides non-linear work-flow.

Note:

Source Control 2.2 and later supports Git for Windows client. Thanks to it 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 Git for Windows client installed on your machine.

Prerequisites:

  • Git for Windows client installed on the machine
  • Git repository created locally or cloned from the remote repository.

1. In Object Explorer, right-click a database you want to link to source control.

2. Click Source Control, and then select Link database to source control from the shortcut menu.

Link DB to Source Control

The Link Database To Source Control wizard opens.

3. On the Link tab of the wizard, click ‘+’ in the Source control repository field.

Link DB Wizard

The Source Control Repository Properties dialog box opens.

4. Select Git from the Source Control system drop-down list box and provide a path to your local Git repository where dbForge Source Control for SQL Server will store SQL scripts.

Note
To work with a remote repository, you need a clone of this repository. To retrieve a local clone, execute the git clone command or use the GUI tool. After the successful creation of the clone, specify the path to the folder containing the clone in the Repository Folder field of the Repository Properties window. You can specify a path to a subfolder in the repository (not .git).

Link DB to Git

Click Test to check the connection.

Note
Keep in mind that you should work with the current repository branch. For this, it needs to have at least one commit.

5. Click OK to close the Source Control Repository Properties dialog box.

6. Select a database development model. For more information, refer to the Database Development Models topic.

7. Click Link. If a database is linked to source control successfully, a database icon in Object Explorer will be changed to show that a database is linked.

Linked DB