Skip to content

Instantly share code, notes, and snippets.

@Gimly Gimly/Git-Import-SVN.ps1
Last active Jul 23, 2019

What would you like to do?
Import a SVN repository into a Git repository, complete with branches and tags. Script inspired by the method described by StackOverflow answer
[Parameter(Mandatory=$true, Position=1)]
[Parameter(Mandatory=$true, Position=2)]
[Parameter(Mandatory=$true, Position=3)]
git svn clone --stdlayout --no-metadata -A users.txt $SvnFolderPath "$TargetFolder-tmp"
cd "$TargetFolder-tmp"
$remoteBranches = git branch -r
foreach($remoteBranch in $remoteBranches)
$remoteBranch = $remoteBranch.Trim()
$tagName = $remoteBranch.Substring(5)
git checkout -b "tag-$tagName" $remoteBranch
git checkout master
git tag $tagName "tag-$tagName"
git branch -D "tag-$tagName"
elseif($remoteBranch -notlike "trunk")
git checkout -b $remoteBranch $remoteBranch
cd ..
git clone "$TargetFolder-tmp" $TargetFolder
rm -Recurse -Force "$TargetFolder-tmp"
cd $TargetFolder
$remoteBranches = git branch -r
foreach($remoteBranch in $remoteBranches)
$remoteBranch = $remoteBranch.Trim()
if($remoteBranch -notcontains "HEAD" -and $remoteBranch -notcontains "master")
$branchName = $remoteBranch.Substring(7)
git checkout -b $branchName $remoteBranch
git checkout master
git remote rm origin
git remote add origin $GitUrl
git push --all

This comment has been minimized.

Copy link

commented Sep 5, 2017

This is way easier than, which is what I was trying to follow before.

I did have to remove --stdlayout from line 10 to deal with Subversion repos that weren't setup with the standard trunk/branches/tags structure. I was otherwise getting an error about the Git repository being empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.