Remove subfolder from all git history

# Remove DIRECTORY_NAME from all commits, then remove the refs to the old commits # (repeat these two commands for as many directories that you want to remove) git filter-branch --index-filter 'git rm -rf --cached --ignore-unmatch DIRECTORY_NAME/' --prune-empty --tag-name-filter cat -- --all git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d # Ensure all old refs are fully removed rm -Rf .git/logs .git/refs/original # Perform a garbage collection to remove commits with no refs git gc --prune=all --aggressive

February 27, 2020  |  🏷️git

Merging git repositories to a monorepository

BFG-clean repository If you’ve had the bad habit of checking in binary data, this is your chance to clean it up. If so, then run these lines. Tweak the bfg command to your taste. cd git-repo # Optional. Will likely make you able to remove more files. You might want to remove remotes as well. git tag -d $(git tag -l) cd .. java -jar bfg-1.13.0.jar --strip-blobs-bigger-than 5M --delete-files "*.{class, jar, png, svg, ico, zip}" git-repo cd git-repo git reflog expire --expire=now --all && git gc --prune=now --aggressive Move the repository to a subfolder Replace subfolder below with the real subfolder name...

November 8, 2018  |  🏷️git 🏷️bfg

Git Cheatsheet

Things about git which I sometimes forget Recovering from a spaghetti branch Different ways of handling when you’ve branched from a branch, which later gets merged to a branch which you also want to merge to. rebase –onto You have created CURRENTBRANCH from OLDBRANCH which later got merged into NEWBRANCH. Now you want to clean up OLDBRANCH branch to reflect the real changes based on NEWBRANCH before a pull request....

March 19, 2015  |  🏷️git