Skip to content

Commit 768bf99

Browse files
committed
Add fetch strategy if bare repository already exists locally
1 parent 988a936 commit 768bf99

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

backup_github_repositories.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,21 @@ function Write-Message([string] $message, [string] $color = 'Yellow') {
8383
}
8484

8585
#
86-
# Clone a remote GitHub repository into a local directory.
86+
# Clone or fetch a remote GitHub repository into a local directory.
8787
#
8888
# @see https://git-scm.com/docs/git-clone#git-clone---mirror
8989
#
9090
function Backup-GitHubRepository([string] $fullName, [string] $directory) {
9191

9292
Write-Message "Starting backup of https://github.com/${fullName} to ${directory}..." 'DarkYellow'
9393

94+
if (Test-Path "${directory}") {
95+
96+
git --git-dir="${directory}" fetch --all
97+
git --git-dir="${directory}" fetch --tags
98+
return
99+
}
100+
94101
git clone --mirror "[email protected]:${fullName}.git" "${directory}"
95102
}
96103

0 commit comments

Comments
 (0)