Created
February 23, 2018 13:14
-
-
Save matthiasbalke/8e40f8251ca860123df98bd504025bd1 to your computer and use it in GitHub Desktop.
extract a specific path from git repository with history
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
git clone https://example.com/repo | |
# change into repository dir | |
cd repo | |
git checkout --detach | |
# delete all local branches | |
git branch | grep --invert-match "*" | xargs git branch -D | |
# checkout all branches to extract | |
git branch --remotes --no-color | grep --invert-match "\->" | while read remote; do git checkout --track "$remote"; done; | |
# remove origin | |
git remote remove origin | |
# extract only choosen-subdirectory | |
# keep tag names | |
git filter-branch --prune-empty --subdirectory-filter choosen-subdirectory --tag-name-filter cat -- --all | |
rm -rf .git/refs/original/* | |
# delete all local tags | |
git tag -l | xargs git tag -d | |
# use BFG to clean big objects fast | |
# https://rtyley.github.io/bfg-repo-cleaner/ | |
# physically delete objects from repository | |
# git reflog expire --expire=now --all | |
# git gc --prune=now |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment