As software developers, it is crucial to maintain our code changes in a version control system (VCS). Version control helps protect our code, allows us to undo problematic changes, and ensures that all team members’ changes are captured in a central place. In this blog post, we will explore the version control features built into Azure Data Studio (ADS) and how they can benefit SQL Server developers.
A Dedicated Pane for Version Control
ADS is built on Visual Studio Code, which includes built-in support for Git. Unlike SQL Server Management Studio (SSMS), ADS retains this functionality. In the ADS sidebar, you will find a VCS icon that resembles a git branch graph. This icon provides access to all the changes you have made to your code and allows you to commit them to your Git repository.
Opening a Repository
To work with a repository in ADS, you can use the “File | Open Folder” link or the button on the main screen. Once you have selected a folder containing a Git repository with your scripts, ADS will reload the folder, and the server connections blade will open. You will see the main screen along with any uncommitted changes in your Git repository. By clicking the source control icon in the right menu, you can view and manage these changes.
The Version Control Flow
The version control flow in ADS is designed to make it easy for SQL Server developers to edit, test, and save code versions. The flow involves opening a Git repository, editing code, connecting to a SQL Server to execute or test the code, saving the file on the local file system, committing the local file to Git, and finally pushing the code to a remote repository. ADS provides an integrated Git client that simplifies this process.
The Git Client in ADS
ADS includes a comprehensive set of Git commands, such as staging, unstaging, committing, pushing, pulling, branching, and fetching code. The Source Control blade in ADS allows you to view the changes you have made to files. Additionally, you can find other important information in areas like branches and the status bar.
Branches
Branching is essential for distributed work, and ADS makes it easy to create and switch between branches. The branch name is displayed in the lower left corner of ADS, and you can access a list of branches by clicking the branch name. ADS also provides the ability to create new branches from the current branch state or from another branch.
Pushing and Pulling Code
One of the main advantages of using a VCS like Git is the ability to easily share code with others. ADS simplifies the process of pushing and pulling code from a remote repository. The status bar in ADS displays arrows indicating the number of commits that are different between the local and remote branches. By clicking the sync button, you can push and pull changes. Alternatively, you can use the command palette to perform these actions.
Staging Changes
When working on multiple scripts, you may want to save changes separately and commit them individually. Git allows you to stage specific changes and commit them separately. In ADS, you can stage changes by clicking the “+” icon next to the file in the Source Control blade. This moves the change to a separate area, and you can then commit only the staged changes.
Other Commands
ADS provides a menu of other Git commands in the Source Control blade, allowing you to perform actions like pushing, pulling, branching, and more. You can also access Git commands through the command palette or view the Git output in the terminal. These options give you flexibility and control over your version control workflow.
Summary
Using version control is essential for modern software developers, including SQL Server developers. ADS with Git integration provides a seamless experience for saving code changes, pushing and pulling those changes to and from a central repository, and collaborating with team members. By practicing these actions in your own repository and exploring additional Git commands, you can become proficient in using version control with SQL Server.