Exercise - Source control with Git
This exercise is written to use the Cronus sample company from the US version of Business Central. You might need to make adjustments to the steps if you use the sample company from your country or region.
Scenario
You're a developer working for CRONUS International Ltd. You want to create a new AL extension, add it to version control with Git, and safeguard the code in Azure Repos.
Tasks
Create a new AL Extension
Add the source code to a local Git repository
Add Azure Repos as remote Git repository
Push the local Git repository to the remote repository
Steps
Start Visual Studio Code.
Select View > Extensions (Ctrl+Shift+X).
Type AL Language in the Search Extensions in the Marketplace search box.
Click the green Install button.
Create a new AL Extension project. Select View > Command Palette... (Ctrl+Shift+P).
Type AL: Go! in the search box and select the command from the list.
Accept the suggested path (or enter another path).
Select the latest target platform.
Select Microsoft cloud sandbox as the development endpoint.
Download the application symbols by selecting View > Command Palette... (Ctrl+Shift+P).
Type AL: Download symbols in the search box and select the command from the list.
If requested, provide your organizational credentials (Microsoft 365 account/Microsoft Entra ID account).
Open the App.json file and change the name setting to Hello Business Central Change the publisher setting to Cronus International Ltd.
Install Git (if not installed) using the Installing Git page.
In Visual Studio Code, select View > SCM (Ctrl+Shift+G) to open the Source Control view.
Select the Initialize Repository button to initialize a local repository for the current AL Extension.
Your files are now displayed with a status U at the end, indicating Untracked. Right click the first .app file and select add to .gitignore. You can only do this step from within the Source Control view, not in the Explorer view
Repeat this process for every .app file and for the launch.json file.
Select all files, right click, and select Stage Changes or select the + icon next to Changes. This action adds the files to the staging area.
Add the message Initial Commit in the commit message box, and select the commit button (the check mark button) or press Ctrl+Enter
Open your favorite web browser and open your Azure DevOps organization.
Select the project Hello Business Central if you created it from the video demonstration, or create a new project if that project isn't available.
Select Repos in the left menu. You see that the repository is empty, and that you can add code to the repository.
Copy the https link that you can find in the Clone to your computer section.
Open Visual Studio Code and press F1, and type Git: Add Remote... in the search box.
Enter a remote name: origin
Paste the URL you copied from Azure Repos in the remote URL box.
Depending on your configuration, Visual Studio Code prompts you to log in into Azure DevOps with your Microsoft Account/Organizational Account. If this doesn't work, and Visual Studio Code still asks you to log in with a username and a password, you can go back into Azure DevOps, and click the button Generate Git Credentials under the input box where you copied the repo URL. This allows you to copy a username and a password that you can use for Git instead of your standard account.
If the remote repository is successfully linked in Visual Studio Code, you can click the Publish icon at the left bottom of your Visual Studio Code window. This button is a cloud icon with an arrow up. You'll find it next to the master branch button.
These steps publish your local code in Azure Repos.
Open Azure DevOps, refresh the page and your code should be visible.
Open Visual Studio Code, open the HelloWorld.al file and change Hello World in Hello Business Central in the Message function. Save your modifications (Ctrl+S).
Open your Source Control view. The HelloWorld.al file should be visible as changed. Select the file and add the file to the staging area.
Add a commit message and click the commit button.
Now, push your changes to the remote repository. You can click the three dots ... to open a menu and select push. Or you can click the synchronization icon at the bottom of the window (same location as you clicked the publish icon). This action will synchronize. Therefore, a window will be visible that mentions that this action performs a pull and a push. You can agree by clicking Yes.
Open Azure DevOps and refresh the page and select the HelloWorld.al file. Your modifications should be visible.