Skip to content

Instantly share code, notes, and snippets.

@kode54
Created April 5, 2014 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kode54/9987343 to your computer and use it in GitHub Desktop.
Save kode54/9987343 to your computer and use it in GitHub Desktop.
These scripts can be used to prune a Git repository down to just the contents of the specified subdirectory, and prunes the change history to only the files contained within.
@echo off
setlocal enableextensions enabledelayedexpansion
set dir=%1
set dir=!dir:\=/!
git remote rm origin
git filter-branch --tag-name-filter cat --prune-empty --subdirectory-filter "%dir%" HEAD
git reset --hard
for /f %%r in ('git for-each-ref --format="%(refname)" refs/original/') do git update-ref -d %%r
git reflog expire --expire=now --all
git gc --aggressive --prune=now
#!/bin/sh
git remote rm origin
git filter-branch --tag-name-filter cat --prune-empty --subdirectory-filter "$1" HEAD
git reset --hard
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
git reflog expire --expire=now --all
git gc --aggressive --prune=now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment