SQL Clone 4

Git hooks

Branch switching

SQL Clone can be used to create full copies of your database for each piece of work during development, and switch between them automatically when you change branch in git. This allows you to make changes to your database on one branch, and store those changes when you need to work on another branch. When you return to the original branch all your database changes including data will be preserved.

The same database connection string will be available regardless of which branch you're on. This means you don't need to reconfigure your application code depending on which branch you're on.


This functionality requires SQL Clone 4.1.2 Powershell or greater installed on your local machine.

To enable clone based branch switching in your repo you will need to create a git post-checkout hook. This will be invoked when you change branch and ensure that the correct SQL Clone database is in use.

To create the post-checkout hook add the following script to the `.git\hooks` folder in your repository.

View "post-checkout" on GitHub

Download the clone-branch.ps1 script and place it in the `.git\hooks` folder.

The following variables must be configured in the script.

  • SQL Clone server URL - $CloneServerUrl  - The location of the SQL Clone server. This is the same URL you would use to visit the SQL Clone dashboard.
  • Image Name - $ImageName - The name of the image you wish to create a clone from.
  • SQL Server Machine - $SqlServerMachineName - The machine hosting the SQL Server Instance that the clone will be created on. A SQL Clone agent must be installed on this machine.
  • SQL Server Instance - $SqlServerInstanceName - The SQL Server instance the clone will be created on. A SQL Clone agent must be installed on the same machine.
  • Clone Name - $DBName - The name that the provisioned database should be given.

View "clone-branch.ps1" on GitHub

Didn't find what you were looking for?