Link a SQL Server database to a Git repository in GitHub

GitHub is a web-based platform for software developers that enables the storage and management of code and the tracking and control of code changes via Git repositories. It makes it easy for developers to collaborate on projects and to create and manage issues, bugs, and feature requests. They can also automate testing, build processes and workflows during deployment by integrating various CI/CD tools.

Prerequisites

  • Install Git for a Windows client on the machine you’ll be version-controlling a database.
  • Have a GitHub account.

The article covers the following topics:

Step 1: Create a new repository on GitHub

1. Sign in to your GitHub account.

2. In the upper-right corner of the page, click the + dropdown menu and select New repository.

Create a new repository on GitHub

3. On the Create a new repository page that opens, enter the name and optional description.

4. Select the visibility mode:

  • Public to make the repository to be visible to everyone on the Internet.
  • Private to restrict access to specific users.

5. Make an initial commit to the repository by selecting the options:

  • Add a README file: Create a README file containing the project description.
  • Add .gitignore: Select files to be ignored. The .gitignore file will have a set of ignore rules.
  • Choose a license: Grant permissions so users can use, change, and distribute the product.

The default name of the branch is main. If you want to change the name, go to the settings tab.

Note

If you import an existing repository, skip this step.

6. To keep the changes, click Create repository.

Step 2: Clone the repository using the command line

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

2. In the GitHub account, switch to the Repositories page and select the repository you want to copy to your computer.

3. From the <> Code dropdown menu, select HTTPS and copy the repository URL.

Copy the URL of the repository on GitHub

4. Start Windows Command Prompt (CMD) and navigate to the empty folder you created.

5. In the Command Prompt, type the git clone command, paste the URL directory you’ve copied, and press Enter to create a cloned copy of the repository.

Note

Specify 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, execute the following commands:

  • git commit --allow-empty -m initial

  • git push

Copy the URL of the repository on GitHub

1. In Database Explorer, right-click a 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.

2. On the Link page of the Link Database to Source Control wizard, click + in the Source control repository field.

Note

The previously linked repository will be selected by default.

3. In the Source Control Repository Properties dialog that opens, select Git from the Source Control system dropdown list and specify a path to the folder with the cloned copy of the repository in the Repository Folder field. You can specify a path to a subfolder in the repository (not .git).

Note

To work with a remote repository, you need a clone of this repository. To retrieve a local clone, execute the git clone <url> <path> 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

4. Optional: Click Test to verify that the database can be successfully connected to source control.

Note

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

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

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

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

Link DB Wizard

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

Step 4: After linking to the GitHub 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?