-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathmigrate-mirror.ps1
71 lines (47 loc) · 1.7 KB
/
migrate-mirror.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
Param(
[Parameter( Mandatory = $true)]
$AzDOPAT,
[Parameter( Mandatory = $true)]
$AzDOOrg,
[Parameter( Mandatory = $true)]
$AzDOPrj,
[Parameter( Mandatory = $true)]
$AzDORepo,
[Parameter( Mandatory = $true)]
$GHPAT,
[Parameter( Mandatory = $true)]
$GHUser,
[Parameter( Mandatory = $true)]
$GHRepo
)
Write-Verbose "STARTING MIRROR MIGRATION FROM $AzDOOrg/$AzDOPrj/$AzDORepo to $GHUser/$GHRepo"
# STEP 1: Make sure you have a local copy of all "old repo", branches and tags
Write-Verbose 'Cloning Source Repo...'
if ( -not (Test-Path -LiteralPath '/migration' -PathType Container) )
{
# This means we didn't mount an external volume
Set-Location /
mkdir migration
}
Set-Location migration
$migrationFolder = "$AzDORepo-Migration"
mkdir $migrationFolder
Set-Location $migrationFolder
$cloneUrl = "https://$AzDOPAT@dev.azure.com/$AzDOOrg/$AzDOPrj/_git/$AzDORepo"
git clone --mirror $cloneUrl .
# STEP 2: Add a "new repo" as a new remote origin:
Write-Verbose 'Adding Target Repo as Origin'
$GHoriginUrl = "https://github.com/$GHUser/$GHRepo.git"
git remote add GHorigin $GHoriginUrl
# STEP 3: Push everything to the new repo.
Write-Verbose 'Pushing all code, branches, tags, and history to Target Repo...'
$GHpushUrl = "https://$GHPAT@github.com/$GHUser/$GHRepo.git"
git push --mirror $GHpushUrl
# STEP 4. Clean up. Remove "old repo" origin and its dependencies, and rename new origin
Write-Verbose 'Cleaning up...'
git remote -v
git remote rm origin
git remote rename GHorigin origin
Write-Verbose 'MIGRATION COMPLETED'
### Done! Now your local git repo is connected to "new repo" remote
### which has all the branches, tags and commits history.