Public/Sync/Sync-GitRepository.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<#
.SYNOPSIS
    Syncs all defined repositories.
.DESCRIPTION
    Performs fetch or pull operation on all defined GIT repositories.
.EXAMPLE
    Sync-GitRepository -Pull
 
    Pulls changes of the remote tracking branch to the actual checked out
    branch.
.EXAMPLE
    Sync-GitRepository
 
    Fetches all remote branches to the local GIT repositories.
#>

function Sync-GitRepository {
    [CmdletBinding(PositionalBinding=$false,
                   HelpUri = 'http://www.microsoft.com/',
                   ConfirmImpact='Medium')]
    [Alias("sgr")]
    [OutputType([String])]
    Param (
        # Pulls changes of into actual GIT branch
        [Parameter()]
        [Switch]
        $Pull
    )
    
    end {
        ForEach-GitRepository -Callback {
            Write-Host "Sync $($_.Name)" -ForegroundColor Magenta
            if ($Pull){
                git pull --tags
            }
            else{
                git fetch --all --prune --tags
            }
        }
    }
}