In the following scenario, I will use an existing Git repository stored in Azure DevOps to demonstrate the process of cloning the repository to a local folder, committing some changes, and updating the changes back to the Azure DevOps repository.
You need to install Git before working with Git repositories in either of our SAPIEN editors. Use the following link to download and install Git for Windows.
Configuring Git in PowerShell Studio or PrimalScript
After installing Git, you will need to set up Git source control in PowerShell Studio or PrimalScript.
In PowerShell Studio, on the Home ribbon in the Windows section, select Options (or File > Options). Then select the Source Control tab at the bottom:
In PrimalScript, select File > Options. Under the Source Control section, select General:
In the Options > Source Control section of either SAPIEN editor:
- Under Universal Version Control System select Git.
- Click OK to save the Options changes.
- Restart the editor.
In PowerShell Studio, the Git menu is in the Source Control ribbon tab:
In PrimalScript, the Git menu is in the Tools ribbon tab:
All options in the menu are preset Git commands.
There are two additional options if you want to do more with Git:
- Shell – Git command line
- GUI – Git GUI application
Prior to cloning an existing repository
First, a placeholder for the cloned repository needs to exist on the local machine. For this example, I created an empty folder named GitRepoPowerShellScripts01.
Now I can proceed to clone my Git repository from my Azure DevOps site. Keep in mind that I have previously set my permissions to access this repository.
Working with the Repository Source Code
Working with Git is as simple as following the SDLC (Software Development Life-Cycle):
- Clone a repository to a local folder.
- Diff to list the code changes.
- Commit the changes in the local repository.
- Push the changes back to the remote repository.
Note: The Git menu options are enabled when a script is open in the editor.
This option is used to copy the remote repository to the local drive, and it will prompt for the following information:
- Name of a new directory to clone into.
- The Git remote repository address.
When the cloning process completes, the source code will be available for editing.
Now I can open a script and start making changes to the code.
This option gives a list of the changes made to the code. In either SAPIEN editor, the results will be displayed in the Tool Output panel:
After making changes to the code, I will use the Commit button to mark the changes in the local repository.
The Commit option will prompt for the following information:
1. Enter a commit message.
The Push option will send the changes back to the remote repository. There is no prompt for this option.
The results display in the Tool Output panel:
You can go back to the remote repository to confirm that the source code was updated.
Both of our SAPIEN editors—PowerShell Studio and PrimalScript—provide the essential options for working with Git repositories. Additionally, we have included the Git command line for more complex commands, and also the Git GUI application for fast interaction with the source code.
- Git Documentation
- Git Manual
- PrimalScript 2018 adds Git Version Control Support
- PowerShell Studio 2018: Service Release v5.5.153 and Git Support
- GitHub: Tell Git to ignore files
- Customizing Git Commands
As always, if you have any ideas, comments, or feedback, please visit our feedback forum and reference this post.
Max Trinidad is a Technology Evangelist at SAPIEN Technologies Inc., and a Microsoft PowerShell MVP. You can reach him at email@example.com