Automate GIT PULL
Have you encountered situation where you have bunch of projects git repos and every morning you have to manually do git pull for all the project repos, so that you have latest code in local development machine .
Well I used to go to each and every repo folders and open git bash and manually pull latest changes . Think of you have ten different projects/solutions/Microservice you work on day to day basis and you have to repeat this process every time , its tedious right , so as a developer what can we do AUTOMATE boring tedious tasks.
Well you can say this level of automation wont save lot of time for me , may be 10 mins a day . Well you are kind of correct but think of 10*5*4 = 200 , you will save 200 mins a month . Not bad huh so lets get to actual script on how can we do that.
Prerequisite:
- Install GIT on your machine
- Admin privileges(though its not required but sometime PS acts crazy if you don’t have admin permission)
- Group all project repo under single directory in your local box (for example I have all my project repos located under C:\Code, you can modify below script if you project scattered all across your drive )
param([string]$repoLocalpath)
$repoLocalpath = Read-Host -Prompt 'Input your GIT Repo'
if($repoLocalpath -eq "")
{
Write-Host "You gotta provide path" -Path -Level Error -ForegroundColor Red
#return
}
else {
Write-Host "You entered '$repoLocalpath' " -ForegroundColor DarkGreen
}
#You can directly hardcode your repo root path in case you want to avoid inputing path everytime
#$repoLocalpath = "C:\Code";
Write-Host "Starting with root: $repoLocalpath"
$dir = Get-ChildItem $repoLocalpath | Where-Object {$_.PSISContainer} | select-object FullName
foreach ($d in $dir)
{
Write-Host "git pull --all -> $($d.FullName)" -ForegroundColor Green
Set-Location $d.FullName;
git pull -v --all
# Write-Host
#build web and portal
#find if there are any difference for project then build it
}
Set-Location $PSScriptRoot;
Write-Host "Done"
You can skip user input by hard coding 'repoLocalpath'
Using above script you can customize based on your needs such as find difference before pulling remote changes or push/sync all repo.