« My Visio Presentation from the PowerShell Summit 2014 | Main | Comic Neue »
Wednesday
Apr232014

Exporting the Contents of a Git Repository with PowerShell

A handy script for automating quickly getting the code out of a git repo, without actually wanting all the history of the repo.

$GITEXE="C:\Program Files (x86)\Git\bin\git.exe"
$REPO="https://github.com/advancedrei/MetaWeblogPortable.git"
$DESTDIR="d:\SourceCodeExport"

# Clean out destination folder
if (Test-Path $DESTDIR)
{
    Remove-Item -Recurse -Force $DESTDIR
}

# Clone from repo to folder
&$GITEXE clone --depth 1 $REPO $DESTDIR

# Remove non-source code files from the destination folder
Remove-Item -Recurse -Force ( join-path $DESTDIR ".git")

In my case, I needed to ZIP up the contents also. If you need to do check out this post: how to create ZIPs easily with PowerShell.

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments (1)

Thanks nice post
thanks :)

April 30, 2014 | Unregistered CommenterJason

PostPost a New Comment

Enter your information below to add a new comment.
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>