Repository Batch Update Utility
Developers can possibly work with quite a few repositories, especially in hsbcad offices since it is common practice to keep a copy for each active branch of each repository. I found it time consuming to update each repository using the typical Git clients, and I don’t like my repos to get too far behind.
To address this, I’ve written a PowerShell script which navigates to each repo and pulls down changes. It features a custom alias of ‘git pull’ which specifies fast forward and enables some other switches.
You can read about the recommended alias here if you’re interested.
So, to get started you need to define this alias on your machine. Note that this is all for PowerShell, if you prefer a different shell in your terminal you might have to edit this somewhat, but the concept is universal.
At any PowerShell command prompt, enter and run:
git config --global alias.up '!git remote update -p; git merge --ff-only @{u}'
The script itself is quite concise:
$repos = “<Repo Path 1>”, “<Repo Path 2>”, …
foreach ($repo in $repos)
{
Set-Location "${repo}"
git checkout master
git up
}
Save this to a file with the .ps1 extension. With PowerShell installed you should get an option to run the script when you Rt-click. Or you can open it in VS Code and use it’s built-in PowerShell terminal.
You might be prompted about Execution policy, but that is straightforward to answer.
My version of this script can be downloaded here.
Cheers,
cc